Skip to content

Part 1: Build docker images and push it to ECR

andrewC edited this page Sep 8, 2022 · 6 revisions

Overview

Building the docker images (web & api) and pushing them to the AWS ECR is now done through GitHub Actions

Part 1, build once and store the image in ECR on the DS-intersite account and Part 2, deploy the same image to Dev/Test/Live environment.

Drawing1

Run the 'KBS Build and Push API & Web' workflow to build the docker images (web & api) and push them to the AWS ECR

  • i. Raise a PR and get your code change approved and merged into main.
  • ii. Click on the 'Actions' menu item on https://github.com/nationalarchives/ds-book-a-reading-room-visit.
  • iii. Click on the 'KBS Build and Push API & Web' workflow button on the left hand menu.
  • iv. Expand 'Run workflow'.
  • v. Select the Web and/or the API checkbox depending on what you are deploying.
  • vi. Enter the build image version as the version Tag. (Get the version numbers from the AWS console or the Terraform repo)
  • vii. Run the workflow.

*** Steps 1 to 6 below are now superseded by using the 'KBS Build and Push API & Web' GitHub Action to perform them ***

Step 1: Get the latest code from Github (master branch)

Open the power-shell as administrator and navigate to your kbs solution directory on your machine (e.g. cd C:\Repos\ds-book-a-reading-room-visit) and get the latest code from GitHub

`git checkout main'

'git pull'

Step 2: Build the kbs-web docker image

Run the below code, change the version number with subsequent number (refer the ECR on DS-intersite ECR-->Repositories-->kbs-web to find the current image tag and increment by 1). Make sure you include the fullstop at the end of the command otherwise you will get a '"docker build" requires exactly 1 argument'.

docker build -t 500447081210.dkr.ecr.eu-west-2.amazonaws.com/kbs-web:<version> -f Dockerfile-web .

If you get a message 'error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.' make sure you have Docker running on your machine.

Step 3: Build the kbs-api docker image

Run the below code, change the version number with subsequent number (refer the ECR on DS-intersite ECR-->Repositories-->kbs-api to find the current image tag and increment by 1). Make sure you include the fullstop at the end of the command otherwise you will get a '"docker build" requires exactly 1 argument'.

docker build -t 500447081210.dkr.ecr.eu-west-2.amazonaws.com/kbs-api:<version> -f Dockerfile-api .

If you get a message 'error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.' make sure you have Docker running on your machine.

Step 4: Authenticate to the ECR (inter-site account)

Run the below code, replacing with your aws.credentials profile name for the DS-intersite (500447081210) account. (You do not have to change the username and password in the command.)

aws ecr get-login-password --region eu-west-2 --profile <inter-site-profile-account> | docker login --username AWS --password-stdin 500447081210.dkr.ecr.eu-west-2.amazonaws.com

Step 5: Push the kbs web docker image to ECR

Run the below code, change the version number with the build image version

docker push 500447081210.dkr.ecr.eu-west-2.amazonaws.com/kbs-web:<version>

Step 6: Push the kbs api docker image to ECR

Run the below code, change the version number with the build image version

docker push 500447081210.dkr.ecr.eu-west-2.amazonaws.com/kbs-api:<version>

*** End superseded ***

Clone this wiki locally