-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (96 loc) · 3.65 KB
/
dev_cd.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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Dev_CD
on:
push:
branches: [ "dev_deploy" ]
permissions:
contents: read
jobs:
check_repo:
runs-on: ubuntu-latest
outputs:
cd-skip: ${{ steps.check_repo.outputs.cd-skip-value }}
steps:
- uses: actions/checkout@v4
- name: Check Repo
run: |
if [ "$GITHUB_REPOSITORY" != "YOUR_USER/YOUR_REPO_NAME" ]; then
echo 'cd-skip-value=true' >> $GITHUB_OUTPUT
else
echo 'cd-skip-value=false' >> $GITHUB_OUTPUT
fi
skip_cd:
needs: check_repo
if: github.repository != 'SWM-WeLike2Coding/ELSwhere-product-service'
runs-on: ubuntu-latest
steps:
- name: Skip CD
run: |
echo "CD will be terminated soon..."
exit 0
build:
runs-on: ubuntu-latest
if: github.repository == 'SWM-WeLike2Coding/ELSwhere-product-service'
needs: check_repo
environment: dev
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Make test properties
env:
PROPERTIES: ${{ secrets.PROPERTIES_TEST }}
run: |
mkdir -p ./src/test/resources && cd "$_"
touch ./application.yml
echo $PROPERTIES | base64 --decode > application.yml
shell: bash
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Build with Gradle Wrapper
run: ./gradlew build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Docker build
env:
AWS_ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_DEV_PRODUCT_SERVICE_REPOSITORY }}
run: |
docker build -t $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:${GITHUB_SHA::7} -t $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:latest .
- name: Docker push
env:
AWS_ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_DEV_PRODUCT_SERVICE_REPOSITORY }}
run: |
docker push $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:${GITHUB_SHA::7}
docker push $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:latest
- name: SSH Remote Commands
uses: appleboy/ssh-action@master
env:
AWS_ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_DEV_PRODUCT_SERVICE_REPOSITORY }}
with:
host: ${{ secrets.SERVER_HOST }}
username: ubuntu
key: ${{ secrets.PRIVATE_SUB_PRIVATE_PEM_KEY }}
proxy_host: ${{ secrets.BASTION_SERVER_HOST }}
proxy_username: ubuntu
proxy_key: ${{ secrets.PUBLIC_SUB_PRIVATE_PEM_KEY }}
envs: GITHUB_SHA,AWS_ECR_REGISTRY,AWS_ECR_REPOSITORY
script: |
./deploy_product.sh $AWS_ECR_REGISTRY $AWS_ECR_REPOSITORY ${GITHUB_SHA::7}