Switch to multi-stage Dockerbuild
This commit is contained in:
parent
562bac6987
commit
3888c91a6b
@ -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
|
FROM debian:bookworm
|
||||||
|
|
||||||
@ -13,9 +23,7 @@ RUN apt-get update && \
|
|||||||
rm -rf /var/cache/apt/archives && \
|
rm -rf /var/cache/apt/archives && \
|
||||||
rm -rf /var/lib/apt/lists
|
rm -rf /var/lib/apt/lists
|
||||||
|
|
||||||
COPY --from=builder /repo/_build/scn_backend /app/scnserver
|
COPY --from=builder /buildsrc/_build/scn_backend /app/server
|
||||||
|
|
||||||
COPY DOCKER_GIT_INFO /app/DOCKER_GIT_INFO
|
|
||||||
|
|
||||||
RUN mkdir /data
|
RUN mkdir /data
|
||||||
|
|
||||||
@ -23,4 +31,4 @@ WORKDIR /app
|
|||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
CMD ["/app/scnserver"]
|
CMD ["/app/server"]
|
||||||
|
@ -21,12 +21,15 @@ gow:
|
|||||||
which gow || go install github.com/mitranim/gow@latest
|
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
|
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
|
[ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO
|
||||||
git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO
|
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; echo "git" >> DOCKER_GIT_INFO
|
||||||
git rev-parse HEAD >> DOCKER_GIT_INFO
|
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO
|
||||||
git log -1 --format=%cd --date=iso >> DOCKER_GIT_INFO
|
echo -n "HASH=" >> DOCKER_GIT_INFO ; git rev-parse HEAD >> DOCKER_GIT_INFO
|
||||||
git config --get remote.origin.url >> 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 \
|
docker build \
|
||||||
-t "$(DOCKER_NAME):$(HASH)" \
|
-t "$(DOCKER_NAME):$(HASH)" \
|
||||||
-t "$(DOCKER_NAME):$(NAMESPACE)-latest" \
|
-t "$(DOCKER_NAME):$(NAMESPACE)-latest" \
|
||||||
|
@ -49,6 +49,8 @@
|
|||||||
|
|
||||||
- TODO-comments
|
- TODO-comments
|
||||||
|
|
||||||
|
- multistage build
|
||||||
|
|
||||||
#### PERSONAL
|
#### PERSONAL
|
||||||
|
|
||||||
- in my script: use `srvname` for sendername
|
- in my script: use `srvname` for sendername
|
||||||
|
42
scnserver/dgi.go
Normal file
42
scnserver/dgi.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user