Compare commits

...

2 Commits

Author SHA1 Message Date
Mikaël Cluseau
1555419549 files: default mode 2023-11-27 16:08:09 +01:00
Mikaël Cluseau
3f2cd997a0 better build 2023-11-27 14:40:15 +01:00
6 changed files with 38 additions and 13 deletions

View File

@ -1 +1,3 @@
Dockerfile
tmp/**/*
dist/*

25
Dockerfile Normal file
View File

@ -0,0 +1,25 @@
from golang:1.21.4-alpine3.18 as build
workdir /src
copy go.mod go.sum .
run go mod download
copy . .
run go test ./...
run go build -o /go/bin/init -trimpath .
# ------------------------------------------------------------------------
from alpine:3.18.4
workdir /layer
run wget -O- https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-minirootfs-3.18.4-x86_64.tar.gz |tar zxv
run apk add --no-cache -p . musl lvm2 lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk
run rm -rf usr/share/apk var/cache/apk
copy --from=build /go/bin/init .
# check viability
run chroot /layer /init hello
entrypoint ["sh","-c","find |cpio -H newc -o |base64"]

View File

@ -1,12 +0,0 @@
# ------------------------------------------------------------------------
from alpine:3.15
add alpine-minirootfs-3.15.0-x86_64.tar.gz /layer/
workdir /layer
run apk update
run apk add -p . musl lvm2 lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs
run rm -rf usr/share/apk var/cache/apk
entrypoint ["sh","-c","find |cpio -H newc -o |base64"]

View File

@ -147,7 +147,12 @@ func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) {
log.Printf("failed to create dir %s: %v", filepath.Dir(fileDef.Path), err)
}
err = os.WriteFile(filePath, []byte(fileDef.Content), fileDef.Mode)
mode := fileDef.Mode
if mode == 0 {
mode = 0644
}
err = os.WriteFile(filePath, []byte(fileDef.Content), mode)
if err != nil {
fatalf("failed to write %s: %v", fileDef.Path, err)
}

View File

@ -50,6 +50,11 @@ func main() {
}
func runInit() {
if len(os.Args) > 1 && os.Args[1] == "hello" {
fmt.Println("hello world!")
os.Exit(0)
}
runtime.LockOSThread()
if pid := os.Getpid(); pid != 1 {