Skip to content

Commit

Permalink
ci: inject dockerfile dependency versions from workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
zerok committed Nov 26, 2024
1 parent fb6380f commit 0c2dea8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,34 @@ env:
type=semver,pattern={{version}},value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
jobs:
determine-versions:
runs-on: ubuntu-latest
outputs:
helm: ${{ steps.versions.outputs.helm }}
kustomize: ${{ steps.versions.outputs.kustomize }}
steps:
- name: "Determine dependency versions"
id: "versions"
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const helmRelease = await github.rest.repos.getLatestRelease({
'owner': 'helm',
'repo': 'helm',
});
core.setOutput('helm', helmRelease.data.tag_name);
console.log('Helm version', helmRelease.data.tag_name);
const kustomizeReleases = await github.rest.repos.listReleases({
'owner': 'kubernetes-sigs',
'repo': 'kustomize',
});
const kustomizeRelease = kustomizeReleases.data.filter(release => release.tag_name.startsWith('kustomize') && !release.draft && !release.prerelease).map(release => release.tag_name.split('/')[1])[0];
console.log('Kustomize version', kustomizeRelease);
core.setOutput('kustomize', kustomizeRelease);
build:
needs:
- determine-versions
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -66,6 +93,9 @@ jobs:
context: .
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.event_name == 'push' }}
build-args: |
HELM_VERSION=${{ needs.determine-versions.outputs.helm }}
KUSTOMIZE_VERSION=${{ needs.determine-versions.outputs.kustomize }}
- name: Export digest
id: digest
Expand Down
15 changes: 6 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,21 @@ RUN apk add --no-cache git make bash &&\

FROM golang:1.23.3-alpine AS helm
WORKDIR /tmp/helm
ARG HELM_VERSION
RUN apk add --no-cache jq curl
RUN export TAG=$(curl --silent "https://api.github.com/repos/helm/helm/releases/latest" | jq -r .tag_name) &&\
export OS=$(go env GOOS) &&\
export ARCH=$(go env GOARCH) &&\
curl -SL "https://get.helm.sh/helm-${TAG}-${OS}-${ARCH}.tar.gz" > helm.tgz && \
RUN curl -SL "https://get.helm.sh/helm-${HELM_VERSION}-${OS}-${ARCH}.tar.gz" > helm.tgz && \
tar -xvf helm.tgz --strip-components=1

FROM golang:1.23.3-alpine AS kustomize
WORKDIR /tmp/kustomize
ARG KUSTOMIZE_VERSION
RUN apk add --no-cache jq curl
# Get the latest version of kustomize
# Releases are filtered by their name since the kustomize repository exposes multiple products in the releases
RUN export TAG=$(curl --silent "https://api.github.com/repos/kubernetes-sigs/kustomize/releases" | jq -r '[ .[] | select(.name | startswith("kustomize")) ] | .[0].tag_name') &&\
export VERSION_TAG=${TAG#*/} &&\
export OS=$(go env GOOS) &&\
RUN export OS=$(go env GOOS) &&\
export ARCH=$(go env GOARCH) &&\
echo "https://github.com/kubernetes-sigs/kustomize/releases/download/${TAG}/kustomize_${VERSION_TAG}_${OS}_${ARCH}.tar.gz" && \
curl -SL "https://github.com/kubernetes-sigs/kustomize/releases/download/${TAG}/kustomize_${VERSION_TAG}_${OS}_${ARCH}.tar.gz" > kustomize.tgz && \
echo "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_${OS}_${ARCH}.tar.gz" && \
curl -SL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_${OS}_${ARCH}.tar.gz" > kustomize.tgz && \
tar -xvf kustomize.tgz

FROM golang:1.23.3 AS build
Expand Down

0 comments on commit 0c2dea8

Please sign in to comment.