Skip to content

Commit

Permalink
update the docker workflow to build a devcontainer specifically
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Pflueger <[email protected]>
  • Loading branch information
jpflueger committed Mar 7, 2024
1 parent c82c2a5 commit fa4b0cb
Showing 1 changed file with 54 additions and 11 deletions.
65 changes: 54 additions & 11 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,80 @@ name: docker

on:
push:
branches: [ main ]
branches: ["main"]
tags: ["v*.*.*"]
paths:
- .devcontainer/Dockerfile
- .github/workflows/docker.yaml
pull_request:
branches: ["main"]
paths:
- .devcontainer/Dockerfile
- .github/workflows/docker.yaml
workflow_dispatch:

jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup version info
run: echo "VERSION=$(date +%Y%m%d-%H%M%S)-g$(git rev-parse --short HEAD)" >> $GITHUB_ENV
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/[email protected]

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
uses: docker/build-push-action@v4
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
push: true
context: ./.devcontainer
platforms: linux/amd64, linux/arm64
images: |
ghcr.io/${{ github.repository }}
tags: |
ghcr.io/fermyon/workshops/dev-container:${{ env.VERSION }}
type=semver,pattern={{version}}
type=ref,event=pr
type=sha,enable={{is_default_branch}},prefix={{date 'YYYYMMDD-HHmmss'}}-,suffix=,format=short
# Build the Docker image with Buildx (don't push yet)
# https://github.com/docker/build-push-action
- name: Build Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .devcontainer
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Uses the cached prebuilt image and adds
# devcontainer features and metadata before pushing
- name: Add devcontainer extras and push
uses: devcontainers/[email protected]
with:
cacheFrom: ghcr.io/${{ github.repository }}
imageName: ghcr.io/${{ github.repository }}
imageTag: ${{ join(steps.meta.outputs.tags) }}
skipContainerUserIdUpdate: true
platform: linux/amd64,linux/arm64

0 comments on commit fa4b0cb

Please sign in to comment.