-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (97 loc) · 3.74 KB
/
release-server.yaml
File metadata and controls
112 lines (97 loc) · 3.74 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
name: Release-Server
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
on:
workflow_dispatch:
inputs:
WORKFLOW_PHASE:
description: "배포할 대상 환경을 선택하세요."
required: true
default: dev
type: choice
options:
- dev
- prd
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:
- 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: |
echo "TAG=$(uv run python ./.github/scripts/get_new_version.py --cleanup-invalid ${{ env.BUMP_RULE }})" >> "$GITHUB_OUTPUT"
echo "date=$(date +'%Y-%m-%d_%H:%M:%S')" >> "$GITHUB_OUTPUT"
echo "repository_name=$(echo ${{ github.repository }} | sed -e 's/${{ github.repository_owner }}\///')" >> "$GITHUB_OUTPUT"
- 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 }}
- name: Create and push git tag
run: |
git tag ${{ steps.info.outputs.TAG }}
git push origin ${{ steps.info.outputs.TAG }}
# Trigger infrastructure repo to bump tag and run ansible deploy.
- name: Generate infrastructure deploy token
id: deploy-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.DEPLOY_APP_CLIENT_ID }}
private-key: ${{ secrets.DEPLOY_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ secrets.INFRA_REPO_NAME }}
- name: Trigger infrastructure deploy
env:
GH_TOKEN: ${{ steps.deploy-token.outputs.token }}
INFRA_REPO: ${{ github.repository_owner }}/${{ secrets.INFRA_REPO_NAME }}
SERVICE: backend-${{ env.API_STAGE }}
IMAGE_TAG: ${{ steps.info.outputs.TAG }}
run: |
gh api "repos/$INFRA_REPO/dispatches" \
--method POST \
-f event_type=bump-image \
-f "client_payload[service]=$SERVICE" \
-f "client_payload[image_tag]=$IMAGE_TAG"
- uses: ./.github/actions/notify-slack-deploy
if: always()
with:
slack-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel: ${{ vars.SLACK_DEPLOYMENT_ALERT_CHANNEL }}
header-prefix: "${{ steps.info.outputs.repository_name }} ${{ steps.info.outputs.TAG }} 버전 Build & Push"