From 9610a642f231d6419a8f73feef76779da3888a15 Mon Sep 17 00:00:00 2001 From: Ash Davies <3853061+DrizzlyOwl@users.noreply.github.com> Date: Tue, 24 Jan 2023 10:31:16 +0000 Subject: [PATCH] added workflow for deploying to Dev and Test env --- .../build-and-push-image-development.yml | 105 --------------- .github/workflows/build-and-push-image.yml | 122 ++++++++++++++++++ 2 files changed, 122 insertions(+), 105 deletions(-) delete mode 100644 .github/workflows/build-and-push-image-development.yml create mode 100644 .github/workflows/build-and-push-image.yml diff --git a/.github/workflows/build-and-push-image-development.yml b/.github/workflows/build-and-push-image-development.yml deleted file mode 100644 index d58d39d84..000000000 --- a/.github/workflows/build-and-push-image-development.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: Continuous delivery (Development) - -on: - push: - branches: - - main - -env: - DOCKER_IMAGE: acatran-app - -jobs: - set-env: - name: Prepare - runs-on: ubuntu-latest - outputs: - branch: ${{ steps.var.outputs.branch }} - release: ${{ steps.var.outputs.release }} - steps: - - id: var - run: | - GIT_REF=${{ github.ref }} - GIT_BRANCH=${GIT_REF##*/} - RELEASE=dev-`date +%Y-%m-%d`.${{ github.run_number }} - echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT - echo "release=${RELEASE}" >> $GITHUB_OUTPUT - - build-and-push-image: - name: Build and push image - needs: [ set-env ] - environment: Dev - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Login to ACR - uses: docker/login-action@v2 - with: - username: ${{ secrets.DEVELOPMENT_AZURE_ACR_CLIENTID }} - password: ${{ secrets.DEVELOPMENT_AZURE_ACR_SECRET }} - registry: ${{ secrets.DEVELOPMENT_AZURE_ACR_URL }} - - - name: Build and push image - uses: docker/build-push-action@v3 - with: - context: . - file: Dockerfile.gpaas-azure-migration - tags: | - ${{ secrets.DEVELOPMENT_AZURE_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.branch }} - ${{ secrets.DEVELOPMENT_AZURE_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.release }} - ${{ secrets.DEVELOPMENT_AZURE_ACR_URL }}/${{ env.DOCKER_IMAGE }}:latest - push: true - - create-tag: - name: Tag and release - needs: [ set-env ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Create tag - run: | - git tag ${{ needs.set-env.outputs.release }} - git push origin ${{ needs.set-env.outputs.release }} - - - name: Create release - uses: "actions/github-script@v6" - with: - github-token: "${{ secrets.GITHUB_TOKEN }}" - script: | - try { - await github.rest.repos.createRelease({ - draft: false, - generate_release_notes: true, - name: "${{ needs.set-env.outputs.release }}", - owner: context.repo.owner, - prerelease: false, - repo: context.repo.repo, - tag_name: "${{ needs.set-env.outputs.release }}", - }); - } catch (error) { - core.setFailed(error.message); - } - - deploy-image: - name: Deploy to Development - needs: [ build-and-push-image, set-env ] - runs-on: ubuntu-latest - environment: Dev - steps: - - name: Login to Azure - uses: azure/login@v1 - with: - creds: ${{ secrets.DEVELOPMENT_AZURE_ACA_CREDENTIALS }} - - - name: Update Container Revision - uses: azure/CLI@v1 - with: - azcliversion: 2.40.0 - inlineScript: | - az config set extension.use_dynamic_install=yes_without_prompt - az containerapp update \ - --name ${{ secrets.DEVELOPMENT_AZURE_ACA_CONTAINERAPP_NAME }} \ - --resource-group ${{ secrets.DEVELOPMENT_AZURE_ACA_RESOURCE_GROUP }} \ - --image ${{ secrets.DEVELOPMENT_AZURE_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.release }} \ - --output none diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml new file mode 100644 index 000000000..85806938a --- /dev/null +++ b/.github/workflows/build-and-push-image.yml @@ -0,0 +1,122 @@ +name: Deploy to environment (CIP) + +on: + push: + branches: + - main + workflow_dispatch: + inputs: + environment: + type: environment + description: "Choose an environment to deploy to" + required: true + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +env: + DOCKER_IMAGE: acatran-app + +jobs: + set-env: + name: Determine environment + runs-on: ubuntu-22.04 + outputs: + environment: ${{ steps.var.outputs.environment }} + branch: ${{ steps.var.outputs.branch }} + release: ${{ steps.var.outputs.release }} + steps: + - id: var + run: | + GIT_REF=${{ github.ref }} + GIT_BRANCH=${GIT_REF##*/} + INPUT=${{ github.event.inputs.environment }} + ENVIRONMENT=${INPUT:-"dev"} + RELEASE=${ENVIRONMENT,,}-`date +%Y-%m-%d`.${{ github.run_number }} + echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT + echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT + echo "release=${RELEASE}" >> $GITHUB_OUTPUT + + build-and-push-image: + name: Build and push to ACR + needs: set-env + runs-on: ubuntu-22.04 + environment: ${{ needs.set-env.outputs.environment }} + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + + - name: Azure Container Registry login + uses: docker/login-action@v2 + with: + username: ${{ secrets.CIP_ACR_CLIENTID }} + password: ${{ secrets.CIP_ACR_SECRET }} + registry: ${{ secrets.CIP_ACR_URL }} + + - name: Build and push docker image + uses: docker/build-push-action@v3 + with: + context: . + file: Dockerfile.gpaas-azure-migration + tags: | + ${{ secrets.CIP_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.branch }} + ${{ secrets.CIP_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.release }} + ${{ secrets.CIP_ACR_URL }}/${{ env.DOCKER_IMAGE }}:latest + push: true + + create-tag: + name: Tag and release + needs: set-env + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + + - name: Create tag + run: | + git tag ${{ needs.set-env.outputs.release }} + git push origin ${{ needs.set-env.outputs.release }} + + - name: Create release + uses: "actions/github-script@v6" + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + script: | + try { + await github.rest.repos.createRelease({ + draft: ${{ needs.set-env.outputs.environment == 'staging' }}, + generate_release_notes: true, + name: "${{ needs.set-env.outputs.release }}", + owner: context.repo.owner, + prerelease: ${{ needs.set-env.outputs.environment == 'staging' }}, + repo: context.repo.repo, + tag_name: "${{ needs.set-env.outputs.release }}", + }); + } catch (error) { + core.setFailed(error.message); + } + + deploy-image: + name: Deploy to ${{ needs.set-env.outputs.environment }} + needs: [ build-and-push-image, set-env ] + runs-on: ubuntu-22.04 + environment: ${{ needs.set-env.outputs.environment }} + steps: + - name: Azure login with ACA credentials + uses: azure/login@v1 + with: + creds: ${{ secrets.CIP_ACA_CREDENTIALS }} + + - name: Update Azure Container Apps Revision + uses: azure/CLI@v1 + with: + azcliversion: 2.40.0 + inlineScript: | + az config set extension.use_dynamic_install=yes_without_prompt + az containerapp update \ + --name ${{ secrets.CIP_ACA_CONTAINERAPP_NAME }} \ + --resource-group ${{ secrets.CIP_ACA_RESOURCE_GROUP }} \ + --image ${{ secrets.CIP_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.release }} \ + --output none