-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (79 loc) · 3.45 KB
/
batch-deploy.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
name: batch deploy
on:
push:
branches:
- main
- develop
- fix/#147
paths:
- 'adapters/in-batch/**'
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_BATCH_IMAGE: ${{ secrets.DOCKERHUB_BATCH_IMAGE }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
kotlin-version: [ "1.9.23" ]
java-version: [ "17" ]
steps:
- name: Check Out The Repository
uses: actions/checkout@v3
- name: Set up Kotlin
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
kotlin-version: ${{ matrix.kotlin-version }}
distribution: 'corretto'
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Create config file
run: |
mkdir -p ./adapters/out-persistence/src/main/resources
echo "${{ secrets.OUT_PERSISTENCE_YML }}" > ./adapters/out-persistence/src/main/resources/application-out-persistence.yml
mkdir -p ./adapters/out-web/src/main/resources
echo "${{ secrets.OUT_WEB_GOOGLE }}" | base64 --decode > ./adapters/out-web/src/main/resources/google-services.json
echo "${{ secrets.OUT_WEB_YML }}" > ./adapters/out-web/src/main/resources/application-out-web.yml
mkdir -p ./application/src/main/resources
echo "${{ secrets.APPLICATION_CORE }}" > ./application/src/main/resources/application-core.yml
mkdir -p ./adapters/in-batch/src/main/resources
echo "${{ secrets.APPLICATION_IN_BATCH_YML }}" > ./adapters/in-batch/src/main/resources/application-in-batch.yml
- name: Build with Gradle
run: ./gradlew :entry:batch:build --no-daemon
- name: Docker build and push
run: |
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
docker build -f entry/batch/Dockerfile -t $DOCKERHUB_USERNAME/$DOCKERHUB_BATCH_IMAGE:latest .
docker push $DOCKERHUB_USERNAME/$DOCKERHUB_BATCH_IMAGE:latest
- name: Get Public IP
id: publicip
run: |
response=$(curl -s canhazip.com)
echo "ip='$response'" >> $GITHUB_OUTPUT
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_BATCH_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_BATCH_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Add GitHub IP to AWS
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_BATCH_SG_ID }} --protocol tcp --port ${{ secrets.PORT }} --cidr ${{ steps.publicip.outputs.ip }}/32
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.BATCH_HOST }}
username: ${{ secrets.BATCH_USERNAME }}
key: ${{ secrets.BATCH_KEY }}
port: ${{ secrets.PORT }}
script: |
cd pokit-batch
sudo docker-compose pull
sudo docker-compose down
sudo docker-compose up --force-recreate --remove-orphans -d
sudo docker image prune -f
- name: Remove IP FROM security group
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_BATCH_SG_ID }} --protocol tcp --port ${{ secrets.PORT }} --cidr ${{ steps.publicip.outputs.ip }}/32