-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (106 loc) · 3.68 KB
/
cd-to-dev.yml
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
name: Deploy to Test Instance
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
repository_dispatch:
types: [deploy-to-test-event]
push:
branches: [ develop ]
pull_request:
types: [ edited ]
env:
SPRING_PROFILES_ACTIVE: dev
ECR_APP_NAME: ${{ secrets.ECR_APP_NAME }}-${{ env.SPRING_PROFILES_ACTIVE }}
ECR_REPO: ${{ secrets.ECR_HOST }}/${{ env.ECR_APP_NAME }}
GREEN_SERVER_IMAGE: ${{ env.ECR_REPO }}
BLUE_SERVER_IMAGE: ${{ env.ECR_REPO }}
jobs:
build:
name: CD Pipeline
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 1.17
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: 'Check Java Version'
run: |
java --version
echo 'ecr repo is $ECR_REPO'
- name: 'Configure AWS credentials'
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID__TEAM_PLAYGROUND }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY__TEAM_PLAYGROUND }}
aws-region: ap-northeast-2
- name: 'Get application.yml from AWS S3'
run: |
aws s3 cp \
--region ap-northeast-2 \
s3://sopt-makers-internal/dev/deploy/application-dev.yml src/main/resources/application.yml
- name: 'Get key from AWS S3'
run: |
aws s3 cp \
--region ap-northeast-2 \
s3://sopt-makers-internal/dev/deploy/${{ secrets.APPLE_KEY }} src/main/resources/static/${{ secrets.APPLE_KEY }}
- name: 'Build with Gradle'
run: |
chmod +x ./gradlew
./gradlew clean build -x test
shell: bash
- name: 'Configure Docker Build Environment'
uses: docker/[email protected]
- name: 'Login to ECR'
run: |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_HOST }}
- name: 'Docker Image Build & Push'
run: |
docker buildx build --platform linux/arm64 -f Dockerfile -t $ECR_REPO .
docker push $ECR_REPO
- name: 'Send docker-compose.yml to EC2 Instance'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEV_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }}
source: "./docker-compose.yml"
target: "/home/ec2-user/"
- name: 'Send deploy script to EC2 Instance'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEV_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }}
source: "./scripts/deploy.sh"
target: "/home/ec2-user/app/"
- name: 'Get current time'
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
- name: 'Docker Container Run'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }}
script: |
cd ~
sudo docker pull ${{ secrets.ECR_REPO }}
sudo chmod +x ./deploy.sh
cp ./app/scripts/deploy,sh
./deploy.sh
docker image prune -f