Build a Docker image
Use Duplo to build and push a docker image from Gitlab CI/CD
Case: Build and Push to DockerHub
The goal of this section is to show how you can build a docker image and push it to DockerHub.
It does three basic things:
Logs in to DockerHub
Builds and tags your docker image, with the tag based on the git commit SHA.
Pushes your docker image
Example Workflow
Here is an example gitlab workflow that builds a docker image and pushes it to DockerHub.
To use it you will need to change:
DOCKERHUB_USERNAME
variableDOCKERHUB_REPO
variableDUPLO_HOST
variableDUPLO_SERVICE_NAME
variableTENANT_NAME
variable
Case: Build and Push to Amazon ECR (Elastic Container Registry)
The goal of this section is to show how you can build a docker image and push it to Amazon ECR.
It does three basic things:
Logs in to Amazon ECR
Builds and tags your docker image, with the tag based on the GitLab CI Pipeline execution id.
Pushes your docker image to ECR
Prerequisite - A repository in ECR must have been created before proceeding with the next steps.
This process uses DuploCloud API Token (refer DuploCloud API Token) to gain access to AWS ECR.
Go to GitLab > Settings > CI CD > Variables > Expand and ensure that DUPLO_TOKEN variable is set and has correct value. Check the Protect Variable and Masked options for security purposes. You can refer to Configuring GitLab for the steps to setup a service account and to create a token for the newly configured account. The service account must have admin role.
The script uses amazon/aws-cli image as the base running image and uses Docker-in-Docker (docker/dind) to run the Docker commands. It uses duplo_utils.sh script from DuploCloud to get configuration from the DuploCloud instance.
Example Workflow
Here is an example gitlab workflow that builds a docker image and pushes it to DockerHub.
To use it you will need to change:
DOCKER_REGISTRY
variableDOCKER_REPO
variableDUPLO_HOST
variableDUPLO_SERVICE_NAME
variableTENANT_NAME
variableAWS_DEFAULT_REGION
variableAPP_NAME
variable
Last updated