From 28a374f206020142474e5bb27156ced84aebd6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Mon, 4 Mar 2024 21:19:56 +0800 Subject: [PATCH 1/5] WIP: CICD --- .dockerignore | 1 + Dockerfile | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..d581c29d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +conf/appsettings.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2c147638 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +## build +FROM golang:1.22.0-alpine3.19 AS build-env + +RUN apk add build-base + +ADD . /go/src/app + +WORKDIR /go/src/app + +RUN go env -w GO111MODULE=on \ + && go mod tidy \ + && go build -o relay + +## run +FROM alpine:3.19 + +RUN mkdir -p /ep && mkdir -p /ep/log + +WORKDIR /ep + +COPY --from=build-env /go/src/app /ep/ + +ENV PATH $PATH:/aa + +EXPOSE 80 +CMD ["/ep/relay"] From 988716a93d3c699179b1d5b20f7335e88a4b11ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Mon, 4 Mar 2024 22:10:43 +0800 Subject: [PATCH 2/5] read conf from env --- conf/conf.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/conf/conf.go b/conf/conf.go index 46e200e1..73f0198d 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -44,6 +44,15 @@ func mappingEnvToConf(conf *Conf) *Conf { // TODO: read from env // e.g. if dummy := os.Getenv("dummy"); len(dummy) > 0 {conf.Dummy = dummy} + if jwt__security := os.Getenv("jwt__security"); len(jwt__security) > 0 { + conf.Jwt.Security = jwt__security + } + if jwt__realm := os.Getenv("jwt__realm"); len(jwt__realm) > 0 { + conf.Jwt.Security = jwt__realm + } + if jwt__idkey := os.Getenv("jwt__idkey"); len(jwt__idkey) > 0 { + conf.Jwt.Security = jwt__idkey + } return conf } From 72b06b3cbe9eff0dd90d9389c4834ba2fe912916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Mon, 4 Mar 2024 22:13:50 +0800 Subject: [PATCH 3/5] chore: try to fix --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2c147638..05090b31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ ADD . /go/src/app WORKDIR /go/src/app -RUN go env -w GO111MODULE=on \ - && go mod tidy \ - && go build -o relay +RUN go env -w GO111MODULE=on +RUN go mod tidy +RUN go build -o relay ## run FROM alpine:3.19 From 6bc58bdd50b0062190fe8810b0af777f89ff86a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Mon, 4 Mar 2024 22:17:48 +0800 Subject: [PATCH 4/5] chore: fix go build --- Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 05090b31..90903d84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,10 @@ ADD . /go/src/app WORKDIR /go/src/app -RUN go env -w GO111MODULE=on -RUN go mod tidy -RUN go build -o relay +RUN go env -w GO111MODULE=on \ + && go mod tidy \ + && cd ./cmd/server \ + && go build -o ../../relay ## run FROM alpine:3.19 From c486d0ae4e50aa4f4e854a52d79b479fc9cefdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Mon, 4 Mar 2024 22:23:54 +0800 Subject: [PATCH 5/5] bugfix: read env when appsettings.yaml not exists --- conf/conf.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/conf/conf.go b/conf/conf.go index 73f0198d..9e85f880 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -28,7 +28,11 @@ func getConf() *Conf { // getConfiguration func getConfiguration(filePath *string) *Conf { if file, err := os.ReadFile(*filePath); err != nil { - return mappingEnvToConf(nil) + return mappingEnvToConf( + &Conf{ + Jwt: JWT{}, + }, + ) } else { c := Conf{} err := yaml.Unmarshal(file, &c)