diff --git a/.github/workflows/dev-aws-CI-CD.yml b/.github/workflows/dev-aws-CI-CD.yml index e8ed520..26a14b7 100644 --- a/.github/workflows/dev-aws-CI-CD.yml +++ b/.github/workflows/dev-aws-CI-CD.yml @@ -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 @@ -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 @@ -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: @@ -81,7 +80,6 @@ jobs: source: "./docker-compose.yml" target: "/home/ubuntu/" - ## nginx 설정 파일 서버로 전달하기(복사 후 붙여넣기) - name: Send nginx.conf uses: appleboy/scp-action@master with: @@ -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 @@ -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