Deploy to prod by @ratafa #129
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deployment | |
run-name: Deploy to ${{ inputs.environment }} by @${{ github.actor }} | |
permissions: | |
id-token: write | |
contents: read | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: '배포 대상 환경' | |
required: true | |
default: 'alpha' | |
type: choice | |
options: | |
- alpha | |
- prod | |
ref: | |
description: '배포 대상 브랜치/태그' | |
required: true | |
default: 'HEAD' | |
type: string | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
GIT_REF: ${{ inputs.ref == 'HEAD' && 'refs/heads/main' || format('refs/tags/{0}', inputs.ref) }} | |
GIT_PROJECT_NAME: meeting | |
HARBOR_REGISTRY: harbor.uoslife.net | |
HARBOR_PROJECT: uoslife-${{ inputs.environment }}-v1 | |
HARBOR_REPOSITORY: meeting-client | |
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }} | |
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }} | |
GITHUB_TOKEN: ${{ secrets.NPM_GITHUB_TOKEN }} | |
steps: | |
- name: Clone Repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.GIT_REF }} | |
- name: Generate Version Code | |
run: | | |
echo "version=$(date +'%Y%m%d%H%M%S')" >> "$GITHUB_OUTPUT" | |
echo "VERSION=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV | |
- name: Setup Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.HARBOR_REGISTRY }} | |
username: ${{ env.HARBOR_USERNAME }} | |
password: ${{ env.HARBOR_PASSWORD }} | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v5 | |
with: | |
file: Dockerfile | |
context: . | |
push: true | |
platforms: linux/amd64 | |
cache-from: type=gha | |
cache-to: 'type=gha,mode=max' | |
build-args: | |
GITHUB_TOKEN=${{ env.GITHUB_TOKEN }} | |
tags: > | |
${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.HARBOR_REPOSITORY }}:${{ env.VERSION }}, | |
${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.HARBOR_REPOSITORY }}:latest | |
- name: Checkout GitOps Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: uoslife/gitops | |
ref: main | |
ssh-key: ${{ secrets.GITOPS_SSH_KEY }} | |
path: gitops | |
- name: Setup Kustomize | |
uses: imranismail/setup-kustomize@v2 | |
- name: Update Image Tag | |
run: | | |
cd gitops/projects/${{ env.GIT_PROJECT_NAME }}/overlays/${{ inputs.environment }} | |
kustomize edit set image ${{ env.HARBOR_REPOSITORY }}=${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.HARBOR_REPOSITORY }}:${{ env.VERSION }} | |
- name: Apply Image Tag | |
run: | | |
cd gitops/projects/${{ env.GIT_PROJECT_NAME }}/overlays/${{ inputs.environment }} | |
git config --global user.email ${{ github.actor }}@users.noreply.github.com | |
git config --global user.name ${{ github.actor }} | |
git add . | |
git commit -am "projects(${{ env.GIT_PROJECT_NAME }}): update version to ${{ env.VERSION }}" | |
git push |