Skip to content

Instantly share code, notes, and snippets.

@shvargon
Created October 3, 2023 06:14
Show Gist options
  • Select an option

  • Save shvargon/fc00a1e219a7ff0432b6577c371779f0 to your computer and use it in GitHub Desktop.

Select an option

Save shvargon/fc00a1e219a7ff0432b6577c371779f0 to your computer and use it in GitHub Desktop.
opentofu creating docker image and compiling linux binary
ARG GO_VERSION=1.20
FROM golang:${GO_VERSION}-bookworm as builder
WORKDIR /app
RUN git clone --depth 1 https://github.com/opentofu/opentofu.git .
RUN go mod download && go mod verify
RUN CGO_ENABLED=0 GOOS=linux go build -v -o bin/ ./cmd/tofu
FROM scratch AS export-stage
COPY --from=builder /app/bin/tofu /
FROM ubuntu:jammy as release
WORKDIR /usr/local/bin
COPY --from=builder /app/bin/tofu ./
CMD [ "tofu" ]
BUILD_CMD ?= docker build
DESTDIR ?= ./bin
NAME ?= shvargon/opentofu
all: build binary
.PHONY: build
build:
$(BUILD_CMD) -t "$(NAME)" .
.PHONY: binary
binary:
$(BUILD_CMD) -o "$(DESTDIR)" . --target=export-stage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment