From 73afbef4158066ee2917c841a6b20e0c2c5d4a80 Mon Sep 17 00:00:00 2001 From: Fabrizio Furnari Date: Wed, 9 Dec 2020 00:31:03 +0100 Subject: [PATCH] added build script for container (buildah) --- Makefile | 3 +-- build.sh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 build.sh diff --git a/Makefile b/Makefile index 1830b46..9d486c3 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ -#GOFLAGS="" LDFLAGS=-ldflags "-s -w" BINARY=metrorama .DEFAULT_GOAL: $(BINARY) $(BINARY): clean - go build ${GOFLAGS} ${LDFLAGS} -o ${BINARY} + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build ${GOFLAGS} ${LDFLAGS} -o ${BINARY} install: go install ${GOFLAGS} ${LDFLAGS} -o ${BINARY} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..53e2197 --- /dev/null +++ b/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Remember to run buildah unshare before launching this +# Build container +echo "Start creating first stage " +buildctrl=$(buildah from golang:1.15.2) +buildmnt=$(buildah mount $buildctrl) + +buildah copy $buildctrl *.go . +buildah copy $buildctrl Makefile . +buildah run $buildctrl make deps +buildah run $buildctrl make + +# Runtime container +echo "Start creating second stage" +buildctrl2=$(buildah from alpine:latest) +buildmnt2=$(buildah mount $builctrl2) + +buildah copy $buildctrl2 $buildmnt/go/metrorama +buildah config --cmd ./metrorama $buildctrl2 +buildah config --port 8080 $buildctrl2 +buildah unmount $buildctrl +buildah unmount $buildctrl2 +buildah commit $buildctrl2 metrorama:latest +buildah rm $buildctrl $buildctrl2