Skip to content

Commit

Permalink
chore: dev-aws-CI-CD.yml 수정
Browse files Browse the repository at this point in the history
1. Docker Compose Pull 후 Up 실행:
- 최신 이미지를 Docker Hub에서 Pull하고, docker-compose up -d --build를 통해 새 컨테이너를 실행합니다.

2. Docker Login 중복 제거:
- Docker 로그인은 한 번만 수행하여 중복된 로그인을 제거했습니다.

3. 불필요한 docker-compose down 제거:
- 모든 컨테이너와 네트워크를 정리하는 docker-compose down을 제거했습니다. 단순히 컨테이너를 업데이트하려면 docker-compose up으로 충분합니다.
  • Loading branch information
Ogu1208 committed Sep 4, 2024
1 parent 1ab41ef commit f2bc971
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions .github/workflows/dev-aws-CI-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
environment: dev # 환경을 명시적으로 설정
environment: dev
if: github.event_name == 'push' || github.event_name == 'pull_request'
env:
jasypt.encryptor.password: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}
DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }} # 환경 변수 설정
DOCKER_REPOSITORY_NGINX: ${{ secrets.DOCKER_REPOSITORY_NGINX }} # 환경 변수 설정
DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }}
DOCKER_REPOSITORY_NGINX: ${{ secrets.DOCKER_REPOSITORY_NGINX }}
steps:
- name: checkout
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 17
Expand All @@ -42,9 +42,9 @@ jobs:
run: chmod +x gradlew

- name: Build With Gradle
run: ./gradlew build -x test --warning-mode all # 모든 경고를 표시
run: ./gradlew build -x test --warning-mode all

## build Test
## Build and test
- name: 테스트 코드 실행
run: ./gradlew --info test

Expand All @@ -56,22 +56,21 @@ jobs:

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
if: success() || failure()
with:
report_paths: '**/build/test-results/test/TEST-*.xml'

deploy:
name: Deploy
runs-on: ubuntu-latest
environment: dev # 환경을 명시적으로 설정
if: github.event_name == 'push' # push일 때만 실행
needs: build # build 작업이 끝난 후 실행
environment: dev
if: github.event_name == 'push'
needs: build
env:
JASYPT_ENCRYPTOR_PASSWORD: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }} # 환경 변수 설정
DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }} # 환경 변수 설정
DOCKER_REPOSITORY_NGINX: ${{ secrets.DOCKER_REPOSITORY_NGINX }} # 환경 변수 설정
JASYPT_ENCRYPTOR_PASSWORD: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}
DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }}
DOCKER_REPOSITORY_NGINX: ${{ secrets.DOCKER_REPOSITORY_NGINX }}
steps:
# 도커 컴포즈 설정 파일 서버로 전달하기(복사 후 붙여넣기)
- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
Expand All @@ -81,7 +80,6 @@ jobs:
source: "./docker-compose.yml"
target: "/home/ubuntu/"

## nginx 설정 파일 서버로 전달하기(복사 후 붙여넣기)
- name: Send nginx.conf
uses: appleboy/scp-action@master
with:
Expand All @@ -91,22 +89,25 @@ jobs:
source: "./nginx/nginx.conf"
target: "/home/ubuntu/"

## Docker login
- name: Docker Login
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
## Nginx 도커 이미지 빌드 후 도커허브에 push하기
- name: Docker build & Push for Nginx
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f dockerfile-nginx -t ${{ secrets.DOCKER_REPOSITORY_NGINX }} . # Nginx용 Dockerfile 사용
docker build -f dockerfile-nginx -t ${{ secrets.DOCKER_REPOSITORY_NGINX }} .
docker push ${{ secrets.DOCKER_REPOSITORY_NGINX }}
## springboot 도커 이미지 빌드 후 도커허브에 push하기
- name: Docker build & Push
## Spring Boot 도커 이미지 빌드 후 도커허브에 push하기
- name: Docker build & Push for Spring Boot
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPOSITORY }} . # 태그를 명시하지 않으면 :latest로 처리됨
docker build -t ${{ secrets.DOCKER_REPOSITORY }} .
docker push ${{ secrets.DOCKER_REPOSITORY }}
# 도커 허브에서 jar파일 및 pull후에 컴포즈 up
- name: Deploy to Dev
# 도커 허브에서 이미지 Pull 및 Docker Compose로 컨테이너 실행
- name: Deploy to Dev with Docker Compose
uses: appleboy/ssh-action@master
with:
username: ubuntu
Expand All @@ -117,8 +118,10 @@ jobs:
export DOCKER_REPOSITORY=${{ secrets.DOCKER_REPOSITORY }}
export DOCKER_REPOSITORY_NGINX=${{ secrets.DOCKER_REPOSITORY_NGINX }}
export JASYPT_ENCRYPTOR_PASSWORD=${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}
sudo docker-compose -f /home/ubuntu/docker-compose.yml down
sudo docker-compose -f /home/ubuntu/docker-compose.yml up -d
# Pull 최신 이미지
docker-compose -f /home/ubuntu/docker-compose.yml pull
# 새 컨테이너 실행
docker-compose -f /home/ubuntu/docker-compose.yml up -d --build
discord-notify:
name: Discord Notify
Expand Down

0 comments on commit f2bc971

Please sign in to comment.