Skip to content

Commit

Permalink
ci: Github Workflow tnwjd (#66)
Browse files Browse the repository at this point in the history
* chore(github): Issue Template Label 수정

* ci: 배포 workflow 수정
  • Loading branch information
son-daehyeon committed Sep 3, 2024
1 parent 8de0b91 commit a5173e5
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Bug Report
about: 프로젝트의 버그와 관련된 이슈
title: "[버그]"
labels: "🔧 Bug"
title: "[버그] "
labels: "🐞 BugFix"
assignees: ''

---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Feature request
about: 프로젝트의 새로운 기능 추가 요청 이슈
title: "[기능 추가]"
title: "[기능 추가] "
labels: "✨ Feature"
assignees: ''

Expand Down
139 changes: 139 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Deploy
run-name: Deploy (${{ github.event.workflow_run.head_branch }})

on:
workflow_run:
workflows:
- Test
types:
- completed
branches:
- master
- develop

concurrency:
group: deploy-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true

env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/wink-official-backend:${{ github.event.workflow_run.head_branch }}

SSH_HOST: ${{ github.event.workflow_run.head_branch == 'master' && secrets.SSH_MASTER_HOST || secrets.SSH_DEVELOP_HOST }}
SSH_USERNAME: ${{ github.event.workflow_run.head_branch == 'master' && secrets.SSH_MASTER_USERNAME || secrets.SSH_DEVELOP_USERNAME }}
SSH_KEY: ${{ github.event.workflow_run.head_branch == 'master' && secrets.SSH_MASTER_KEY || secrets.SSH_DEVELOP_KEY }}

jobs:
build-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Image
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64
provenance: false
tags: ${{ env.IMAGE_NAME }}-amd64
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}-amd64-cache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}-amd64-cache

build-arm64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Image
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/arm64
tags: ${{ env.IMAGE_NAME }}-arm64
provenance: false
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}-arm64-cache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}-arm64-cache

merge-image:
runs-on: ubuntu-latest
needs: [ build-amd64, build-arm64 ]
steps:
- name: Login to Docker Hub
run: |
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Pull Backend Image
run: |
docker pull --platform linux/amd64 ${{ env.IMAGE_NAME }}-amd64
docker pull --platform linux/arm64 ${{ env.IMAGE_NAME }}-arm64
- name: Merge Backend Image
run: |
docker manifest create ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-amd64 ${{ env.IMAGE_NAME }}-arm64
docker manifest annotate ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-amd64 --os linux --arch amd64
docker manifest annotate ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-arm64 --os linux --arch arm64
- name: Push Backend Image
run: docker manifest push ${{ env.IMAGE_NAME }}

check-server:
runs-on: ubuntu-latest
steps:
- name: Check exists project
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
if [ ! -d "Backend" ]; then
echo "Directory "Backend" not found"
exit 1
fi
- name: Check docker compose file
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
if [ ! -f "Backend/docker-compose.yaml" ]; then
echo "File "Backend/docker-compose.yaml" not found"
exit 1
fi
deploy:
runs-on: ubuntu-latest
needs: [ check-server, build-amd64 ]
steps:
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
cd Backend
docker compose pull
docker compose up -d
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Test
run-name: Test on ${{ github.ref_name }}
run-name: Test (${{ github.ref_name }})

on:
push: {}
push:

concurrency:
group: test-${{ github.ref_name }}-${{ github.sha }}
Expand Down
48 changes: 0 additions & 48 deletions .github/workflows/update.yaml

This file was deleted.

0 comments on commit a5173e5

Please sign in to comment.