Skip to content

Merge pull request #43 from roziqinkhoeru/main #90

Merge pull request #43 from roziqinkhoeru/main

Merge pull request #43 from roziqinkhoeru/main #90

name: Game Admin Panel
# testot
on:
push:
branches:
- main
workflow_dispatch:
branches:
- main
- game-admin-panel
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
- name: Confirm git commit SHA output
run: echo ${{ env.COMMIT_SHORT_SHA }}
- 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: env-url
name: get api url from secret
run: |
echo "VITE_MODE=production" >> .env
echo "VITE_API_URL=https://be-game.cyclic.app/admin" > .env
echo "VITE_API_DEV_URL=https://be-game.cyclic.app/admin" >> .env
cat .env
- id: build
name: Build and push
uses: docker/build-push-action@v5
with:
# context: .
push: true
tags: thelogoreng/api:game-panel-${{ env.COMMIT_SHORT_SHA }}
Deploy-to-VM:
runs-on: ubuntu-latest
needs: build-image
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
- name: Deploy in VM
env:
PRIVATE_KEY: ${{ secrets.SSH_KEY }}
HOSTNAME: ${{ secrets.VM_HOST }}
USER_NAME: ${{ secrets.VM_USERNAME }}
port: ${{ secrets.VM_PORT }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
SHORT_SHA: ${{ env.COMMIT_SHORT_SHA }}
# passphrase: ${{ secrets.SSH_PASSPHRASE }}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} -p $port '
cd /home/${{ secrets.VM_USERNAME }}/panel &&
ls -al &&
echo ${{ secrets.DOCKER_TOKEN }} | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin &&
docker pull thelogoreng/api:game-panel-${{ env.COMMIT_SHORT_SHA }} &&
docker tag thelogoreng/api:game-panel-${{ env.COMMIT_SHORT_SHA }} thelogoreng/api:game-panel
docker compose up -d &&
docker image prune --force
'