OXYGENHUB
◆ v0.5.0 oxygenflow / images / tofu / Dockerfile
2.9 KiB · last changed tofu image: curl, jq, xz, sfdisk and debugfs for baking VM images 19 days ago source blame history raw
1
# The OxygenFlow OpenTofu image (oxygenflow#56): OpenTofu and the providers
2
# the deploy pipelines use, mirrored inside, so `tofu init` needs no
3
# registry. A job reaches a cloud's API only through allow-listed egress
4
# (#55); formatting and validation need no network at all.
5
6
# Download and check OpenTofu, and mirror the providers, with the tools
7
# only this stage needs.
8
FROM debian:bookworm-slim AS fetch
9
ARG TOFU_VERSION
10
ARG TOFU_SHA256
11
RUN apt-get update \
12
 && apt-get install -y --no-install-recommends ca-certificates curl unzip \
13
 && rm -rf /var/lib/apt/lists/*
14
RUN curl -fsSL -o /tmp/tofu.zip \
15
      "https://github.com/opentofu/opentofu/releases/download/v${TOFU_VERSION}/tofu_${TOFU_VERSION}_linux_amd64.zip" \
16
 && echo "${TOFU_SHA256}  /tmp/tofu.zip" | sha256sum -c - \
17
 && unzip -q /tmp/tofu.zip tofu -d /usr/local/bin \
18
 && rm /tmp/tofu.zip
19
# The exact provider versions of the pipelines' lock files; `tofu
20
# providers mirror` checks each package against the registry's signed
21
# checksums as it downloads it.
22
COPY mirror.tf /tmp/mirror/
23
RUN cd /tmp/mirror && tofu providers mirror -platform=linux_amd64 /opt/tofu/mirror
24
# TFLint and its Google ruleset (HCL linting), each checked against its
25
# release's SHA-256; the ruleset where TFLint looks for plugins, so
26
# linting needs no `tflint --init` and no network.
27
ARG TFLINT_VERSION
28
ARG TFLINT_SHA256
29
ARG TFLINT_GOOGLE_VERSION
30
ARG TFLINT_GOOGLE_SHA256
31
RUN curl -fsSL -o /tmp/tflint.zip \
32
      "https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION}/tflint_linux_amd64.zip" \
33
 && echo "${TFLINT_SHA256}  /tmp/tflint.zip" | sha256sum -c - \
34
 && unzip -q /tmp/tflint.zip tflint -d /usr/local/bin \
35
 && curl -fsSL -o /tmp/google.zip \
36
      "https://github.com/terraform-linters/tflint-ruleset-google/releases/download/v${TFLINT_GOOGLE_VERSION}/tflint-ruleset-google_linux_amd64.zip" \
37
 && echo "${TFLINT_GOOGLE_SHA256}  /tmp/google.zip" | sha256sum -c - \
38
 && d=/opt/tflint/plugins/github.com/terraform-linters/tflint-ruleset-google/${TFLINT_GOOGLE_VERSION} \
39
 && mkdir -p "$d" && unzip -q /tmp/google.zip -d "$d" \
40
 && rm /tmp/tflint.zip /tmp/google.zip
41
42
FROM debian:bookworm-slim
43
# curl, jq, xz, sfdisk and e2fsprogs' debugfs: oxygenhub-gcp's bake job
44
# builds the hub's VM image by writing files into Debian's cloud disk image,
45
# no root needed, and publishes it through Google's APIs (oxygenhub-gcp #7).
46
RUN apt-get update \
47
 && apt-get install -y --no-install-recommends ca-certificates curl jq xz-utils fdisk e2fsprogs \
48
 && rm -rf /var/lib/apt/lists/*
49
COPY --from=fetch /usr/local/bin/tofu /usr/local/bin/tofu
50
COPY --from=fetch /opt/tofu/mirror /opt/tofu/mirror
51
COPY --from=fetch /usr/local/bin/tflint /usr/local/bin/tflint
52
COPY --from=fetch /opt/tflint/plugins /opt/tflint/plugins
53
# Providers come only from the mirror: a job never reaches a registry.
54
COPY cli.tfrc /etc/tofu/cli.tfrc
55
ENV TF_CLI_CONFIG_FILE=/etc/tofu/cli.tfrc \
56
    TFLINT_PLUGIN_DIR=/opt/tflint/plugins