Skip to content

Commit

Permalink
Additional labels, vars, and image types (#24)
Browse files Browse the repository at this point in the history
* Set 'push' and 'provenance' based on envVars

* Add additional platforms to builds

* Allow more platforms for OpenTofu

* kubectl Dockerfile matches new patterns

* Remove Darwin platform

* provenance false, additional labels and tags
  • Loading branch information
iodeslykos authored Jan 15, 2024
1 parent 91a23e3 commit b7a1275
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ on:
workflow_dispatch:

env:
PUSH_IMAGES: true
PUSH_IMAGES: ${{ github.ref == 'refs/heads/trunk' }}
PROVENANCE: false

jobs:
build-base-images:
Expand All @@ -34,6 +35,7 @@ jobs:
supported_platforms:
- linux/amd64
- linux/arm64
- linux/arm64/v8
- context: base/alpine
image_name: ${{ github.repository_owner }}/alpine
description: "Alpine Linux"
Expand All @@ -42,6 +44,7 @@ jobs:
- linux/arm64
- linux/arm/v7
- linux/arm/v8
- linux/arm64/v8
- context: base/debian
image_name: ${{ github.repository_owner }}/debian
description: "Debian Linux (Slim)"
Expand All @@ -50,6 +53,7 @@ jobs:
- linux/arm64
- linux/arm/v7
- linux/arm/v8
- linux/arm64/v8
outputs:
digests: ${{ steps.build-push-image.outputs.digest }}
steps:
Expand Down Expand Up @@ -80,18 +84,22 @@ jobs:
with:
context: ${{ matrix.images.context }}
file: ${{ matrix.images.context }}/Dockerfile
push: true
provenance: true
push: ${{ env.PUSH_IMAGES }}
provenance: ${{ env.PROVENANCE }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ matrix.images.image_name }}:latest
ghcr.io/${{ matrix.images.image_name }}:latest
${{ matrix.images.image_name }}:${{ github.sha }}
ghcr.io/${{ matrix.images.image_name }}:${{ github.sha }}
platforms: ${{ join(matrix.images.supported_platforms, ',') }}
labels: |-
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.source=https://github.com/${{ github.repository}}
org.opencontainers.image.description=${{ matrix.images.description }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.title=${{ matrix.images.image_name }}
build-tool-images:
needs: build-base-images
Expand All @@ -111,6 +119,7 @@ jobs:
- linux/arm64
- linux/arm/v7
- linux/arm/v8
- linux/arm64/v8
- context: tools/kubectl
image_name: ${{ github.repository_owner }}/kubectl
description: "Kubectl is a CLI tool for running commands against Kubernetes clusters."
Expand Down Expand Up @@ -147,14 +156,19 @@ jobs:
context: ${{ matrix.images.context }}
file: ${{ matrix.images.context }}/Dockerfile
push: ${{ env.PUSH_IMAGES}}
provenance: true
provenance: ${{ env.PROVENANCE }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ matrix.images.image_name }}:latest
ghcr.io/${{ matrix.images.image_name }}:latest
${{ matrix.images.image_name }}:${{ github.sha }}
ghcr.io/${{ matrix.images.image_name }}:${{ github.sha }}
platforms: ${{ join(matrix.images.supported_platforms, ',') }}
labels: |-
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.source=https://github.com/${{ github.repository}}
org.opencontainers.image.description=${{ matrix.images.description }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.title=${{ matrix.images.image_name }}
org.opencontainers.image.version=${{ github.ref }}
7 changes: 4 additions & 3 deletions tools/kubectl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ LABEL org.opencontainers.image.authors="iodeslykos <42@iodeslykos.com>"

ARG VERSION=v1.29.0
ARG TARGETPLATFORM
ARG TARGETARCH
ARG TARGETOS
ENV USER=outis

WORKDIR /tmp

# hadolint ignore=DL4006
RUN TARGET_ARCH=$(echo "${TARGETPLATFORM}" | cut -d '/' -f2) \
&& curl -LO "https://dl.k8s.io/release/${VERSION}/bin/linux/${TARGET_ARCH}/kubectl" \
&& curl -LO "https://dl.k8s.io/${VERSION}/bin/linux/${TARGET_ARCH}/kubectl.sha256" \
RUN curl -LO "https://dl.k8s.io/release/${VERSION}/bin/linux/${TARGETARCH}/kubectl" \
&& curl -LO "https://dl.k8s.io/${VERSION}/bin/linux/${TARGETARCH}/kubectl.sha256" \
&& echo "$(cat kubectl.sha256) kubectl" | sha256sum -c - \
&& mv kubectl /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl
Expand Down
9 changes: 5 additions & 4 deletions tools/opentofu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ LABEL org.opencontainers.image.source="https://github.com/opentofu/opentofu/"

ARG WORKDIR=/tmp/opentofu
ARG TARGETPLATFORM
ARG TARGETARCH
ARG TARGETOS
ARG APP=tofu
ARG VERSION='1.6.0'

Expand All @@ -17,12 +19,11 @@ WORKDIR ${WORKDIR}

# hadolint ignore=DL3018
RUN apk add --no-cache \
curl
curl

# hadolint ignore=DL4006
RUN TARGET_ARCH=$(echo "${TARGETPLATFORM}" | cut -d '/' -f2) \
&& curl -fsSL -o "${WORKDIR}/${APP}.apk" \
"https://github.com/opentofu/opentofu/releases/download/v${VERSION}/${APP}_${VERSION}_${TARGET_ARCH}.apk" \
RUN curl -fsSL -o "${WORKDIR}/${APP}.apk" \
"https://github.com/opentofu/opentofu/releases/download/v${VERSION}/${APP}_${VERSION}_${TARGETARCH}.apk" \
&& apk add --no-cache --allow-untrusted \
"${WORKDIR}/${APP}.apk" \
&& rm -rf "${WORKDIR}/${APP}.apk"
Expand Down

0 comments on commit b7a1275

Please sign in to comment.