better build

This commit is contained in:
Mikaël Cluseau 2023-11-27 14:40:15 +01:00
parent 86d85f014c
commit 3f2cd997a0
5 changed files with 32 additions and 12 deletions

View File

@ -1 +1,3 @@
Dockerfile 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

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