-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (77 loc) · 2.99 KB
/
actions.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
name: spurt CICD
on:
push:
branches:
- main
jobs:
push_to_registry:
name: Push to aws container registry
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build -x spotlessJavaCheck
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
- name: save docs file
uses: actions/upload-artifact@v3
with:
name: api-docs
path: build/docs/asciidoc
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker build & push to prod
if: contains(github.ref, 'develop') || contains(github.ref, 'main')
run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t spurt-be -f Dockerfile .
docker tag spurt-be:latest ${{ secrets.DOCKER_USER }}/spurt-be:latest
docker push ${{ secrets.DOCKER_USER }}/spurt-be:latest
pull_from_registry:
name: Connect server ssh and pull from container registry
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: Deploy to prod
if: contains(github.ref, 'develop') || contains(github.ref, 'main')
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_NAME }}
username: ${{ secrets.AWS_USER_NAME }}
key: ${{ secrets.AWS_PRIVATE_KEY }}
port: ${{ secrets.AWS_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USER }}/spurt-be:latest
docker stop spurt-be
docker rm spurt-be
docker run -d --network spurt --name spurt-be -p 8081:8081 ${{ secrets.DOCKER_USER }}/spurt-be
if docker images -f "dangling=true" -q | grep . > /dev/null; then
docker rmi $(docker images -f "dangling=true" -q)
fi
upload_docs:
name: upload api docs
needs: pull_from_registry
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: api-docs # Artifact name
path: artifact
- name: Upload Files to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.NCP_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.NCP_SECRET_KEY }}
AWS_DEFAULT_REGION: us-east-1
run: |
aws --endpoint-url=https://kr.object.ncloudstorage.com s3 cp artifact/index.html s3://spurt-backend-docs
aws --endpoint-url=https://kr.object.ncloudstorage.com/ s3 ls s3://spurt-backend-docs --recursive | awk '{cmd="aws --endpoint-url=https://kr.object.ncloudstorage.com/ s3api put-object-acl --bucket spurt-backend-docs --acl public-read --key "$4; system(cmd)}'