This repository has been archived on 2024-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
stagex/go/Dockerfile

104 lines
2.9 KiB
Docker
Raw Normal View History

2023-12-14 16:27:58 +00:00
ARG REGISTRY=local
ARG BUSYBOX_VERSION=latest
2023-12-10 18:05:50 +00:00
FROM ${REGISTRY}/bash:latest as bash
FROM ${REGISTRY}/gcc:latest as gcc
FROM ${REGISTRY}/binutils:latest as binutils
FROM ${REGISTRY}/musl:latest as musl
2023-12-16 23:50:40 +00:00
FROM ${REGISTRY}/busybox:${BUSYBOX_VERSION} as busybox
FROM busybox as base
2023-12-14 16:27:58 +00:00
ENV GOOS=linux
ENV CGO_ENABLED=0
2023-12-16 23:50:40 +00:00
ENV VERSION=1.21.4
ENV SRC_SITE=https://storage.googleapis.com/golang
ENV SRC_HASH=e25c9ab72d811142b7f41ff6da5165fec2d1be5feec3ef2c66bc0bdecb431489
ENV VERSION_BOOTSTRAP_2=1.19.11
ENV SRC_SITE_BOOTSTRAP_2=https://storage.googleapis.com/golang
ENV SRC_HASH_BOOTSTRAP_2=e25c9ab72d811142b7f41ff6da5165fec2d1be5feec3ef2c66bc0bdecb431489
ENV VERSION_BOOTSTRAP_1=1.4-bootstrap-20171003
ENV SRC_SITE_BOOTSTRAP_1=https://dl.google.com/go
ENV SRC_HASH_BOOTSTRAP_1=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
COPY --from=gcc . /
COPY --from=gcc . /
2023-12-14 16:27:58 +00:00
COPY --from=bash . /
COPY --from=musl . /
2023-12-14 16:27:58 +00:00
RUN rm /bin/ar
COPY --from=binutils . /
2023-12-16 23:50:40 +00:00
FROM base as fetch
RUN set -eux; \
wget ${SRC_SITE_BOOTSTRAP_1}/go${VERSION_BOOTSTRAP_1}.tar.gz; \
echo "${SRC_HASH_BOOTSTRAP_1} go${VERSION_BOOTSTRAP_1}.tar.gz" | sha256sum -c; \
wget ${SRC_SITE_BOOTSTRAP_2}/go${VERSION_BOOTSTRAP_2}.src.tar.gz; \
echo "${SRC_HASH_BOOTSTRAP_2} go${VERSION_BOOTSTRAP_2}.src.tar.gz" | sha256sum -c; \
wget ${SRC_SITE}/go${VERSION}.src.tar.gz; \
echo "${SRC_HASH} go${VERSION}.src.tar.gz" | sha256sum -c
FROM fetch as build
ENV GOROOT_FINAL=/home/user/go-bootstrap-1
ENV GOROOT=${GOROOT_FINAL}
ENV DEST=${GOROOT_FINAL}
2023-12-14 16:27:58 +00:00
ENV GOBIN=${GOROOT_FINAL}/bin
2023-12-16 23:50:40 +00:00
RUN set -eux; \
tar -xzf go${VERSION_BOOTSTRAP_1}.tar.gz; \
mv go go-bootstrap-1-src
WORKDIR go-bootstrap-1-src
RUN set -eux; \
cd src; \
bash make.bash; \
cd ..; \
mkdir -p ${DEST}; \
cp -R bin lib pkg src ${DEST}
2023-11-02 12:12:38 +00:00
ENV GO11MODULE=off
2023-12-16 23:50:40 +00:00
ENV GOROOT_BOOTSTRAP=/home/user/go-bootstrap-1
ENV GOROOT_FINAL=/home/user/go-bootstrap-2
ENV GOROOT=${GOROOT_FINAL}
ENV DEST=${GOROOT_FINAL}
2023-12-14 16:27:58 +00:00
ENV GOBIN=${GOROOT_FINAL}/bin
2023-12-16 23:50:40 +00:00
RUN set -eux; \
tar -xzf go${VERSION_BOOTSTRAP_2}.tar.gz; \
mv go go-bootstrap-2-src
WORKDIR go-bootstrap-2-src
RUN set -eux; \
cd src; \
bash make.bash; \
cd ..; \
mkdir -p ${DEST}; \
cp -R bin lib pkg src ${DEST}
2023-11-02 12:12:38 +00:00
ENV GOPROXY=off
ENV GOTOOLCHAIN=local
ENV GOFLAGS=-mod=vendor
ENV GO11MODULE=on
2023-12-16 23:50:40 +00:00
ENV GOROOT_BOOTSTRAP=/home/user/go-bootstrap-2
ENV GOROOT_FINAL="/lib/go"
ENV GOBIN=${GOROOT_FINAL}/bin
2023-12-16 23:50:40 +00:00
ENV GOROOT=/home/user/go-bootstrap-2
RUN set -eux; \
tar -xzf go${VERSION}.src.tar.gz; \
mv go go-src
WORKDIR go-src
RUN set -eux; \
cd src; \
bash make.bash; \
cd ..; \
2023-12-16 23:50:40 +00:00
FROM build as install
USER 0:0
RUN set -eux; \
mkdir -p /rootfs; \
cp -R bin lib pkg src /rootfs; \
find /rootfs -exec touch -hcd "@0" "{}" +
2023-11-02 12:12:38 +00:00
2023-12-14 16:27:58 +00:00
FROM base as test
2023-12-16 23:50:40 +00:00
COPY --from=install /rootfs /
2023-12-14 16:27:58 +00:00
ADD test.go .
RUN set -eux; \
go build test.go; \
./test | grep "Success"
2023-12-12 17:45:39 +00:00
FROM scratch as package
2023-12-16 23:50:40 +00:00
COPY --from=install /rootfs /
2023-11-09 10:12:11 +00:00
USER 100:100
ENTRYPOINT ["/bin/go"]
CMD ["version"]