2 Commits

Author SHA1 Message Date
91eb83d6e1 bootstrap: attemps fetching for 1 minute before giving up 2024-11-06 00:42:51 +01:00
5924705b24 shrink exec 2024-11-04 22:06:48 +01:00
2 changed files with 17 additions and 5 deletions

View File

@ -1,5 +1,5 @@
from golang:1.23.2-alpine3.20 as build from golang:1.23.2-alpine3.20 as build
run apk add --no-cache gcc musl-dev linux-headers eudev-dev run apk add --no-cache gcc musl-dev linux-headers eudev-dev upx
workdir /src workdir /src
@ -10,7 +10,9 @@ run \
--mount=type=cache,id=gomod,target=/go/pkg/mod \ --mount=type=cache,id=gomod,target=/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \ --mount=type=cache,id=gobuild,target=/root/.cache/go-build \
go test ./... \ go test ./... \
&& go build -o /go/bin/init -trimpath . && go build -ldflags "-s -w" -o /go/bin/init -trimpath .
run upx /go/bin/init
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
from alpine:3.20.3 as initrd from alpine:3.20.3 as initrd
@ -21,7 +23,7 @@ workdir /layer
run . /etc/os-release \ run . /etc/os-release \
&& wget -O- https://dl-cdn.alpinelinux.org/alpine/v${VERSION_ID%.*}/releases/x86_64/alpine-minirootfs-${VERSION_ID}-x86_64.tar.gz |tar zxv && wget -O- https://dl-cdn.alpinelinux.org/alpine/v${VERSION_ID%.*}/releases/x86_64/alpine-minirootfs-${VERSION_ID}-x86_64.tar.gz |tar zxv
run apk add --no-cache -p . musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk run apk add --no-cache -p . musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs lsblk
run rm -rf usr/share/apk var/cache/apk run rm -rf usr/share/apk var/cache/apk
copy --from=build /go/bin/init . copy --from=build /go/bin/init .

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -45,9 +46,18 @@ func bootstrap(cfg *config.Config) {
bootstrapFile := filepath.Join(baseDir, "bootstrap.tar") bootstrapFile := filepath.Join(baseDir, "bootstrap.tar")
err = func() (err error) { err = func() (err error) {
resp, err := http.Get(seed) var resp *http.Response
start := time.Now()
for time.Since(start) <= time.Minute {
resp, err = http.Get(seed)
if err == nil {
break
}
time.Sleep(time.Second)
}
if err != nil { if err != nil {
return return fmt.Errorf("failed to fetch bootstrap")
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {