Skip to content

Commit

Permalink
A0-3747: Create building process for subway application (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszjedrzejewski authored Jan 2, 2024
1 parent 9c865c9 commit 73e3d28
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/_check-vars-and-secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# This workflow checks if vars and secrets are present and fails if one is empty.
# It should be included as a first step in all the workflows.
name: Check vars and secrets
on:
workflow_call:

jobs:
main:
name: Check available vars and secrets
runs-on: ubuntu-20.04
steps:
- name: Check vars
run: |
if [[ \
-z '${{ vars.ECR_PUBLIC_HOST }}' || \
-z '${{ vars.ECR_PUBLIC_REGISTRY }}'
]]; then
echo '!!! Some repository variables are either missing or empty.'
echo '!!! Please check either repository or organization settings.'
exit 1
fi
- name: Check secrets
run: |
if [[ \
-z '${{ secrets.AWS_MAINNET_ACCESS_KEY_ID }}' || \
-z '${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }}'
]]; then
echo '!!! Some repository secrets are either missing or empty.'
echo '!!! Please check either repository or organization settings.'
exit 1
fi
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: Build subway docker image and push to ECR.

on:
workflow_dispatch:
push:
branches:
- alephzero
paths-ignore:
- ".github/**"
- "*.md"

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
check-vars-and-secrets:
name: Check vars and secrets
uses: ./.github/workflows/_check-vars-and-secrets.yml
secrets: inherit

build-and-push-subway:
name: Build and push subway image
needs: [check-vars-and-secrets]
runs-on: ubuntu-20.04
steps:
- name: GIT | Checkout Source code
uses: actions/checkout@v4

- name: Call action get-ref-properties
id: get-ref-properties
uses: Cardinal-Cryptography/github-actions/get-ref-properties@v6

- name: Get subway image name
id: get-image-name
env:
ECR_REGISTRY: '${{ vars.ECR_PUBLIC_REGISTRY }}'
APP: subway
TAG: '${{ steps.get-ref-properties.outputs.sha }}'
shell: bash
run: |
image=${{ env.ECR_REGISTRY }}${{ env.APP }}:${{ env.TAG }}
echo "image=${image}" >> $GITHUB_OUTPUT
- name: Build docker image
run: |
docker build --tag '${{ steps.get-image-name.outputs.image }}' -f ./Dockerfile .
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ vars.ECR_PUBLIC_HOST }}
username: ${{ secrets.AWS_MAINNET_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }}

- name: Push image to the ECR registry
id: push-image
run: |
docker push '${{ steps.get-image-name.outputs.image }}'

0 comments on commit 73e3d28

Please sign in to comment.