Use DuploCloud to build and push a Docker image from GitHub Actions
Avoid using capital letters when referencing a DuploCloud construct, such as a Tenant, even when the UI displays the string in all capital letters. Don't specify DEV01, for example; specify dev01. The `TENANT_NAME` may need to be lowercase even though the UI shows it in uppercase.
Build and Push to ECR
This section aims to show you how to build a Docker image and push it to ECR.
It does three things:
Logs in to AWS ECR (using just-in-time AWS credentials from DuploCloud)
Builds and tags your Docker image, with the tags based on the Git commit SHA and ref.
Pushes your Docker image
Example Workflow
Here is an example of a GitHub workflow that builds and pushes a Docker image to ECR.
To use it, ensure the following are configured correctly:
DUPLO_HOST environment variable
DUPLO_TOKEN environment variable
name:Publish Imageon:# Triggers the workflow on push to matching branchespush:branches: - main# (Optional) Allows users to trigger the workflow manually from the GitHub UIworkflow_dispatch: {}# (Optional) Allow other workflows to use this workflow and its outputsworkflow_call:outputs:image:description:The URI of the imagevalue:${{ jobs.build_image.outputs.image }}secrets:DUPLO_TOKEN:description:The token to use for DuploCloud API callsrequired:trueenv:DUPLO_HOST:${{ vars.DUPLO_HOST }}DUPLO_TOKEN:${{ secrets.DUPLO_TOKEN }}# Images are usually stored in a dedicated tenant, so the name doesn't changeDUPLO_TENANT:devopsjobs:build_image:name:Build and Push Imageruns-on:ubuntu-latestoutputs:image:${{ steps.build_image.outputs.uri }}steps: - name:Checkout codeuses:actions/checkout@v4# Configures DuploCloud and the host cloud, for example, AWS - name:Cloud CI Setupuses:v0.0.5# logs into the registry, configures Docker, builds the image, and lastly pushes - name:Build and Push Docker Imageid:build_imageuses:v0.0.5with:platforms:linux/amd64,linux/arm64push:true# false for dry runsbuild-args:> foo=bar ice_cream=chocolate name=${{ github.repository }}