Build a Docker image

Use Duplo 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 as all capital letters. Don't specify DEV01 for example, specify dev01.

Build and Push to ECR

The goal of this section is to show how you can build a docker image and push it to ECR.

It does three basic things:

  • Logs in to AWS ECR (using just-in-time AWS credentials from Duplo)

  • Builds and tags your docker image, with the tag based on the git commit SHA and ref.

  • Pushes your docker image

Example Workflow

Here is an example github workflow that builds a docker image and pushes it to ECR.

To use it you will need to ensure the following are configured correctly:

  • DUPLO_HOST env var

  • DUPLO_TOKEN env var

name: Publish Image
on:
  # Triggers the workflow on push to matching branches
  push:
    branches:
    - main
  # (Optional) Allows users to trigger the workflow manually from the GitHub UI
  workflow_dispatch: {}
  # (Optional) Allow other workflows to use this workflow ant its outputs
  workflow_call: 
    outputs:
      image:
        description: The URI of the image
        value: ${{ jobs.build_image.outputs.image }}
    secrets:
      DUPLO_TOKEN:
        description: The token to use for Duplo API calls
        required: true

env:
  DUPLO_HOST: ${{ vars.DUPLO_HOST }}
  DUPLO_TOKEN: ${{ secrets.DUPLO_TOKEN }}
  # Images are usually stored in a dediacted tenant, so the name doesn't change
  DUPLO_TENANT: devops

jobs:
  build_image:
    name: Build and Push Image
    runs-on: ubuntu-latest
    outputs:
      image: ${{ steps.build_image.outputs.uri }}
    steps:

    - name: Checkout code
      uses: actions/checkout@v4

    # configures duplocloud and host cloud, eg aws
    - name: Cloud CI Setup
      uses: v0.0.5
    
    # logs into registry, configures docker, builds image, lastly pushes
    - name: Build and Push Docker Image
      id: build_image
      uses: v0.0.5
      with:
        platforms: linux/amd64,linux/arm64
        push: true # false for dry runs
        build-args: >
          foo=bar
          ice_cream=chocolate
          name=${{ github.repository }}

References

Last updated

Logo

© DuploCloud, Inc. All rights reserved. DuploCloud trademarks used herein are registered trademarks of DuploCloud and affiliates