-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[CI] CI/CD 배포 파이프라인 구축
- Loading branch information
Showing
6 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Dockerizing to Amazon EC2 for Dev | ||
|
||
on: | ||
push: | ||
branches: [ "develop"] | ||
|
||
jobs: | ||
deploy_job: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# 레포지토리 체크아웃 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.ACTION_TOKEN }} | ||
|
||
- name: Update submodule | ||
run: | | ||
git submodule update --remote --recursive | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# gradle caching - 빌드 시간 향상 | ||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew clean build -x test | ||
|
||
# Docker 이미지를 빌드할 준비 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# DockerHub에 로그인 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
# Develop에 Docker 이미지를 build, push | ||
- name: Build and push Docker image to develop | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/running-mate-dev:latest | ||
build-args: | | ||
SPRING_PROFILES_ACTIVE=develop | ||
# docker-compose 파일을 EC2로 복사 | ||
- name: Copy docker-compose file to EC2 | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
source: 'docker-compose.develop.yml' | ||
target: '/home/ubuntu' | ||
|
||
# EC2 인스턴스에 SSH로 접속하여 Docker 컨테이너를 업데이트하고 실행 | ||
- name: Deploy to EC2 (develop) | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
script: | | ||
cd /home/ubuntu | ||
sudo docker compose -f docker-compose.develop.yml pull | ||
sudo docker compose -f docker-compose.develop.yml down | ||
sudo docker compose -f docker-compose.develop.yml up -d | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM openjdk:17-jdk | ||
|
||
# JAR 파일 복사 | ||
ARG JAR_FILE=build/libs/*SNAPSHOT.jar | ||
COPY ${JAR_FILE} running-mate.jar | ||
|
||
# 환경 변수 설정 | ||
ENV SPRING_PROFILES_ACTIVE=develop | ||
|
||
# 프로덕션용 진입점 설정 | ||
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}", "/running-mate.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
services: | ||
# Redis 서비스 설정 | ||
redis: | ||
image: redis:latest | ||
container_name: redis-container | ||
ports: | ||
- '6379:6379' | ||
volumes: | ||
- redis-data:/data # 데이터 지속성을 위한 볼륨 설정 | ||
networks: | ||
- app-network | ||
|
||
# 애플리케이션 서비스 설정 | ||
running-mate: | ||
image: kimjunseok/running-mate-dev:latest | ||
container_name: running-mate-dev | ||
ports: | ||
- '8080:8080' | ||
environment: | ||
- SPRING_PROFILES_ACTIVE=develop # Spring 프로파일 설정 | ||
networks: | ||
- app-network | ||
|
||
networks: | ||
app-network: | ||
driver: bridge | ||
|
||
volumes: | ||
redis-data: | ||
driver: local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters