Skip to content

feat: DockerHub 이미지 업로드 기능 추가 #1

feat: DockerHub 이미지 업로드 기능 추가

feat: DockerHub 이미지 업로드 기능 추가 #1

name: Release
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 }}