Skip to content

Workflow file for this run

name: Build and Push (develop test)
on:
push:
branches:
- develop
tags:
- '*'
jobs:
backend_test_build_and_push_to_docker_registry: #disable backend in test branch
name: Test, build and publish backend image to docker hub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install dependencies
run: cd backend && npm install
- name: Docker login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- name: Determine Docker Image Name
id: image
run: |
if [[ "${{github.ref_name}}" == "master" ]]; then
echo "name=xinfinorg/subnet-stats-service:latest" >> $GITHUB_OUTPUT
else
echo "name=xinfinorg/subnet-stats-service:${{github.ref_name}}" >> $GITHUB_OUTPUT
fi
- name: Docker build and tag image
run: cd backend && docker build . --file Dockerfile --tag ${{ steps.image.outputs.name }}
- name: Docker push
run: docker push ${{ steps.image.outputs.name }}
frontend_test_build_and_push_to_docker_registry:
name: Test, build and publish frontend image to docker hub
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Docker login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- name: Determine Docker Image Name
id: image
run: |
if [[ "${{github.ref_name}}" == "master" ]]; then
echo "name=xinfinorg/subnet-frontend:latest" >> $GITHUB_OUTPUT
else
echo "name=xinfinorg/subnet-frontend:${{github.ref_name}}" >> $GITHUB_OUTPUT
fi
- name: Docker build and tag image
run: docker build . --file Dockerfile --tag ${{ steps.image.outputs.name }}
- name: Test run docker
run: docker run --entrypoint /bin/sh ${{ steps.image.outputs.name }} -c 'yarn run build && yarn global add serve'
- name: Docker push
run: docker push ${{ steps.image.outputs.name }}
trigger_deploy_workflow:
name: Trigger deployment workflow
needs: [frontend_test_build_and_push_to_docker_registry, backend_test_build_and_push_to_docker_registry]
runs-on: ubuntu-latest
steps:
- name: trigger deploy workflow
id: trigger_deploy
run: |
echo "RESPONSE_CODE=$( \
curl -L \
-o response.txt \
-w %{response_code} \
-s \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.CICD_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/hash-laboratories-au/xinfin-script/actions/workflows/test-ansible.yaml/dispatches \
-d '{"ref":"test-ansible", "inputs":{"caller_repo": "${{ github.repository }}", "caller_ref": "${{ github.ref_name }}", "caller_sha": "${{ github.sha }}"}}' \
)" >> $GITHUB_ENV
- name: Check response fail or success
run: |
cat response.txt
echo "RESPONSE_CODE=${{ env.RESPONSE_CODE }}"
if [ ${{ env.RESPONSE_CODE }} != 204 ]
then
exit 1
fi