Skip to content

#build

#build #230

Workflow file for this run

name: Deploy Backend
on:
push:
branches:
- main
workflow_dispatch:
branches:
- main
- backend
jobs:
Build-Image:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, '#build') }}
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Get Short SHA
id: vars
shell: bash
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- id: qemu
name: Set up QEMU
uses: docker/setup-qemu-action@v3
- id: buildx
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- id: auth
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- id: build
name: Build and Push
uses: docker/build-push-action@v5
with:
# context: .
push: true
tags: iwansuryaningrat/game-api:game-${{ env.COMMIT_SHORT_SHA }}
- id: buildSkripsi
name: Build and Push Skripsi Image
uses: docker/build-push-action@v5
with:
# context: .
push: true
tags: iwansuryaningrat/game-api:game-skripsi
Deploy-to-VM:
runs-on: ubuntu-latest
needs: Build-Image
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/private_key
chmod 600 ~/.ssh/private_key
- name: Deploy in VM
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/private_key ${{ secrets.OFFICE_USER }}@${{ secrets.OFFICE_IP }} -p ${{ secrets.OFFICE_PORT }} '
ssh ${{ secrets.VM_USERNAME }}@${{ secrets.VM_HOST }} './deploy-game.sh'
'