Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Docker CD 테스트 #73

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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