Skip to content
Latchkey

Publish Docker image workflow (automl/Auto-PyTorch)

The Publish Docker image workflow from automl/Auto-PyTorch, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: automl/Auto-PyTorch.github/workflows/docker-publish.ymlLicense Apache-2.0View source

What it does

This is the Publish Docker image workflow from the automl/Auto-PyTorch repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish Docker image

on:
  push:
    # Push  to `master` or `development`
    branches:
      - master
      - development
      - fixes_docker
  workflow_dispatch:

jobs:
  push_to_registries:
    name: Push Docker image to multiple registries
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2

      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch

      - name: Log in to Docker Hub
        uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      
      - name: Log in to the Container registry
        uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      
      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
        with:
          images: |
            automlorg/autopytorch
            ghcr.io/${{ github.repository }}
      
      - name: Build and push Docker images
        uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
        with:
          context: .
          push: true
          tags: ${{ steps.extract_branch.outputs.branch }}

      - name: Docker Login
        run: docker login ghcr.io -u $GITHUB_ACTOR -p $GITHUB_TOKEN
        env:
            GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

      - name: Pull Docker image
        run: docker pull ghcr.io/$GITHUB_REPOSITORY/autoPyTorch:$BRANCH
        env:
            BRANCH: ${{ steps.extract_branch.outputs.branch }}

      - name: Run image
        run: docker run -i -d --name unittester -v $GITHUB_WORKSPACE:/workspace -w /workspace ghcr.io/$GITHUB_REPOSITORY/autoPyTorch:$BRANCH
        env:
            BRANCH: ${{ steps.extract_branch.outputs.branch }}

      - name: Auto-PyTorch loaded
        run: docker exec  -i unittester python3 -c 'import autoPyTorch; print(f"Auto-PyTorch imported from {autoPyTorch.__file__}")'

      - name: Run unit testing
        run: docker exec  -i unittester python3 -m pytest -v test

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
 
name: Publish Docker image
 
on:
  push:
    # Push  to `master` or `development`
    branches:
      - master
      - development
      - fixes_docker
  workflow_dispatch:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  push_to_registries:
    timeout-minutes: 30
    name: Push Docker image to multiple registries
    runs-on: latchkey-small
    permissions:
      packages: write
      contents: read
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2
 
      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch
 
      - name: Log in to Docker Hub
        uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      
      - name: Log in to the Container registry
        uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      
      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
        with:
          images: |
            automlorg/autopytorch
            ghcr.io/${{ github.repository }}
      
      - name: Build and push Docker images
        uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
        with:
          context: .
          push: true
          tags: ${{ steps.extract_branch.outputs.branch }}
 
      - name: Docker Login
        run: docker login ghcr.io -u $GITHUB_ACTOR -p $GITHUB_TOKEN
        env:
            GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
 
      - name: Pull Docker image
        run: docker pull ghcr.io/$GITHUB_REPOSITORY/autoPyTorch:$BRANCH
        env:
            BRANCH: ${{ steps.extract_branch.outputs.branch }}
 
      - name: Run image
        run: docker run -i -d --name unittester -v $GITHUB_WORKSPACE:/workspace -w /workspace ghcr.io/$GITHUB_REPOSITORY/autoPyTorch:$BRANCH
        env:
            BRANCH: ${{ steps.extract_branch.outputs.branch }}
 
      - name: Auto-PyTorch loaded
        run: docker exec  -i unittester python3 -c 'import autoPyTorch; print(f"Auto-PyTorch imported from {autoPyTorch.__file__}")'
 
      - name: Run unit testing
        run: docker exec  -i unittester python3 -m pytest -v test

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow