-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (132 loc) · 5.36 KB
/
dev_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
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
139
140
141
142
143
144
145
146
147
148
name: dev deployment
on:
push:
branches:
- develop
jobs:
application_build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: java setting
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: gradle setting
run: |
chmod +x gradlew
./gradlew build \
--build-cache \
--project-cache-dir=$HOME/.gradle/caches/project \
--gradle-user-home=$HOME/.gradle/caches/global \
--project-dir="./"
- name: upload artifact
uses: actions/upload-artifact@v2
with:
name: application
path: build/libs/*.jar
push_to_docker_hub:
needs: application_build
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.generate_version.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: application
path: build/libs
- name: Generate Version
id: generate_version
run: |
current_date=$(date -d "9 hours" +%Y-%m-%d)
current_date_short_year=$(date -d "9 hours" +%y-%m-%d)
runs_this_month=$(curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runs?event=push&status=success&per_page=1&created=cats+created:<=$current_date"\
| jq '.total_count')
echo "new version is $current_date_short_year.$runs_this_month"
echo "new_version=$current_date_short_year.$runs_this_month" >> "$GITHUB_OUTPUT"
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ secrets.DOCKER_REGISTRY }}
- name: Docker build
env:
VERSION: ${{ steps.generate_version.outputs.new_version }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
run: |
docker build -f .deploy/Dockerfile -t $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION .
docker tag $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION $DOCKER_REGISTRY/$IMAGE_NAME:latest
docker push $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION
docker push $DOCKER_REGISTRY/$IMAGE_NAME:latest
config_environment:
runs-on: ubuntu-latest
steps:
- name: config environment
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.OCI_HOST }}
username: ${{ secrets.OCI_USERNAME }}
key: ${{ secrets.OCI_SSH_KEY }}
script: |
sudo rm -rf .env
touch .env
echo "RDB_HOST=${{secrets.RDB_HOST}}" >> .env
echo "RDB_PORT=${{secrets.RDB_PORT}}" >> .env
echo "RDB_SCHEMA=${{secrets.RDB_SCHEMA}}" >> .env
echo "RDB_USER=${{secrets.RDB_USER}}" >> .env
echo "RDB_PASSWORD=${{secrets.RDB_PASSWORD}}" >> .env
echo "MONGO_HOST=${{secrets.MONGO_HOST}}" >> .env
echo "MONGO_DB=${{secrets.MONGO_DB}}" >> .env
echo "MONGO_USER=${{secrets.MONGO_USER}}" >> .env
echo "MONGO_PASSWORD=${{secrets.MONGO_PASSWORD}}" >> .env
echo "JWT_SECRET=${{secrets.JWT_SECRET}}" >> .env
echo "DOCKER_REGISTRY=${{secrets.DOCKER_REGISTRY}}" >> .env
echo "IMAGE_NAME=${{secrets.IMAGE_NAME}}" >> .env
echo "SEOUL_OPEN_API_KEY=${{secrets.SEOUL_OPEN_API_KEY}}" >> .env
echo "NEIS_OPEN_API_KEY=${{secrets.NEIS_OPEN_API_KEY}}" >> .env
echo "OPENAI_API_KEY=${{secrets.OPENAI_API_KEY}}" >> .env
echo "NCP_OCR_API_KEY=${{secrets.NCP_OCR_API_KEY}}" >> .env
run_application:
runs-on: ubuntu-latest
needs: [ push_to_docker_hub, config_environment ]
steps:
- name: Run Docker container
uses: appleboy/ssh-action@master
env:
VERSION: ${{ needs.push_to_docker_hub.outputs.new_version }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
with:
host: ${{ secrets.OCI_HOST }}
username: ${{ secrets.OCI_USERNAME }}
key: ${{ secrets.OCI_SSH_KEY }}
envs: VERSION, DOCKER_REGISTRY, DOCKER_USERNAME, DOCKER_PASSWORD, IMAGE_NAME
script: |
echo "new application version is $VERSION"
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY
docker pull $DOCKER_REGISTRY/$IMAGE_NAME:latest
docker stop $IMAGE_NAME || true
docker rm $IMAGE_NAME || true
docker compose up -d
docker image prune -f