From 125f7ac6e026bd6750817c46da51cb479d95d121 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Thu, 2 Nov 2023 05:12:38 -0700 Subject: [PATCH] wip go example --- packages/golang/Dockerfile | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 packages/golang/Dockerfile diff --git a/packages/golang/Dockerfile b/packages/golang/Dockerfile new file mode 100644 index 0000000..84bfe0e --- /dev/null +++ b/packages/golang/Dockerfile @@ -0,0 +1,64 @@ +ARG GO_VERSION=1.21.3 +ARG GO_HASH=186f2b6f8c8b704e696821b09ab2041a5c1ee13dcbc3156a13adcf75931ee488 +ARG GO_STAGE2_VERSION=1.19.11 +ARG GO_STAGE2_HASH=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52 +ARG GO_SOURCE_SITE = https://dl.google.com/go +ARG GO_BOOTSTRAP_SOURCE = go${GO_BOOTSTRAP_VERSION} +ARG BUSYBOX_IMAGE=ocirep:busybox +ARG GCC_IMAGE=ocirep:gcc + +# build go bootstrap stage 1 with gcc +FROM ${BUSYBOX_IMAGE} as stage1 +ENV GOOS=linux +ENV GOROOT_FINAL="lib/go-${GO_STAGE1_VERSION}" +ENV GOROOT="${GOROOT_FINAL}" +ENV GOBIN="${GOROOT_FINAL}/bin" +ENV CGO_ENABLED=0 +COPY --from=${GCC_IMAGE} / / +RUN wget ${GO_SOURCE_SITE}/${GO_STAGE1_VERSION}.tar.gz +RUN echo "${GO_STAGE1_HASH} ${GO_STAGE1_VERSION}.tar.gz" | sha256sum -c +RUN tar -xvzf ${GO_STAGE1_VERSION}.tar.gz +RUN env -C go ./make.bash +RUN \ + mkdir -p lib/go-${GO_STAGE1_VERSION} \ + && cp bin lib pkg src lib/go-${GO_STAGE1_VERSION} + +# build go bootstrap stage 2 with go bootstrap stage 1 +FROM ${BUSYBOX_IMAGE} as stage2 +ENV GOOS=linux +ENV GOROOT_FINAL="lib/go-${GO_STAGE2_VERSION}" +ENV GOROOT="${GOROOT_FINAL}" +ENV GOBIN="${GOROOT_FINAL}/bin" +ENV GO11MODULE=off +ENV CGO_ENABLED=0 +RUN wget ${GO_SOURCE_SITE}/${GO_STAGE2_VERSION}.tar.gz +RUN echo "${GO_STAGE2_HASH} ${GO_STAGE2_VERSION}.tar.gz" | sha256sum -c +COPY --from=stage1 lib / +RUN tar -xvzf ${GO_STAGE2_VERSION}.tar.gz +RUN env -C go ./make.bash +RUN \ + mkdir -p lib/go-${GO_STAGE1_VERSION} \ + && cp bin lib pkg src lib/go-${GO_STAGE1_VERSION} + +# build target go with go bootstrap stage 2 +FROM ${BUSYBOX_IMAGE} as stage3 +ENV GOOS=linux +ENV GOPROXY=off +ENV GOTOOLCHAIN=local +ENV GOFLAGS=-mod=vendor +ENV GOROOT_FINAL="lib/go" +ENV GOROOT="${GOROOT_FINAL}" +ENV GOBIN="${GOROOT_FINAL}/bin" +ENV GO11MODULE=on +ENV CGO_ENABLED=0 +RUN wget ${GO_SOURCE_SITE}/${GO_VERSION}.tar.gz +RUN echo "${GO_HASH} ${GO_VERSION}.tar.gz" | sha256sum -c +COPY --from=stage2 lib / +RUN tar -xvzf ${GO_VERSION}.tar.gz +RUN env -C go ./make.bash +RUN \ + mkdir -p lib/go \ + && cp bin lib pkg src lib/go + +FROM scratch +COPY --from=stage3 lib /