stagex/packages/go/Containerfile

126 lines
3.4 KiB
Text
Raw Normal View History

2024-02-09 07:30:28 +00:00
FROM scratch as base
ENV VERSION=1.22.1
ENV SRC_HASH=79c9b91d7f109515a25fc3ecdaad125d67e6bdb54f6d4d98580f46799caea321
2024-02-09 07:30:28 +00:00
ENV SRC_FILE=go${VERSION}.src.tar.gz
ENV SRC_SITE=https://storage.googleapis.com/golang/${SRC_FILE}
ENV VERSION_BOOTSTRAP_3=1.20.6
ENV SRC_HASH_BOOTSTRAP_3=62ee5bc6fb55b8bae8f705e0cb8df86d6453626b4ecf93279e2867092e0b7f70
ENV SRC_FILE_BOOTSTRAP_3=go${VERSION_BOOTSTRAP_3}.src.tar.gz
ENV SRC_SITE_BOOTSTRAP_3=https://storage.googleapis.com/golang/${SRC_FILE_BOOTSTRAP_3}
2023-12-16 23:50:40 +00:00
ENV VERSION_BOOTSTRAP_2=1.19.11
ENV SRC_HASH_BOOTSTRAP_2=e25c9ab72d811142b7f41ff6da5165fec2d1be5feec3ef2c66bc0bdecb431489
2024-02-09 07:30:28 +00:00
ENV SRC_FILE_BOOTSTRAP_2=go${VERSION_BOOTSTRAP_2}.src.tar.gz
ENV SRC_SITE_BOOTSTRAP_2=https://storage.googleapis.com/golang/${SRC_FILE_BOOTSTRAP_2}
2023-12-16 23:50:40 +00:00
ENV VERSION_BOOTSTRAP_1=1.4-bootstrap-20171003
ENV SRC_HASH_BOOTSTRAP_1=f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
2024-02-09 07:30:28 +00:00
ENV SRC_FILE_BOOTSTRAP_1=go${VERSION_BOOTSTRAP_1}.tar.gz
ENV SRC_SITE_BOOTSTRAP_1=https://dl.google.com/go/${SRC_FILE_BOOTSTRAP_1}
2023-12-14 16:27:58 +00:00
2023-12-16 23:50:40 +00:00
FROM base as fetch
2024-02-11 00:02:15 +00:00
ADD --checksum=sha256:${SRC_HASH_BOOTSTRAP_1} ${SRC_SITE_BOOTSTRAP_1} .
ADD --checksum=sha256:${SRC_HASH_BOOTSTRAP_2} ${SRC_SITE_BOOTSTRAP_2} .
ADD --checksum=sha256:${SRC_HASH_BOOTSTRAP_3} ${SRC_SITE_BOOTSTRAP_3} .
2024-02-11 00:02:15 +00:00
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
2023-12-16 23:50:40 +00:00
FROM fetch as build
COPY --from=stagex/busybox . /
COPY --from=stagex/gcc . /
COPY --from=stagex/bash . /
COPY --from=stagex/musl . /
COPY --from=stagex/binutils . /
2024-02-09 07:30:28 +00:00
RUN <<-EOF
set -eux
tar -xzf go${VERSION_BOOTSTRAP_1}.tar.gz
mv go go-bootstrap-1-src
tar -xzf go${VERSION_BOOTSTRAP_2}.src.tar.gz
mv go go-bootstrap-2-src
tar -xzf go${VERSION_BOOTSTRAP_3}.src.tar.gz
mv go go-bootstrap-3-src
2024-02-09 07:30:28 +00:00
tar -xzf go${VERSION}.src.tar.gz; \
mv go go-src
EOF
WORKDIR go-bootstrap-1-src
ENV GOOS=linux
ENV CGO_ENABLED=0
ENV GOROOT_FINAL=/go-bootstrap-1
ENV GOROOT=${GOROOT_FINAL}
ENV DEST=${GOROOT_FINAL}
2023-12-14 16:27:58 +00:00
ENV GOBIN=${GOROOT_FINAL}/bin
2024-02-09 07:30:28 +00:00
RUN --network=none <<-EOF
set -eux
cd src
bash make.bash
cd ..
mkdir -p ${DEST}
cp -R bin lib pkg src ${DEST}
EOF
WORKDIR ../go-bootstrap-2-src
2023-11-02 12:12:38 +00:00
ENV GO11MODULE=off
2024-02-09 07:30:28 +00:00
ENV GOROOT_BOOTSTRAP=/go-bootstrap-1
ENV GOROOT_FINAL=/go-bootstrap-2
ENV GOROOT=${GOROOT_FINAL}
ENV DEST=${GOROOT_FINAL}
2023-12-14 16:27:58 +00:00
ENV GOBIN=${GOROOT_FINAL}/bin
2024-02-09 07:30:28 +00:00
RUN --network=none <<-EOF
set -eux
cd src
bash make.bash
cd ..
mkdir -p ${DEST}
cp -R bin lib pkg src ${DEST}
EOF
WORKDIR ../go-bootstrap-3-src
ENV GO11MODULE=off
ENV GOROOT_BOOTSTRAP=/go-bootstrap-2
ENV GOROOT_FINAL=/go-bootstrap-3
ENV GOROOT=${GOROOT_FINAL}
ENV DEST=${GOROOT_FINAL}
ENV GOBIN=${GOROOT_FINAL}/bin
RUN --network=none <<-EOF
set -eux
cd src
bash make.bash
cd ..
mkdir -p ${DEST}
cp -R bin lib pkg src ${DEST}
EOF
2024-02-09 07:30:28 +00:00
WORKDIR ../go-src
2023-11-02 12:12:38 +00:00
ENV GOPROXY=off
ENV GOTOOLCHAIN=local
ENV GOFLAGS=-mod=vendor
ENV GO11MODULE=on
ENV GOROOT_BOOTSTRAP=/go-bootstrap-3
ENV GOROOT_FINAL="/lib/go"
ENV GOBIN=${GOROOT_FINAL}/bin
ENV GOROOT=/go-bootstrap-3
2024-02-09 07:30:28 +00:00
RUN --network=none <<-EOF
set -eux
cd src
bash make.bash
EOF
2023-12-16 23:50:40 +00:00
FROM build as install
2024-02-09 07:30:28 +00:00
RUN <<-EOF
set -eux
mkdir -p /rootfs/usr
cp -R pkg src /rootfs
cp -R bin lib /rootfs/usr
2024-02-09 07:30:28 +00:00
EOF
RUN 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
COPY --from=install /rootfs/. /
2024-02-09 07:30:28 +00:00
COPY <<-EOF test.go
package main
import "fmt"
func main() { fmt.Println("Success") }
EOF
RUN <<-EOF
set -eux
go build test.go
./test | grep "Success"
EOF
2023-12-14 16:27:58 +00:00
FROM stagex/filesystem as package
COPY --from=install /rootfs/. /