Skip to main content
Version: Torizon OS 7.x.y

GitHub Container Registry

Introduction

GitHub Container Registry is a solution from GitHub to store Docker images inside a package registry.

In this article, we will use the TorizonCore Builder Tool to authenticate and pre-provide the target devices with a private container image hosted in GitHub. This guide assumes you have followed the steps in the Private Registry Introduction and Prerequisites.

Disclaimer

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 GitHub Cloud Environment

caution

Please check GitHub Authenticate with the packages registry to find the set of permissions that better fits your specific application.

  1. Create a private registry: For more information, see GitHub container registry.
  2. Create the authentication token: For more information, see how to create a personal token.
    • One access token with full registry management permission for the host machine.
    • Another with read-only permission for the deployed devices (in this guide, we are using read:packages permission).

Get the Authentication Tokens (Host Machine)

tip

In this guide, we are going to use a Personal Access Token (classic). For other authentication methods, check GitHub Authenticate with the container registry.

  1. To save the credentials to be used by docker, run the docker login command.

    $ docker login --username <username> --password <token> ghcr.io
  2. Push the Image to GitHub Cloud. The docker push command should be working normally by default, using the host machine token. For more information, see docker push in GitHub.

Push the GitHub docker-compose to Torizon Cloud using TCB

tip

It is a best practice to canonicalize the version of the docker-compose file before pushing it to Torizon OTA.

  1. To use torizoncore-builder platform push with private repositories, we need to authenticate using the following flag:

    --login-to <repository-url> <username> <token>
    • The <username> is the account email or username.
    • The <token> is the access token.
  2. Push the docker-compose file to Torizon Cloud. If you are missing the <path-to-credentials.zip>, please refer to the prerequisites.

    $ torizoncore-builder platform push \
    --credentials <path-to-credentials.zip> \
    --login-to ghcr.io <username> <token> \
    --canonicalize \
    <path-to-dockercompose.yml>

Get the Authentication Tokens (Deployed Device)

danger

The authentication token from GitHub is short-lived and expires after 30 days by default, the expiration date can be set when creating the token.

  1. Run the following command to save the authentication token to /etc/docker/config.json.

    $ docker --config /etc/docker login --username <username> --password <token> ghcr.io
  2. Copy the authentication file (/etc/docker/config.json) from the host machine to the target device and it should be ready to receive an update from the Torizon Cloud.

    This is going to enable this 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.

For more information on setting up a container update, take a look at the overview article. If you want to learn more, see Torizon Cloud Web Interface.



Send Feedback!