-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup Docker Image Push & Docker Compose Setup (#5)
# Setup Docker Image Push & Docker Compose Setup ## ⚙️ Release Notes - Setup Docker Image Push - Docker Compose Setup ### Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
1 parent
cbda384
commit 06e93cd
Showing
3 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# | ||
# This source file is part of the Stanford Biodesign Digital Health TypeScript Template open-source project | ||
# Based on the Apodini workflow found at: https://github.com/Apodini/.github/workflows/docker-build-and-push.yml | ||
# and the docker documentation found at https://docs.docker.com/build/ci/github-actions/multi-platform/ | ||
# | ||
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
name: Docker Build and Push | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
dockerFile: | ||
description: 'Path or name of the Docker file. The default values is `Dockerfile`. The docker file can use the `baseimage` to get an architecture specific Swift base image' | ||
required: false | ||
type: string | ||
default: 'Dockerfile' | ||
imageName: | ||
description: 'The name used to tag the docker image on the defined registry containing the organzation/account name and the name of the image, e.g.: stanfordbdhg/example' | ||
required: true | ||
type: string | ||
registry: | ||
description: 'Server address of Docker registry. If not set then will default to ghcr.io' | ||
required: false | ||
type: string | ||
default: 'ghcr.io' | ||
workingDirectory: | ||
description: 'The working-directory of the GitHub Action. Defaults to $GITHUB_WORKSPACE' | ||
required: false | ||
type: string | ||
default: '.' | ||
secrets: | ||
username: | ||
description: 'Username for authenticating to the Docker registry. Uses the GitHub actor by default.' | ||
required: false | ||
password: | ||
description: 'Password or personal access token for authenticating the Docker registry. Uses the GitHub token by default.' | ||
required: false | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ${{ inputs.workingDirectory }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: | ||
- linux/amd64 | ||
- linux/arm64 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ inputs.imageName }} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Setup Credentials | ||
id: credentials | ||
run: | | ||
USERNAME=${{ secrets.username }} | ||
PASSWORD=${{ secrets.password }} | ||
if [ -z "$USERNAME" ]; then | ||
USERNAME=${{ github.actor }} | ||
fi | ||
if [ -z "$PASSWORD" ]; then | ||
PASSWORD=${{ secrets.GITHUB_TOKEN }} | ||
fi | ||
echo "username=$USERNAME" >> "$GITHUB_OUTPUT" | ||
echo "password=$PASSWORD" >> "$GITHUB_OUTPUT" | ||
- name: Log in to ${{ inputs.registry }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ inputs.registry }} | ||
username: ${{ steps.credentials.outputs.username }} | ||
password: ${{ steps.credentials.outputs.password }} | ||
- name: Build and push by digest | ||
id: build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ${{ inputs.dockerFile }} | ||
platforms: ${{ matrix.platform }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=${{ inputs.registry }}/${{ inputs.imageName }},push-by-digest=true,name-canonical=true,push=true | ||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
- name: Upload digest | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: digests | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
merge: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build | ||
steps: | ||
- name: Download digests | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: digests | ||
path: /tmp/digests | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ inputs.imageName }} | ||
- name: Setup Credentials | ||
id: credentials | ||
run: | | ||
USERNAME=${{ secrets.username }} | ||
PASSWORD=${{ secrets.password }} | ||
if [ -z "$USERNAME" ]; then | ||
USERNAME=${{ github.actor }} | ||
fi | ||
if [ -z "$PASSWORD" ]; then | ||
PASSWORD=${{ secrets.GITHUB_TOKEN }} | ||
fi | ||
echo "username=$USERNAME" >> "$GITHUB_OUTPUT" | ||
echo "password=$PASSWORD" >> "$GITHUB_OUTPUT" | ||
- name: Log in to ${{ inputs.registry }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ inputs.registry }} | ||
username: ${{ steps.credentials.outputs.username }} | ||
password: ${{ steps.credentials.outputs.password }} | ||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t ${{ inputs.registry }}/" + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ inputs.registry }}/${{ inputs.imageName }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ inputs.registry }}/${{ inputs.imageName }}:${{ steps.meta.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters