Switch to multi-stage Dockerbuild

This commit is contained in:
Mike Schwörer 2023-06-06 18:52:03 +02:00
parent 562bac6987
commit 3888c91a6b
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
4 changed files with 68 additions and 13 deletions

View File

@ -1,9 +1,19 @@
FROM golang as builder
WORKDIR /repo
COPY . /repo
RUN make build
FROM golang:1-bullseye AS builder
RUN apt-get update && \
apt-get install -y ca-certificates openssl make git tar coreutils && \
rm -rf /var/lib/apt/lists/*
COPY . /buildsrc
RUN cd /buildsrc && make build
FROM debian:bookworm
@ -13,9 +23,7 @@ RUN apt-get update && \
rm -rf /var/cache/apt/archives && \
rm -rf /var/lib/apt/lists
COPY --from=builder /repo/_build/scn_backend /app/scnserver
COPY DOCKER_GIT_INFO /app/DOCKER_GIT_INFO
COPY --from=builder /buildsrc/_build/scn_backend /app/server
RUN mkdir /data
@ -23,4 +31,4 @@ WORKDIR /app
EXPOSE 80
CMD ["/app/scnserver"]
CMD ["/app/server"]

View File

@ -21,12 +21,15 @@ gow:
which gow || go install github.com/mitranim/gow@latest
gow -e "go,mod,html,css,json,yaml,js" run -tags "timetzdata sqlite_fts5 sqlite_foreign_keys" blackforestbytes.com/simplecloudnotifier/cmd/scnserver
docker:
dgi:
[ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO
git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO
git rev-parse HEAD >> DOCKER_GIT_INFO
git log -1 --format=%cd --date=iso >> DOCKER_GIT_INFO
git config --get remote.origin.url >> DOCKER_GIT_INFO
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; echo "git" >> DOCKER_GIT_INFO
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO
echo -n "HASH=" >> DOCKER_GIT_INFO ; git rev-parse HEAD >> DOCKER_GIT_INFO
echo -n "COMMITTIME=" >> DOCKER_GIT_INFO ; git log -1 --format=%cd --date=iso >> DOCKER_GIT_INFO
echo -n "REMOTE=" >> DOCKER_GIT_INFO ; git config --get remote.origin.url >> DOCKER_GIT_INFO
build-docker: dgi
docker build \
-t "$(DOCKER_NAME):$(HASH)" \
-t "$(DOCKER_NAME):$(NAMESPACE)-latest" \

View File

@ -49,6 +49,8 @@
- TODO-comments
- multistage build
#### PERSONAL
- in my script: use `srvname` for sendername

42
scnserver/dgi.go Normal file
View File

@ -0,0 +1,42 @@
package server
import (
_ "embed"
"fmt"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"strings"
)
//go:embed DOCKER_GIT_INFO
var FileDockerGitInfo string
var CommitHash *string
var VCSType *string
var CommitTime *string
var BranchName *string
var RemoteURL *string
func init() {
for _, v := range strings.Split(FileDockerGitInfo, "\n") {
if v == "" {
continue
} else if strings.HasPrefix(v, "VCSTYPE=") {
VCSType = langext.Ptr(v[len("VCSTYPE="):])
fmt.Printf("Found DGI Config: '%s' := '%s'\n", "VCSType", *VCSType)
} else if strings.HasPrefix(v, "BRANCH=") {
BranchName = langext.Ptr(v[len("BRANCH="):])
fmt.Printf("Found DGI Config: '%s' := '%s'\n", "BranchName", *BranchName)
} else if strings.HasPrefix(v, "HASH=") {
CommitHash = langext.Ptr(v[len("HASH="):])
fmt.Printf("Found DGI Config: '%s' := '%s'\n", "CommitHash", *CommitHash)
} else if strings.HasPrefix(v, "COMMITTIME=") {
CommitTime = langext.Ptr(v[len("COMMITTIME="):])
fmt.Printf("Found DGI Config: '%s' := '%s'\n", "CommitTime", *CommitTime)
} else if strings.HasPrefix(v, "REMOTE=") {
RemoteURL = langext.Ptr(v[len("REMOTE="):])
fmt.Printf("Found DGI Config: '%s' := '%s'\n", "RemoteURL", *RemoteURL)
} else {
fmt.Printf("[ERROR] Failed to parse DGI Config '%s'\n", v)
}
}
}