Skip to content

Commit

Permalink
add docker raw output and docker merge for distrubted multi-arch builds
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreat committed Nov 13, 2024
1 parent f8df38e commit ff8b914
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
71 changes: 71 additions & 0 deletions docker-merge-digests/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Mobilecoin Docker
description: Standardized docker build and publish actions

inputs:
digest_artifact_prefix:
description: Prefix for the artifact names to restore
required: false
default: ""
flavor:
description: New line separated list of docker meta flavor options
required: false
default: "latest=false"
images:
description: URL/Path to docker image registry
default: ""
required: false
tags:
description: New line separated list of tags for the docker image
required: false
default: ""
username:
description: docker registry user
default: ""
required: false
password:
description: docker registry password
default: ""
required: false

outputs:
tags:
description: docker/meta-action tags
value: ${{ steps.docker_meta.output.tags }}

runs:
using: composite
steps:
- name: Download digests
uses: mobilecoinofficial/gh-actions/download-artifact@v0
with:
path: /tmp/digests
pattern: ${{ inputs.digest_artifact_prefix }}*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Generate Docker Tags
id: docker_meta
uses: docker/metadata-action@v5
with:
flavor: ${{ inputs.flavor }}
images: ${{ inputs.images }}
tags: ${{ inputs.tags }}

- name: Login to DockerHub
if: inputs.username && inputs.password
uses: docker/login-action@v3
with:
username: ${{ inputs.username }}
password: ${{ inputs.password }}

- name: Create manifest list and push
shell: bash
working-directory: /tmp/digests
run: |
# Grab the tags from metadata-action ENV with jq
# Gather all the digests for the images pushed (names of empty files stored as artifacts)
# Push a manifest (tag) with all the digests to dockerhub
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ inputs.images }}@sha256:%s ' *)
19 changes: 14 additions & 5 deletions docker/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ inputs:
flavor:
description: New line separated list of docker meta flavor options
required: false
default: |
latest=true
default: "latest=false"
platforms:
description: comma separated list of platforms to build for linux/amd64,linux/arm64
default: ""
Expand All @@ -36,7 +35,8 @@ inputs:
required: false
tags:
description: New line separated list of tags for the docker image
required: true
required: false
default: ""
target:
description: Sets the target stage to build in Dockerfile
required: false
Expand All @@ -49,14 +49,21 @@ inputs:
description: docker registry password
default: ""
required: false
outputs:
description: override the image output methods https://docs.docker.com/build/exporters/
required: false
default: ""

outputs:
tags:
description: docker/meta-action tags
value: ${{ steps.docker_meta.tags }}
value: ${{ steps.docker_meta.output.tags }}
pushed:
description: was the docker image published to the registry
value: ${{ inputs.push }}
digest:
description: docker image digest
value: ${{ steps.docker_build.outputs.digest }}

runs:
using: composite
Expand Down Expand Up @@ -85,6 +92,7 @@ runs:
password: ${{ inputs.password }}

- name: Publish to DockerHub
id: docker_build
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_CHECKS_ANNOTATIONS: "false"
Expand All @@ -97,5 +105,6 @@ runs:
labels: ${{ steps.docker_meta.outputs.labels }}
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
tags: ${{ steps.docker_meta.outputs.tags }}
tags: ${{ inputs.outputs == '' && steps.docker_meta.outputs.tags || '' }}
target: ${{ inputs.target }}
outputs: ${{ inputs.outputs }}
16 changes: 16 additions & 0 deletions short-sha/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Short SHA
description: Just spit out the short SHA (7) of the commit.

outputs:
short_sha:
description: Short SHA (7) of the commit
value: ${{ steps.short_sha.outputs.sha }}

runs:
using: composite
steps:
- name: Get short SHA
shell: bash
id: short_sha
run: |
echo "sha=sha-${GITHUB_SHA::7}" >> "${GITHUB_OUTPUT}"

0 comments on commit ff8b914

Please sign in to comment.