-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (137 loc) · 5.17 KB
/
release-server.yaml
File metadata and controls
151 lines (137 loc) · 5.17 KB
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
149
150
151
name: Release-Server
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
WORKFLOW_PHASE:
description: "배포할 대상 환경을 선택하세요."
required: true
default: dev
type: choice
options:
- dev
- prod
push:
branches:
- "main"
jobs:
BuildAndDeploy:
runs-on: ubuntu-latest
env:
API_STAGE: ${{ github.event_name == 'workflow_dispatch' && inputs.WORKFLOW_PHASE || 'dev' }}
BUMP_RULE: ${{ (github.event_name == 'workflow_dispatch' && inputs.WORKFLOW_PHASE || 'dev') == 'dev' && '--stage' || '' }}
steps:
# Checkout source codes
- name: Checkout source codes
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
ignore-nothing-to-cache: true
- name: Install dependencies
run: uv sync --only-group=deployment
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get current date, repo name and release tag version
id: info
run: |
LATEST_TAG=$(git tag -l --sort=-creatordate | head -n 1)
echo "::set-output name=TAG::$(python ./.github/scripts/get_new_version.py --current=$LATEST_TAG ${{ env.BUMP_RULE }})"
echo "::set-output name=date::$(date +'%Y-%m-%d_%H:%M:%S')"
echo "::set-output name=repository_name::$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')"
# Build and Push Docker image to Docker Hub
- name: Build and Push Docker image to Docker Hub
uses: docker/build-push-action@v5
with:
push: true
tags: |
${{ secrets.DOCKERHUB_IMAGE }}:${{ steps.info.outputs.TAG }}
${{ secrets.DOCKERHUB_IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: ./infra/server.Dockerfile
platforms: linux/amd64
provenance: false
build-args: |
RELEASE_VERSION=${{ steps.info.outputs.TAG }}
GIT_HASH=${{ github.sha }}
IMAGE_BUILD_DATETIME=${{ steps.info.outputs.date }}
# Create git tag
- name: Create and push git tag
run: |
git tag ${{ steps.info.outputs.TAG }}
git push origin ${{ steps.info.outputs.TAG }}
# Notify to Slack (Success)
- name: Notify deployment to Slack
if: failure() || cancelled()
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: ${{ vars.SLACK_DEPLOYMENT_ALERT_CHANNEL }}
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ steps.info.outputs.repository_name }} ${{ steps.info.outputs.TAG }} 버전 Build & Push 실패 :rotating_light: (${{ job.status }})",
"emoji": true
}
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": "GitHub Action 바로가기"},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "${{ github.run_id }}"},
"value": "github_action",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"action_id": "button-action"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# Notify to Slack (Failure)
- name: Notify deployment to Slack
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: ${{ vars.SLACK_DEPLOYMENT_ALERT_CHANNEL }}
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ steps.info.outputs.repository_name }} ${{ steps.info.outputs.TAG }} 버전 Build & Push 성공 :tada:",
"emoji": true
}
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": "GitHub Action 바로가기"},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "${{ github.run_id }}"},
"value": "github_action",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"action_id": "button-action"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}