Skip to content

Publish - 1780-new-pipeline to development by @Pooley3100 #267

Publish - 1780-new-pipeline to development by @Pooley3100

Publish - 1780-new-pipeline to development by @Pooley3100 #267

Workflow file for this run

name: Publish
run-name: Publish - ${{ github.head_ref || github.ref_name }} to ${{ inputs.environment }} by @${{ github.actor }}
on:
push:
branches: [main]
workflow_dispatch:
inputs:
environment:
type: environment
description: The environment to deploy to.
jobs:
detect-environments:
runs-on: ubuntu-latest
outputs:
environments: ${{ steps.environments.outputs.result }}
steps:
- uses: actions/github-script@v6
id: environments
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: json
script: |
if (context.payload?.inputs?.environment) return [context.payload?.inputs?.environment];
const {data: {environments}} =
await github.request(`GET /repos/${process.env.GITHUB_REPOSITORY}/environments`);
return environments.map(e => e.name)
test:
uses: ./.github/workflows/test.yml
publish-request-api:
runs-on: ubuntu-22.04
needs: [detect-environments, test]
strategy:
matrix:
environment: ${{ fromJSON(needs.detect-environments.outputs.environments) }}
environment: ${{ matrix.environment }}
env:
DOCKER_REPO: ${{ secrets.DEPLOY_DOCKER_REPOSITORY_REQUEST_API }}
steps:
- uses: actions/checkout@v4
- id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install --update
sudo apt-get update
sudo apt-get install -y rsync
- uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- run: docker pull $DOCKER_REPO:${GITHUB_REF_NAME} || echo "no current latest image"
- run: docker build --build-arg DEPLOY_TIME="$(date +%Y-%m-%dT%H:%M:%S)" --build-arg GIT_COMMIT="${{ steps.vars.outputs.sha_short }}" -t $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} -f request-api/Dockerfile .
- run: docker tag $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} $DOCKER_REPO:main
- run: docker push $DOCKER_REPO:${{ steps.vars.outputs.sha_short }}
- run: docker push $DOCKER_REPO:main
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Update ECS Service
run: |
aws ecs update-service --cluster ${{ matrix.environment }}-cluster --service ${{ matrix.environment }}-pub-async-request-api --task-definition ${{ matrix.environment }}-pub-async-request-api-task --force-new-deployment
publish-request-processor:
runs-on: ubuntu-22.04
needs: [detect-environments, test]
strategy:
matrix:
environment: ${{ fromJSON(needs.detect-environments.outputs.environments) }}
environment: ${{ matrix.environment }}
env:
DOCKER_REPO: ${{ secrets.DEPLOY_DOCKER_REPOSITORY_REQUEST_PROCESSOR }}
steps:
- uses: actions/checkout@v4
- id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install --update
sudo apt-get update
sudo apt-get install -y rsync
- uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- run: docker pull $DOCKER_REPO:${GITHUB_REF_NAME} || echo "no current latest image"
- run: docker build --build-arg DEPLOY_TIME="$(date +%Y-%m-%dT%H:%M:%S)" --build-arg GIT_COMMIT="${{ steps.vars.outputs.sha_short }}" -t $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} -f request-processor/Dockerfile .
- run: docker tag $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} $DOCKER_REPO:main
- run: docker push $DOCKER_REPO:${{ steps.vars.outputs.sha_short }}
- run: docker push $DOCKER_REPO:main
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Update ECS Service (Processor)
run: |
aws ecs update-service --cluster ${{ matrix.environment }}-cluster --service ${{ matrix.environment }}-pub-async-request-processor --task-definition ${{ matrix.environment }}-pub-async-request-processor-task --force-new-deployment