From 5c7a29f26033b49bdbfb695c9ddc5c3985f06b1f Mon Sep 17 00:00:00 2001 From: David Lehuby Date: Mon, 29 Jan 2024 13:33:58 +1000 Subject: [PATCH] PM-1102 - Create Publish Github Action Workflow --- .github/workflows/publish.yaml | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..b658b82 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,56 @@ +name: Publish + +on: + push: + tags: + - '*' + workflow_dispatch: + inputs: + docker_tag_prefix: + description: "Enter the Docker Tag Prefix (e.g adhoc-test)" + required: true + type: string +env: + ECR_REPOSITORY_URL: 673156464838.dkr.ecr.us-west-2.amazonaws.com + ECR_REPOSITORY_NAME: delegation-verify-coordinator + DOCKER_TAG_PREFIX: ${{ github.event.inputs.docker_tag_prefix }} + +# This allows a subsequently queued workflow run to interrupt previous runs +concurrency: + group: '${{ github.workflow }} @ ${{ github.head_ref || github.ref }}' + cancel-in-progress: true + +jobs: + build-docker-image: + name: Build and Push Docker Image + runs-on: minafoundation-default-runners + steps: + - name: 📥 Checkout + uses: actions/checkout@v3 + - name: 🏷️ Generate Tag + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + PREFIX=${{ env.DOCKER_TAG_PREFIX }} + elif [ "${{ github.event_name }}" == "push" ] && [ -n "${{ github.event.ref }}" ]; then + PREFIX=$(basename ${{ github.ref }}) + else + echo "Invalid event. Exiting..." + exit 1 + fi + echo "TAG=$PREFIX-$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV + - name: 🔑 ECR Login + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: 🔍 Check if Tag already exists + id: checktag + uses: tyriis/docker-image-tag-exists@main + with: + registry: ${{ env.ECR_REPOSITORY_URL}} + repository: ${{ env.ECR_REPOSITORY_NAME }} + tag: ${{ env.TAG }} + - name: 🛠️ Build Uptime Service Validation Docker Image + if: steps.checktag.outputs.tag == 'not found' + run: DOCKER_BUILDKIT=1 docker build -t ${{ env.ECR_REPOSITORY_URL}}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.TAG }} . + - name: 🚚 Push Uptime Service Validation Docker Image + if: steps.checktag.outputs.tag == 'not found' + run: docker push ${{ env.ECR_REPOSITORY_URL}}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.TAG }}