Skip to content

Merge branch 'main' of https://github.com/Argus-Labs/agar-shooter #27

Merge branch 'main' of https://github.com/Argus-Labs/agar-shooter

Merge branch 'main' of https://github.com/Argus-Labs/agar-shooter #27

name: Backend - Build-Test-Release
## workflow will trigger on below condition,
## except image release that have jobs condition to trigger only on tagging
on:
pull_request:
branches:
- main
- dev
push:
branches:
- main
- dev
tags:
- 'v*.*.*'
env:
GCP_REGISTRY_ARTIFACT_PATH: us-docker.pkg.dev/world-engine-test/agar-shooter
GCP_PROJECT_ID: world-engine-test
CARDINAL_REGISTRY_PATH: agar-shooter/cardinal
NAKAMA_REGISTRY_PATH: agar-shooter/nakama
jobs:
backend-build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
env:
GOPRIVATE: github.com/argus-labs
strategy:
matrix:
go-version: [1.20.x]
backend-dir:
- cardinal
- nakama
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: |
${{ secrets.CARDINAL_AGAR_SHOOTER_DEPLOY_KEY }}
- name: Use git SSH Deploy Key
run: git config --global --add url."git@github.com:".insteadOf "https://github.com/"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Prepare Go Build
run: |
cd ${{ matrix.backend-dir }}
go mod tidy
go mod vendor
- name: Docker Build
run: |
cd ${{ matrix.backend-dir }}
docker build -t agar-shooter-${{ matrix.backend-dir }}:latest .
docker save agar-shooter-${{ matrix.backend-dir }}:latest > /tmp/agar-shooter-${{ matrix.backend-dir }}-latest.tar
- name: Upload local build images to temporary artifact
uses: actions/upload-artifact@v3
with:
name: buildimage
path: /tmp/agar-shooter-${{ matrix.backend-dir }}-latest.tar
backend-test:
runs-on: ubuntu-latest
needs: backend-build
defaults:
run:
shell: bash
env:
GOPRIVATE: github.com/argus-labs
strategy:
matrix:
go-version: [1.20.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use git SSH Deploy Key
run: git config --global --add url."git@github.com:".insteadOf "https://github.com/"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download local build images artifact
uses: actions/download-artifact@v3
with:
name: buildimage
path: /tmp/
- name: Load image and show build images
run: |
docker load --input /tmp/agar-shooter-nakama-latest.tar
docker load --input /tmp/agar-shooter-cardinal-latest.tar
docker image ls -a | grep agar-shooter
- name: Docker Compose Up
run: |
docker compose up --detach --wait --wait-timeout 60
- name: Docker compose logs last status
if: success() || failure()
run: |
docker compose logs
- name: Verify running container
run: |
docker compose ps
>/dev/tcp/127.0.0.1/7350
- name: Docker Compose Down
run: |
docker compose down
backend-release:
runs-on: ubuntu-latest
needs: backend-test
if: startsWith(github.ref, 'refs/tags/v')
# Add "id-token" with the intended google-github-actions/auth permissions.
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download local build images artifact
uses: actions/download-artifact@v3
with:
name: buildimage
path: /tmp/
- name: Load image and show build images
run: |
docker load --input /tmp/agar-shooter-nakama-latest.tar
docker load --input /tmp/agar-shooter-cardinal-latest.tar
docker image ls -a | grep agar-shooter
- name: GCP auth
id: auth
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_WIF_SERVICE_ACCOUNT }}
- name: GCP - Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ env.GCP_PROJECT_ID }}
- name: Docker - auth to artifact registry
run: |
gcloud auth configure-docker us-docker.pkg.dev
- name: Set RELEASE_VERSION value (branch main / tag v.*)
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Docker - tag and push container
run: |
docker tag agar-shooter-cardinal:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker tag agar-shooter-nakama:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker tag agar-shooter-cardinal:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:latest"
docker tag agar-shooter-nakama:latest "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:latest"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:latest"
docker push "${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:latest"
- name: Dark Forest - Docker Image Released
run: |
echo "----------------------------------------------"
echo "🎉 Agar Shooter container images released [${{ env.RELEASE_VERSION }}]"
echo " Cardinal : ${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.CARDINAL_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
echo " Nakama : ${{ env.GCP_REGISTRY_ARTIFACT_PATH }}/${{ env.NAKAMA_REGISTRY_PATH }}:${{ env.RELEASE_VERSION }}"
echo "----------------------------------------------"
backend-cleanup:
runs-on: ubuntu-latest
needs: [
backend-build,
backend-test,
backend-release
]
if: always()
steps:
- name: Remove local build image artifact
uses: geekyeggo/delete-artifact@v2
with:
name: buildimage