Skip to content

Instantly share code, notes, and snippets.

@mitchallen
Last active September 16, 2023 19:47
Show Gist options
  • Save mitchallen/48a370c315de03877edfee85e3e08f96 to your computer and use it in GitHub Desktop.
Save mitchallen/48a370c315de03877edfee85e3e08f96 to your computer and use it in GitHub Desktop.
Example GitHub Action workflow to publish a docker container image
name: publish
on:
push:
tags:
- 'v*'
jobs:
publish-docker-image:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the Docker image
run: |
tag=${GITHUB_REF#refs/tags/}
tag=${tag:1}
image=ghcr.io/${GITHUB_REPOSITORY}
docker build . -t ${image}:${tag} -t ${image}:latest
docker push ${image} --all-tags
@mitchallen
Copy link
Author

  • pinned runs-on to a specific version
  • added a timeout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment