Skip to content

Commit

Permalink
Merge pull request #73 from capstone-five-ai/refactor/cd-flow
Browse files Browse the repository at this point in the history
test: Docker CD 테스트
  • Loading branch information
yujamint authored Jun 27, 2024
2 parents 413d26a + 600e8bb commit 4f2c72f
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
steps:
- name: 체크아웃
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- name: JDK 11 설치
uses: actions/setup-java@v4
Expand All @@ -28,33 +31,28 @@ jobs:
- name: 빌드
run: ./gradlew build -x test

- name: zip 파일 생성
run: zip -r ./qtudy.zip .
shell: bash

- name: AWS credentials 설정
uses: aws-actions/configure-aws-credentials@v4
- name: DockerHub 로그인
uses: docker/login-action@v3
with:
aws-access-key-id: ${{ secrets.STG_AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.STG_AWS_SECRET_KEY }}
aws-region: ap-northeast-2

- name: S3에 zip 파일 업로드
run: >
aws s3 cp
--region ap-northeast-2
./qtudy.zip s3://${{ secrets.STG_AWS_S3_BUCKET_NAME }}/qtudy.zip
- name: Code Deploy 통해 배포
run: >
aws deploy create-deployment
--application-name QtudyStageCodeDeploy
--deployment-group-name QtudyStageCodeDeploy-DepGrp
--file-exists-behavior OVERWRITE
--deployment-config-name CodeDeployDefault.AllAtOnce
--s3-location bucket=${{ secrets.STG_AWS_S3_BUCKET_NAME }},bundleType=zip,key=qtudy.zip
--region ap-northeast-2
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker 이미지 빌드 & DockerHub에 Push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/qtudy-server:latest

- name: EC2 서버에 배포
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.STG_SERVER_HOST }}
username: ${{ secrets.STG_SERVER_USERNAME }}
key: ${{ secrets.STG_SERVER_PEM_KEY }}
envs: GITHUB_SHA
script: |
sudo docker stop $(sudo docker ps -a -q)
sudo docker pull ${{secrets.DOCKER_USERNAME}}/qtudy-server
sudo docker run -d -p 8080:8080 --name qtudy-server-container ${{secrets.DOCKER_USERNAME}}/qtudy-server
sudo docker image prune -f

0 comments on commit 4f2c72f

Please sign in to comment.