Docker build and publish #4
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
name: Docker build and publish | |
on: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
version: | |
description: Build with the given version. | |
default: v1.0.0 | |
required: true | |
app: | |
type: choice | |
description: Target application | |
default: 'playground' | |
required: true | |
options: | |
- playground | |
- web | |
- docs | |
- offline | |
dey-run: | |
description: Build with dey-run. | |
required: false | |
push: | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
env: | |
GHCR_REGISTRY: ghcr.io | |
SCOPE: ${{ inputs.app }} | |
IMAGE_NAME: ${{ github.repository }}/${{ inputs.app }} | |
permissions: | |
contents: write # needed to write releases | |
id-token: write # needed for keyless signing | |
packages: write # needed for ghcr access | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# - name: Install cosign | |
# uses: sigstore/[email protected] | |
# - name: Install syft | |
# uses: anchore/sbom-action/[email protected] | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: login to GitHub Artifact Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.GHCR_REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
name=${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }},enable=true | |
labels: | | |
org.opencontainers.image.vendor=MyCompany | |
org.opencontainers.image.licenses=MIT | |
org.opencontainers.image.documentation=docker run -it -e NODE_ENV=production -p 3000:3000 ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
org.opencontainers.image.name=${{ env.IMAGE_NAME }} | |
org.opencontainers.image.authors=sumanth | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: | | |
BUILD_TIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} | |
BUILD_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} | |
BUILD_REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} |