From 516809cd02f67d012af47aded3a7761f56d208e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 20 Nov 2022 03:41:38 +0100 Subject: [PATCH] Dockerfile, CONF_NS and fix sqlite3 under alpine --- server/Dockerfile | 15 +++++++++++++++ server/Makefile | 8 ++++---- server/config.go | 19 +++++++++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 server/Dockerfile diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..5a68e5f --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:latest + +RUN apk update +RUN apk add --no-cache libc6-compat tzdata ca-certificates sqlite + +COPY _build/scn_backend /app/scnserver +COPY DOCKER_GIT_INFO /app/DOCKER_GIT_INFO + +RUN mkdir /data + +WORKDIR /app + +EXPOSE 80 + +CMD ["/app/scnserver"] diff --git a/server/Makefile b/server/Makefile index 5effd70..f94da55 100644 --- a/server/Makefile +++ b/server/Makefile @@ -7,13 +7,13 @@ HASH=$(shell git rev-parse HEAD) build: rm -f ./_build/scn_backend - go build -v -o _build/scn_backend ./cmd/scnserver + CGO_ENABLED=1 go build -v -ldflags "-linkmode external -extldflags -static" -o _build/scn_backend ./cmd/scnserver run: build mkdir -p .run-data _build/scn_backend -build-docker: +docker: [ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO git rev-parse HEAD >> DOCKER_GIT_INFO @@ -37,9 +37,9 @@ run-docker-local: mkdir -p .run-data docker run --rm \ --init \ - --env "CONF_NS=local" \ + --env "CONF_NS=local-docker" \ --volume "$(shell pwd)/.run-data/docker-local:/data" \ - --network host \ + --publish "8080:80" \ $(DOCKER_NAME):latest inspect-docker: diff --git a/server/config.go b/server/config.go index 6a2ce78..8107e23 100644 --- a/server/config.go +++ b/server/config.go @@ -18,8 +18,8 @@ type Config struct { var Conf Config -var configLoc = Config{ - Namespace: "local", +var configLocHost = Config{ + Namespace: "local-host", GinDebug: true, ServerIP: "0.0.0.0", ServerPort: "8080", @@ -28,6 +28,16 @@ var configLoc = Config{ ReturnRawErrors: true, } +var configLocDocker = Config{ + Namespace: "local-docker", + GinDebug: true, + ServerIP: "0.0.0.0", + ServerPort: "80", + DBFile: "/data/scn_docker.sqlite3", + RequestTimeout: 16 * time.Second, + ReturnRawErrors: true, +} + var configDev = Config{ Namespace: "develop", GinDebug: true, @@ -59,7 +69,8 @@ var configProd = Config{ } var allConfig = []Config{ - configLoc, + configLocHost, + configLocDocker, configDev, configStag, configProd, @@ -67,7 +78,7 @@ var allConfig = []Config{ func getConfig(ns string) (Config, bool) { if ns == "" { - return configLoc, true + return configLocHost, true } for _, c := range allConfig { if c.Namespace == ns {