-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (118 loc) · 4.18 KB
/
ci-cd-compose.yaml
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: deploy action
on:
push:
branches:
- develop/compose
- main
env:
REGISTRY: "ghcr.io"
NAMESPACE: "depromeet"
IMAGE_NAME: "kasukabe-server"
# TODO: 멀티모듈 적용시 동적 할당 필요
MODULE: "layer-api"
jobs:
setup:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
deploy_target: ${{ steps.set-env.outputs.DEPLOY_TARGET }}
steps:
- name: Setup Env
id: set-env
run: |
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "DEPLOY_TARGET=production" >> $GITHUB_OUTPUT
else
echo "DEPLOY_TARGET=development" >> $GITHUB_OUTPUT
fi
build:
name: build
needs: [ setup ]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
REGISTRY: "ghcr.io"
NAMESPACE: "depromeet"
IMAGE_NAME: "kasukabe-server"
# TODO: 멀티모듈 적용시 동적 할당 필요
MODULE: "layer-api"
APPLICATION_SECRET_PROPERTIES: ${{ secrets.APPLICATION_SECRET_PROPERTIES }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
steps:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
- name: Create application-secret.properties
run: |
echo "${APPLICATION_SECRET_PROPERTIES}" > ./${{ env.MODULE }}/src/main/resources/application-secret.properties
- name: Build ${{ env.MODULE }} module
run: ./gradlew :${{ env.MODULE }}:build
- name: Run tests:${{ env.MODULE }}
run: ./gradlew :${{ env.MODULE }}:test
- name: login github container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}/${{ env.MODULE }}
- name: push
uses: docker/build-push-action@v4
with:
context: ./${{ env.MODULE }}
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}/${{ env.MODULE }}:latest
# ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}/${{ env.MODULE }}:${{ github.run_id }}
deploy:
name: Deploy
needs: [ build, setup ]
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
# TODO: 멀티모듈 적용시 동적 할당 필요
MODULE: "layer-api"
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Create application-secret.properties file
run: |
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
- name: Send Docker Compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.INSTANCE_HOST }}
username: ${{ secrets.INSTANCE_USERNAME }}
password: ${{ secrets.INSTANCE_PASSWORD }}
port: 22
source: ./${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}/*
target: "/home"
- name: Deploy with Docker Compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.INSTANCE_HOST }}
username: ${{ secrets.INSTANCE_USERNAME }}
password: ${{ secrets.INSTANCE_PASSWORD }}
port: 22
script: |
cd /home/${{ env.MODULE }}/infra/${{ env.DEPLOY_TARGET }}
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > application-secret.properties
docker compose pull
docker compose up -d
docker image prune -a -f