Skip to content

Commit 90451d6

Browse files
committed
Put metadata in image annotations
Attestations in the image manifest aren't really usable with current tooling. This also uses GitHub to attest the image provenance
1 parent 5f83a55 commit 90451d6

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

.github/workflows/base-image.yaml

+25-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- image/Dockerfile-base
99
- .github/workflows/base-image.yaml
1010
schedule:
11-
- cron: 0 1 * * 1
11+
- cron: 0 1 1 * *
1212

1313
permissions:
1414
contents: read
@@ -17,31 +17,53 @@ jobs:
1717
push_image:
1818
runs-on: ubuntu-24.04
1919
name: Docker Images
20-
env:
21-
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
20+
permissions:
21+
id-token: write
22+
attestations: write
23+
environment:
24+
name: dockerhub
25+
url: https://hub.docker.com/r/danielflook/terraform-github-actions-base/tags?name=${{ github.run_id }}
2226
steps:
2327
- name: Checkout
2428
uses: actions/checkout@v4
2529
with:
2630
persist-credentials: false
2731

2832
- name: Registry login
33+
env:
34+
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
2935
run: |
3036
echo $DOCKER_TOKEN | docker login --username danielflook --password-stdin
3137
3238
- name: Set up Docker Buildx
3339
uses: docker/setup-buildx-action@v2
3440

3541
- name: Base image
42+
id: build-and-push
3643
run: |
3744
docker buildx build \
3845
--tag danielflook/terraform-github-actions-base:$GITHUB_RUN_ID \
3946
--tag danielflook/terraform-github-actions-base:latest \
4047
--platform linux/amd64,linux/arm64 \
4148
--attest type=provenance,mode=max,builder-id=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID \
49+
--annotation "index,manifest:org.opencontainers.image.created=$(date '+%Y-%m-%dT%H:%M:%S%z')" \
50+
--annotation "index,manifest:org.opencontainers.image.source=https://github.com/${{ github.repository }}" \
51+
--annotation "index,manifest:org.opencontainers.image.revision=${{ github.sha }}" \
52+
--annotation "index,manifest:org.opencontainers.image.title=terraform-github-actions-base" \
53+
--annotation "index,manifest:org.opencontainers.image.description=Base image for terraform-github-actions" \
54+
--annotation "index:org.opencontainers.image.ref.name=docker.io/danielflook/terraform-github-actions-base:$GITHUB_RUN_ID" \
55+
--annotation "index,manifest:builder-id=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
56+
--annotation "index,manifest:ref.tag=$GITHUB_RUN_ID" \
57+
--annotation "index,manifest:org.opencontainers.image.base.name=docker.io/debian:bullseye-slim" \
4258
--file image/Dockerfile-base \
4359
--push \
4460
--iidfile manifest-list-digest.txt \
4561
image
4662
4763
echo "digest=$(<manifest-list-digest.txt)" >> "$GITHUB_OUTPUT"
64+
65+
- name: Generate image attestation
66+
uses: actions/attest-build-provenance@v2
67+
with:
68+
subject-name: index.docker.io/danielflook/terraform-github-actions-base
69+
subject-digest: ${{ steps.build-and-push.outputs.digest }}

image/Dockerfile

-12
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ ARG TARGETARCH
55
ARG FETCH_CHECKSUMS
66
ARG VERSION=99.0.0
77

8-
RUN gpg --recv-keys C874011F0AB405110D02105534365D9472D7468F \
9-
&& echo "C874011F0AB405110D02105534365D9472D7468F:6:" | gpg --import-ownertrust
10-
11-
RUN curl https://get.opentofu.org/opentofu.gpg | gpg --import \
12-
&& echo "E3E6E43D84CB852EADB0051D0C0AF313E5FD9F80:6:" | gpg --import-ownertrust
13-
14-
RUN gpg --check-trustdb
15-
168
COPY src/ /tmp/src/
179
COPY setup.py /tmp
1810
RUN sed -i "s|version='.*'|version=\'${VERSION}\'|" /tmp/setup.py \
@@ -45,10 +37,6 @@ COPY tools/compact_plan.py /usr/local/bin/compact_plan
4537
COPY tools/format_tf_credentials.py /usr/local/bin/format_tf_credentials
4638
COPY tools/github_comment_react.py /usr/local/bin/github_comment_react
4739

48-
RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config \
49-
&& echo "IdentityFile /.ssh/id_rsa" >> /etc/ssh/ssh_config \
50-
&& mkdir -p /.ssh
51-
5240
COPY tools/http_credential_actions_helper.py /usr/bin/git-credential-actions
5341
RUN git config --system credential.helper /usr/bin/git-credential-actions \
5442
&& git config --system credential.useHttpPath true \

image/Dockerfile-base

+20-8
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ RUN git clone https://github.com/cloudposse/tfmask.git \
66
&& make \
77
&& make go/build
88

9-
FROM debian:bullseye-slim as base
9+
FROM debian:bullseye-slim AS terraform-github-actions-base
1010

1111
# Terraform environment variables
1212
ENV CHECKPOINT_DISABLE=true
1313
ENV TF_IN_AUTOMATION=true
1414
ENV TF_INPUT=false
1515
ENV TF_PLUGIN_CACHE_DIR=/usr/local/share/terraform/plugin-cache
1616

17-
RUN apt-get update \
18-
&& apt-get install --no-install-recommends -y \
17+
RUN <<EOF
18+
apt-get update
19+
apt-get install --no-install-recommends -y \
1920
git \
2021
ssh \
2122
tar \
@@ -31,12 +32,23 @@ RUN apt-get update \
3132
gpg \
3233
gpg-agent \
3334
dirmngr \
34-
tree \
35-
&& rm -rf /var/lib/apt/lists/*
35+
tree
36+
rm -rf /var/lib/apt/lists/*
3637

37-
RUN mkdir -p $TF_PLUGIN_CACHE_DIR
38+
mkdir -p $TF_PLUGIN_CACHE_DIR
39+
40+
gpg --recv-keys C874011F0AB405110D02105534365D9472D7468F
41+
echo "C874011F0AB405110D02105534365D9472D7468F:6:" | gpg --import-ownertrust
42+
43+
curl https://get.opentofu.org/opentofu.gpg | gpg --import
44+
echo "E3E6E43D84CB852EADB0051D0C0AF313E5FD9F80:6:" | gpg --import-ownertrust
45+
46+
gpg --check-trustdb
47+
48+
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
49+
echo "IdentityFile /.ssh/id_rsa" >> /etc/ssh/ssh_config
50+
mkdir -p /.ssh
51+
EOF
3852

3953
COPY --from=tfmask /go/tfmask/release/tfmask /usr/local/bin/tfmask
4054
ENV TFMASK_RESOURCES_REGEX="(?i)^(random_id|kubernetes_secret|acme_certificate).*$"
41-
42-
ENTRYPOINT ["/usr/local/bin/terraform"]

0 commit comments

Comments
 (0)