Skip to content

Commit

Permalink
docker cicd test
Browse files Browse the repository at this point in the history
  • Loading branch information
wjddn2165 committed Jul 29, 2024
1 parent 821fe83 commit 1ab0d41
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to EC2
name: Deploy to EC2 with Docker Compose

on:
push:
Expand All @@ -7,13 +7,11 @@ on:

env:
AWS_REGION: ap-northeast-2
AWS_S3_BUCKET: spring-boot-code
AWS_CODE_DEPLOY_APPLICATION: spring-boot-deploy
AWS_CODE_DEPLOY_GROUP: spring-boot-CD-group
DOCKER_HUB_REPOSITORY: baeeejw/jgs-spring-boot
working-directory: ./Server

jobs:
deploy:
build-and-deploy:
runs-on: ubuntu-latest

steps:
Expand All @@ -30,28 +28,39 @@ jobs:
run: chmod +x gradlew
working-directory: ${{ env.working-directory }}


- name: gradlew init
run: ./gradlew init
working-directory: ${{ env.working-directory }}


- name: 프로젝트 빌드
run: ./gradlew clean build -x test
working-directory: ${{ env.working-directory }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: AWS credential 설정
uses: aws-actions/configure-aws-credentials@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.CICD_SECRET_KEY }}
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: S3에 업로드
run: aws deploy push --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --ignore-hidden-files --s3-location s3://$AWS_S3_BUCKET/spring-boot-code/$GITHUB_SHA.zip --source .
working-directory: ${{ env.working-directory }}
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: EC2에 배포
run: aws deploy create-deployment --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} --s3-location bucket=$AWS_S3_BUCKET,key=spring-boot-code/$GITHUB_SHA.zip,bundleType=zip
- name: Build and push Docker image
run: |
docker buildx build --push --tag ${{ env.DOCKER_HUB_REPOSITORY }}:latest .
working-directory: ${{ env.working-directory }}

- name: SSH into EC2 and deploy with Docker Compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_KEY }}
script: |
cd /home/ubuntu/spring-boot
docker-compose pull
docker-compose up -d

0 comments on commit 1ab0d41

Please sign in to comment.