diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 691641f..009de31 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,8 +1,8 @@ --- name: Bug Report about: 프로젝트의 버그와 관련된 이슈 -title: "[버그]" -labels: "🔧 Bug" +title: "[버그] " +labels: "🐞 BugFix" assignees: '' --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 2838029..8a199a3 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,7 +1,7 @@ --- name: Feature request about: 프로젝트의 새로운 기능 추가 요청 이슈 -title: "[기능 추가]" +title: "[기능 추가] " labels: "✨ Feature" assignees: '' diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..9c4cf92 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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/ssh-action@v1.0.3 + 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/ssh-action@v1.0.3 + 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/ssh-action@v1.0.3 + with: + host: ${{ env.SSH_HOST }} + username: ${{ env.SSH_USERNAME }} + key: ${{ env.SSH_KEY }} + script: | + cd Backend + + docker compose pull + docker compose up -d diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f8640e..e1bfa30 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml deleted file mode 100644 index e54441d..0000000 --- a/.github/workflows/update.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: Update to Deploy Repository -run-name: Update to Deploy Repository (${{ github.event.workflow_run.head_branch }}) - -on: - workflow_run: - workflows: - - Test - types: - - completed - branches: - - master - - develop - -concurrency: - group: update-${{ github.event.workflow_run.head_branch }} - cancel-in-progress: true - -jobs: - update-deploy: - runs-on: ubuntu-latest - steps: - - name: Set up Git - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - - name: Set up Github SSH - run: | - mkdir -p ~/.ssh - echo "${{ secrets.SSH_GITHUB_KEY }}" > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - ssh-keyscan github.com >> ~/.ssh/known_hosts - - - name: Checkout code - run: | - git clone --branch ${{ github.event.workflow_run.head_branch }} --recursive git@github.com:kmu-wink/wink-official-deploy.git deploy - - - name: Update Submodule - run: | - cd deploy - git submodule update --remote backend - - - name: Commit and Push - run: | - cd deploy - git add backend - git commit -m "update: backend" - git push -f origin ${{ github.event.workflow_run.head_branch }}