From 2e7f73a1df0215c51d1f6bc0dad8ec8ac97251b8 Mon Sep 17 00:00:00 2001 From: David Lehuby Date: Thu, 22 Aug 2024 10:33:51 +1000 Subject: [PATCH] PM-1940 - Add CI Configuration --- .github/workflows/build-publish.yaml | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/build-publish.yaml diff --git a/.github/workflows/build-publish.yaml b/.github/workflows/build-publish.yaml new file mode 100644 index 0000000..abf2227 --- /dev/null +++ b/.github/workflows/build-publish.yaml @@ -0,0 +1,63 @@ +name: Build - publish + +on: + push: + branches: + - main + workflow_dispatch: + inputs: + docker_tag_suffix: + description: "Enter a Docker Tag suffix (e.g dev)\nSuffixed images will not be auto-deployed" + required: false + type: string + +env: + ECR_REPOSITORY_URL: 673156464838.dkr.ecr.us-west-2.amazonaws.com + ECR_REPOSITORY_NAME: pgt-gov-bot-ocv-web + +jobs: + build-publish: + name: Build and Publish Docker Image + runs-on: minafoundation-default-runners + steps: + - name: 📥 Checkout + uses: actions/checkout@v4 + + - name: 🦀 Get application version from package.json + id: application-version + uses: martinbeentjes/npm-get-version-action@v1.3.1 + + - name: 🏷️ Generate Tag + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + if [ "${{ github.event.inputs.docker_tag_suffix }}" != "" ]; then + echo "TAG=${{ steps.application-version.outputs.current-version }}-${{ github.event.inputs.docker_tag_suffix }}" >> $GITHUB_ENV + else + echo "TAG=${{ steps.application-version.outputs.current-version }}" >> $GITHUB_ENV + fi + elif [ "${{ github.event_name }}" == "push" ] && [ -n "${{ github.event.ref }}" ]; then + echo "TAG=${{ steps.application-version.outputs.current-version }}" >> $GITHUB_ENV + else + echo "Invalid event. Exiting..." + exit 1 + fi + + - name: 🔑 ECR Login + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - 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 and Push Docker + uses: mr-smithers-excellent/docker-build-push@v6 + if: steps.checktag.outputs.tag == 'not found' + with: + image: ${{ env.ECR_REPOSITORY_NAME }} + registry: ${{ env.ECR_REPOSITORY_URL }} + tags: ${{ env.TAG }}