From 3caf0f16f603336292f6e17a4eb4e67ba4347e3c Mon Sep 17 00:00:00 2001 From: Sheogorath <sheogorath@shivering-isles.com> Date: Thu, 12 Oct 2023 02:22:06 +0200 Subject: [PATCH] ci(opentf): Optimise builds with earthly --- images/.utils/Earthfile | 14 +++++++++++++- images/opentf/Earthfile | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/images/.utils/Earthfile b/images/.utils/Earthfile index d8de15e28..df6582d3d 100644 --- a/images/.utils/Earthfile +++ b/images/.utils/Earthfile @@ -5,4 +5,16 @@ SCAN: FROM ../mirror+trivy WITH DOCKER --load image=+container RUN trivy image image:latest - END \ No newline at end of file + END + +LABEL: + COMMAND + ARG image + ARG EARTHLY_GIT_CO_AUTHORS + ARG EARTHLY_GIT_BRANCH + LABEL org.opencontainers.image.title="${image}" + LABEL org.opencontainers.image.source="https://git.shivering-isles.com/shivering-isles/infrastructure-gitops/-/tree/main/images/${image}" + LABEL org.opencontainers.image.url="https://git.shivering-isles.com/shivering-isles/infrastructure-gitops/-/tree/main/images/${image}" + LABEL org.opencontainers.image.version="${EARTHLY_GIT_BRANCH}" + LABEL org.opencontainers.image.description="Container for ${image} by ${author}" + LABEL org.opencontainers.image.authors="${EARTHLY_GIT_CO_AUTHORS}" \ No newline at end of file diff --git a/images/opentf/Earthfile b/images/opentf/Earthfile index 2280bcaa1..08de6736c 100644 --- a/images/opentf/Earthfile +++ b/images/opentf/Earthfile @@ -1,19 +1,31 @@ VERSION 0.7 +src: + FROM ../mirror+golang + ARG branch=main + WORKDIR /go-workdir + GIT CLONE --branch=${branch} https://github.com/opentofu/opentofu.git ./ + SAVE ARTIFACT ./ ./src + build: FROM ../mirror+golang WORKDIR /go-workdir - GIT CLONE --branch=v1.6.0-alpha2 https://github.com/opentofu/opentofu.git ./ + COPY +src/src/go.mod ./ + COPY +src/src/go.sum ./ ENV CGO_ENABLED=0 + RUN go mod download && go mod verify + COPY +src/src/ ./ RUN go build -ldflags "-s -w" -mod=readonly -trimpath ./cmd/tofu SAVE ARTIFACT ./tofu ./tofu container-internal: FROM ../mirror+distroless-static + ARG branch=main COPY +build/tofu /usr/local/bin/tofu COPY +build/tofu /usr/local/bin/opentofu COPY +build/tofu /usr/local/bin/opentf ENTRYPOINT ["/usr/local/bin/tofu"] + DO ../.utils/+LABEL --image=opentf --version=${branch} container: FROM ../mirror+golang @@ -22,10 +34,10 @@ container: ARG tag=$(awk -F'=' '$1 == "release" {print $2}' .release) ARG latest=false IF [ $latest = "true" ] - FROM +container-internal + FROM +container-internal --branch=v${tag} SAVE IMAGE --push ${registry}:latest ELSE - FROM +container-internal + FROM +container-internal --branch=v${tag} LABEL "quay.expires-after"="12w" END SAVE IMAGE --push ${registry}:${tag} -- GitLab