AWS Elastic Container Registry (ECR)
Introduction
Amazon Elastic Container Registry (ECR) is the Docker container registry solution from AWS.
In this article, we will use the TorizonCore Builder Tool to authenticate and pre-provide the modules with a private container image hosted in ECR. This guide assumes you have followed the steps in the Private Registry Introduction and Prerequisites.
This guide offers a general guideline for further development and, therefore, should always be adapted to your specific use case.
In real-world scenarios, ensure you set up the appropriate access control, authentication and permissions.
Set Up the AWS Cloud Environment
Please check Private repository policies and policy examples to find the set of permissions that better fits your specific application.
Create a private registry. For more information, see Getting started with Amazon ECR.
Create two IAM users:
- One with full registry management permission for the host machine.
- Another with read-only permission for the deployed devices (in this guide, we are using AmazonEC2ContainerRegistryReadOnly).
Remember to take note of the credentials. It will be used to authenticate the user.
Install the AWS CLI. In this guide, installing the AWS CLI on the board is not required. For more information, see Getting started with AWS CLI.
Get the Authentication Tokens (Host Machine)
In this guide, we will use an authorization token. For other authentication methods, see Private registry authentication.
To get the authentication tokens on the host machine, proceed as follows:
In the host machine, log in with the host machine
AWS Access Key ID
andAWS Secret Access Key
.$ aws configure
To save the credentials to be used by docker, run the
docker login
command.The
<username>
is "AWS".The
<registry-url>
looks like<aws_account_id>.dkr.ecr.<region>.amazonaws.com
.
$ aws ecr get-login-password | docker login --username <username> --password-stdin <registry-url>
Push the image to AWS. The
docker push
command should be working normally by default, using the host machine Access Keys. For more details, see docker push in ECR.
Push the AWS Docker-Compose to Torizon Cloud Using TCB
It is a best practice to canonicalize the version of the docker-compose file before pushing it to Torizon OTA.
To use torizoncore-builder platform push
with private repositories, we need to authenticate using the following flag:
--login-to <repository-url> <username> <password>
To get the <password>
:
Login using the deployed device
AWS Access Key ID
andAWS Secret Access Key
in the host machine.$ aws configure
Run the
get-login-password
command.$ aws ecr get-login-password
Push the docker-compose file to Torizon Cloud. If you are missing
<path-to-credentials.zip>
, please check the prerequisites.$ torizoncore-builder platform push \
--credentials <path-to-credentials.zip> \
--login-to <registry-url> <username> <password> \
--canonicalize \
<path-to-dockercompose.yml>
Get the Authentication Tokens in AWS (Deployed Device)
The authentication token from AWS is short-lived and expires after 12 hours.
Run the following command to save the authentication token to
/etc/docker/config.json
.$ aws ecr get-login-password | docker --config /etc/docker login --username <username> --password-stdin <registry-url>
Copy the authentication file (
/etc/docker/config.json
) from the host machine to the module and it should be ready to receive an update from Torizon Cloud.This enables that single device to receive an OTA update. Scaling is really simple with torizoncore-builder and Torizon Cloud, check the section on how to enable multiple devices.