diff --git a/.github/workflows/build-publish-deploy.yaml b/.github/workflows/build-publish-deploy.yaml deleted file mode 100644 index 2c0338d..0000000 --- a/.github/workflows/build-publish-deploy.yaml +++ /dev/null @@ -1,88 +0,0 @@ -name: Build - publish - deploy - -on: - push: - branches: - - main - 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: gpt-survey-summarizer - APPLICATION_NAME: gpt-survey-summarizer - DOCKER_TAG_PREFIX: ${{ github.event.inputs.docker_tag_prefix }} - PLATFORM: staging - NAMESPACE: governance - -jobs: - build-publish-deploy: - name: Build Publish and Deploy Docker Image - runs-on: minafoundation-default-runners - steps: - - name: ⚙️ Set environment variables - run: | - echo "AWS_REGION=$AWS_REGION" >> $GITHUB_ENV - echo "DEPLOYMENT_ROLE_NAME=$DEPLOYMENT_ROLE_NAME" >> $GITHUB_ENV - echo "AWS_ROLE_DURATION_SECONDS=$AWS_ROLE_DURATION_SECONDS" >> $GITHUB_ENV - - - 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: | - SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7) - if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - echo "TAG=${{ env.DOCKER_TAG_PREFIX }}-${{ steps.application-version.outputs.current-version }}-$SHORT_SHA" >> $GITHUB_ENV - elif [ "${{ github.event_name }}" == "push" ] && [ -n "${{ github.event.ref }}" ]; then - echo "TAG=${{ steps.application-version.outputs.current-version }}-$SHORT_SHA" >> $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 }} - - - name: 🔑 Assume role - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: ${{ env.AWS_REGION }} - role-to-assume: ${{ env.DEPLOYMENT_ROLE_NAME }} - role-session-name: ${{ env.DEPLOYMENT_ROLE_NAME }} - role-duration-seconds: ${{ env.AWS_ROLE_DURATION_SECONDS }} - - - name: ⬇️ Get kubeconfig - run: aws eks update-kubeconfig --name $PLATFORM --region $AWS_REGION 1>/dev/null - - # "*=" means we set the image for every container in the selected deployments - - name: 💿 Set deployment image - run: kubectl set image deployment "*=$ECR_REPOSITORY_URL/$ECR_REPOSITORY_NAME:$TAG" -l app.kubernetes.io/name=$APPLICATION_NAME -n $NAMESPACE - - - name: ⏱️ Wait for deployment to be ready - run: kubectl rollout status deployment --timeout=10m -l app.kubernetes.io/name=$APPLICATION_NAME -n $NAMESPACE diff --git a/.github/workflows/build-publish.yaml b/.github/workflows/build-publish.yaml new file mode 100644 index 0000000..d67a3e2 --- /dev/null +++ b/.github/workflows/build-publish.yaml @@ -0,0 +1,64 @@ +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: gpt-survey-summarizer + +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 }}