Skip to content

[PRMP-820] GoCD -> GitHub Actions #163

[PRMP-820] GoCD -> GitHub Actions

[PRMP-820] GoCD -> GitHub Actions #163

Workflow file for this run

name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read # Required for actions/checkout
id-token: write # Required for requesting the JWT
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'latest'
- run: npm ci
- name: build
run: npm run build
- name: Configure AWS Credentials (Read Write)
if: github.event_name == 'push'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE_ECR_HOLDING_ACCOUNT_READ_WRITE }}
aws-region: eu-west-2
- name: Configure AWS Credentials (Read Only)
if: github.event_name == 'pull_request'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE_ECR_HOLDING_ACCOUNT_READ_ONLY }}
aws-region: eu-west-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Get docker tags
id: get-tags
run: |
sha=$(echo ${{ github.sha }} | cut -c 1-8)
echo "sha=$sha" >> $GITHUB_OUTPUT
branchname=$(echo ${{ github.ref_name }}${{ github.head_ref }} | sed 's/^[0-9]*\/merge//g')
echo "branchname=$branchname" >> $GITHUB_OUTPUT
- name: Get redactor
run: |
mkdir utils/0.2.27
wget --quiet -O utils/0.2.27/run-with-redaction.sh https://github.com/nhsconnect/prm-deductions-support-infra/releases/download/0.2.27/run-with-redaction.sh
wget --quiet -O utils/0.2.27/redactor https://github.com/nhsconnect/prm-deductions-support-infra/releases/download/0.2.27/redactor
chmod +x utils/0.2.27/*
- name: docker build
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }}
SHA_TAG: ${{ steps.get-tags.outputs.sha }}
BRANCH_TAG: ${{ steps.get-tags.outputs.branchname }}
run: |
docker build --build-arg UTILS_VERSION=0.2.27 -t $REGISTRY/$REPOSITORY:$SHA_TAG -t $REGISTRY/$REPOSITORY:$BRANCH_TAG -t $REGISTRY/$REPOSITORY:latest .
# docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -t $REGISTRY/$REPOSITORY:$BRANCH_TAG -t $REGISTRY/$REPOSITORY:latest .
- name: Start LocalStack
uses: LocalStack/[email protected]
# https://docs.aws.amazon.com/cli/latest/reference/dynamodb/create-table.html
- name: Create AWS resources
run: |-
awslocal dynamodb create-table --region eu-west-2 --cli-input-json file://scripts/local-test-db-scheme.json
awslocal s3 mb s3://test-bucket --region eu-west-2
- name: docker compose
env:
S3_BUCKET_NAME: test-bucket
# https://docs.localstack.cloud/user-guide/integrations/sdks/javascript/
LOCALSTACK_URL: http://localhost:4566
DOCKER_IMAGE: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
run: docker compose -f docker-compose-github-actions.yml up -d
- name: sleep
run: sleep 5
- name: docker logs
run: |-
echo "http://localhost:3000/health"
echo $(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/health)
docker logs -t this-service
- name: /health check
env:
SERVICE_URL: http://localhost:3000
run: |-
npm run test:docker
## Eventually we will want to remove this if when branches can be deployed to dev
- name: docker push
if: github.event_name == 'push'
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }}
SHA_TAG: ${{ steps.get-tags.outputs.sha }}
BRANCH_TAG: ${{ steps.get-tags.outputs.branchname }}
run: |
docker push $REGISTRY/$REPOSITORY:$SHA_TAG $REGISTRY/$REPOSITORY:$BRANCH_TAG