Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shrink/28d2bc1446c7acdddfec6dbc540d6c2b to your computer and use it in GitHub Desktop.
Save shrink/28d2bc1446c7acdddfec6dbc540d6c2b to your computer and use it in GitHub Desktop.
Type Builds Image Includes Tags Requires Registry Supports Multi-Platform
local
tar
oci
docker
image
jobs:
build-image:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
name: Build Docker Image
on:
push:
branches:
- "**"
jobs:
build-image:
runs-on: ubuntu-latest
env:
image: "ghcr.io/${{ github.repository }}"
archive: "docker-image.tar"
steps:
- uses: docker/setup-buildx-action@v1
- uses: docker/setup-qemu-action@v1
- uses: docker/build-push-action@v2
with:
outputs: "type=oci,dest=${{ env.archive }}"
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Upload Docker Image as pipeline artifact
uses: actions/upload-artifact@v2
with:
path: "${{ env.archive }}"
name: "${{ env.archive }}"
retention-days: 7
name: Push Docker Image To Registry
on:
workflow_run:
workflows:
- Build Docker Image
types:
- completed
jobs:
push-image-on-success:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
env:
image: "ghcr.io/${{ github.repository }}"
archive: "docker-image.tar"
steps:
- uses: actions/checkout@v2
- name: Download Docker Image from build workflow
uses: dawidd6/action-download-artifact@v2
with:
workflow: build.yml
name: "${{ env.archive }}"
- name: Log in to GitHub Container Registry as actor
uses: docker/login-action@v1
with:
registry: ghcr.io
username: "${{ github.repository_owner }}"
password: "${{ secrets.GHCR_PAT }}"
- id: commit
uses: pr-mpt/actions-commit-hash@v1
with:
commit: ${{ github.event.workflow_run.head_sha }}
prefix: "sha-"
- uses: pr-mpt/actions-push-oci-archive-to-registry@v1
with:
archive: ${{ env.archive }}
tag: "${{ steps.commit.outputs.short }}"
image: "ghcr.io/${{ github.repository }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment