6 - Build and push images
Build HCMS and HCMS CSK images and push them to the Elastic Container Registry
You need to build both HCMS and HCMS CSK images and push them to the Elastic Container Registry. You can push both to the same repository.
Create repositories in ECR
In the ECR console, create two repositories, one for each image. Recommended settings:
- namespace: any
- repo-name:
hcms
andhcms-client
- image tag mutability set to mutable: this allows to override the
latest
tag when the image is updated with a new version
Create an IAM user, provide access and get keys
In addition to the IAM user, optionally required on some previous steps, you will need a separate one for the Docker host to be able to push images to ECR using the AWS CLI.
- In the IAM console, create a new user
- Add permissions attaching policies directly (follow the UI)
- Attach the policy
AmazonEC2ContainerRegistryFullAccess
- Attach the policy
- Click on the user, find "Create access key", generate and save the key pair
- In the Terminal, run
aws configure
- Enter credentials after each prompt
Build and push HCMS image
Note Remember to replace the region in all commands below if necessary!
Also, make sure that Docker is running before you use any commands. Optionally, start your Docker Desktop.
Download the Docker image
- Go to our Download Portal
- Search for "censhare HeadlessCMS Docker"
- Download the latest
gz
archive
Note If you are using Safari, you need to use the right-click menu to download the file since Safari unpacks it automatically which we do not want.
For this, on the Download Portal:
- Click on the item you need
- Right-click on "Master"
- Click on "Download linked file"
Build and tag the image
- In the ECR console, click on "View push commands" and follow them; make sure that you are always in the correct folder
- We provide all commands here as well, but with placeholders; you can copy final commands from the console, which is much easier
- Authenticate your Docker host using AWS CLIBASH
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin <<AccountId>>.dkr.ecr.eu-central-1.amazonaws.com
cd
into the folder where you downloaded the archive- Unpack the archive by
tar zxvf censhare-HeadlessCMS-DockerImage-<<build_number>>_master.gz
- Go into the new folder:
cd censhare-HeadlessCMS-DockerImage
- Build the image
docker build -t <<namespace>>/hcms .
Note If you build your image on macOS, please make sure to add --platform linux/amd64 .
as we will be using an Intel-based EC2 instance in the ECS later. Otherwise, you will run into incompatibility problem, since your image will be for ARM and not Intel.
- Tag the image
docker tag <namespace>/hcms:latest <<AccountId>>.dkr.ecr.eu-central-1.amazonaws.com/<<namespace>>/hcms:latest
Push the image to ECR
Still in the same directory, run this command:
docker push <<AccountId>>.dkr.ecr.eu-central-1.amazonaws.com/<<namespace>>/hcms:latest
Check in the ECR, if the image has been uploaded.
Build and push the HCMS CSK image
Note Remember to replace the region in all commands below if necessary!
Build and tag the image
The HCMS CSK image should be built from source.
- You may already have cloned the HCMS CSK repo on one of the previous steps. If not, use the following command:
git clone https://gitlab.censhare.com/oc/product/release/hcms-client-starter-kit.git
- Now build the image:BASH
cd hcms-client-starter-kit docker build -t hcms-client:latest -f deployment/docker/Dockerfile .
Note If you build your image on macOS, please make sure to add --platform linux/amd64 .
as we will be using an Intel-based EC2 instance in the ECS later. Otherwise, you will run into incompatibility problem, since your image will be for ARM and not Intel.
- Tag the image:
docker tag <namespace>/hcms-client:latest <<AccountId>>.dkr.ecr.eu-central-1.amazonaws.com/<<namespace>>/hcms-client:latest
Push the image to ECR
Still in the same directory, run this command:
docker push <<AccountId>>.dkr.ecr.eu-central-1.amazonaws.com/<<namespace>>/hcms-client:latest