-
Notifications
You must be signed in to change notification settings - Fork 4
134 lines (107 loc) · 3.63 KB
/
backend-dev-cd.yml
File metadata and controls
134 lines (107 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Backend CD on develop branch
on:
push:
branches: [ "develop" ]
paths:
- 'backend/**'
workflow_dispatch:
env:
WORKING_DIR: backend/spring-routie
jobs:
build-and-push:
name: 1. Build Application & Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PAT_FOR_SUBMODULE }}
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
- name: Gradle Caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/gradle.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
env:
SPRING_PROFILES_ACTIVE: test
- name: BootJar with Gradle
run: ./gradlew bootJar
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PAT }}
- name: Build and Push Docker Image
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_APPLICATION_IMAGE_NAME: ${{ secrets.DOCKER_APPLICATION_IMAGE_NAME }}
TAG: ${{ github.sha }}
run: |
FULL_IMAGE_NAME=$DOCKER_USERNAME/$DOCKER_APPLICATION_IMAGE_NAME
docker buildx build \
--platform linux/arm64 \
-f ./routie-backend-private/dev/Dockerfile \
-t $FULL_IMAGE_NAME:$TAG \
-t $FULL_IMAGE_NAME:latest \
--push .
upload-s3:
name: 2. Upload Config to S3
runs-on: ubuntu-latest
needs: build-and-push
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PAT_FOR_SUBMODULE }}
- name: Prepare Deployment Package
run: |
DEPLOY_DIR=$GITHUB_WORKSPACE/deployment
SUBMODULE_DIR=./routie-backend-private/dev
mkdir -p $DEPLOY_DIR/migration
cp -r src/main/resources/db/migration/* $DEPLOY_DIR/migration/
cp -r $SUBMODULE_DIR/. $DEPLOY_DIR/
sed -i "s/\${TAG}/${{ github.sha }}/g" $DEPLOY_DIR/docker-compose.yml
cd $DEPLOY_DIR
zip -r "$GITHUB_WORKSPACE/deploy.zip" .
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Upload Config to S3
run: |
aws s3 cp $GITHUB_WORKSPACE/deploy.zip s3://routie-dev-deployment/${{ github.sha }}/deploy.zip
deploy-to-ec2:
name: 3. Deploy to EC2
runs-on: [ self-hosted, dev ]
needs: upload-s3
steps:
- name: Execute Deployment Script
run: /home/ubuntu/deployment/deployment.sh ${{ github.sha }}