-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (81 loc) · 3.14 KB
/
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
name: DEV-CD
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.ACCESS_TOKEN }}
submodules: true
- name: Replace application.yml with application-dev.yml
run: |
sed -i 's/local/dev/' src/main/resources/application.yml
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'
- name: Get image tag(version)
id: image
run: |
VERSION=$(echo ${{ github.sha }} | cut -c1-8)
echo VERSION=$VERSION
echo "::set-output name=version::$VERSION"
- name: Build With Jib and push image to Amazon ECR with tag
id: image-info
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ steps.image.outputs.version }}
run: |
echo "::set-output name=ecr_repository::$ECR_REPOSITORY"
echo "::set-output name=image_tag::$IMAGE_TAG"
./gradlew -Djib.to.image=$ECR_REGISTRY/$ECR_REPOSITORY -PinputTag=$IMAGE_TAG clean jib -x test
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Get Github Actions IP
id: ip
uses: haythem/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: SSH Commands
uses: appleboy/[email protected]
with:
host: ${{ secrets.AWS_SSH_HOST }}
username: ${{ secrets.AWS_SSH_USERNAME }}
password: ${{ secrets.AWS_SSH_PASSWORD }}
port: ${{ secrets.AWS_SSH_PORT }}
script_stop: true
script: |
cd test
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 075584359222.dkr.ecr.ap-northeast-2.amazonaws.com
docker system prune -a --volumes -f
docker-compose pull -q
docker-compose up --force-recreate --build -d --quiet-pull 2>log.out
cat log.out
- name: Remove Github Actions IP From Security Group
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32