This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
Build and Deploy Racing Game #55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Racing Game | |
on: | |
workflow_dispatch: | |
push: | |
branches: ['master', 'main', 'staging'] | |
paths: | |
- frontend/** | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
ENVIRONMENT: ${{ (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && 'prod' || 'stg' }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} | |
KUBECTL_VERSION: "v1.22.17" | |
KUBE_NAMESPACE: gear-dapps | |
KUBE_DEPLOYMENT_PREFIX: dapps-racing | |
REGISTRY: ghcr.io/${{ github.repository }} | |
jobs: | |
prepair: | |
runs-on: ubuntu-latest | |
outputs: | |
image_name: ${{ steps.image.outputs.image_name }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get branch | |
id: branch | |
run: | | |
branch_name=${GITHUB_REF#refs/heads/} | |
echo "branch_name=$branch_name" >> $GITHUB_ENV | |
- name: Get short SHA | |
id: sha | |
run: | | |
sha_short=$(git rev-parse --short HEAD) | |
echo "sha_short=$sha_short" >> $GITHUB_ENV | |
- name: Set IMAGE_NAME | |
id: image | |
run: | | |
image_name=${{ env.REGISTRY }}-${{ env.KUBE_DEPLOYMENT_PREFIX }}:${{ env.branch_name }}-${{ env.sha_short }} | |
echo "image_name=$image_name" >> $GITHUB_OUTPUT | |
build-and-push-image: | |
needs: [prepair] | |
runs-on: ubuntu-latest | |
environment: ${{ (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && 'prod' || 'stg' }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to the github container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push image | |
uses: docker/build-push-action@v4 | |
with: | |
context: frontend | |
file: frontend/Dockerfile | |
push: true | |
tags: ${{ needs.prepair.outputs.image_name }} | |
build-args: | | |
REACT_APP_SIGNALING_SERVER=${{ secrets.REACT_APP_SIGNALING_SERVER }} | |
REACT_APP_AUTH_API_ADDRESS=${{ secrets.REACT_APP_AUTH_API_ADDRESS }} | |
REACT_APP_TESTNET_URL=${{ secrets.REACT_APP_TESTNET_URL }} | |
REACT_APP_FT_ADDRESS=${{ secrets.REACT_APP_FT_ADDRESS }} | |
REACT_APP_CONTRACT_ADDRESS=${{ secrets.REACT_APP_CONTRACT_ADDRESS }} | |
REACT_APP_NODE=${{ secrets.REACT_APP_NODE }} | |
deploy-to-k8s: | |
needs: [prepair, build-and-push-image] | |
runs-on: ubuntu-latest | |
environment: ${{ (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && 'prod' || 'stg' }} | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Update deployment image | |
uses: kodermax/[email protected] | |
with: | |
args: | | |
set image deployment/${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }} \ | |
${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }}=${{ needs.prepair.outputs.image_name }} \ | |
-n ${{ env.KUBE_NAMESPACE }} | |
- name: Restart deployment | |
uses: kodermax/[email protected] | |
with: | |
args: | | |
rollout restart deployment/${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }} \ | |
-n ${{ env.KUBE_NAMESPACE }} | |
- name: Check deployment | |
uses: kodermax/[email protected] | |
with: | |
args: | | |
rollout status deployment/${{ env.KUBE_DEPLOYMENT_PREFIX }}-${{ env.ENVIRONMENT }} \ | |
--timeout=120s \ | |
-n ${{ env.KUBE_NAMESPACE }} |