From 021ba06a8d65c02866442c6c2d4e3c9b6c62886f Mon Sep 17 00:00:00 2001 From: TommyLike Date: Wed, 9 Sep 2020 18:30:27 +0800 Subject: [PATCH 1/4] Add dockerfile and ignore --- .gitignore | 1 + Dockerfile | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore index 6c15f24..57cdcaa 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ app-cla-server commentsRouter_controllers.go lastupdate.tmp conf/* +.idea diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf1c7fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:latest as BUILDER + +MAINTAINER TommyLike + +# build binary +COPY . /go/src/github.com/opensourceways/app-cla-server +RUN cd /go/src/github.com/opensourceways/app-cla-server && CGO_ENABLED=1 go build -v -o ./cla-server main.go + +# copy binary and config +FROM golang:latest +RUN apt-get update && apt-get install -y python-pip && mkdir -p /opt/app/ +COPY ./conf /opt/app/ +COPY --from=BUILDER /go/src/github.com/opensourceways/app-cla-server/cla-server /opt/app + +WORKDIR /opt/app/cla-server +ENTRYPOINT ["/opt/app/cla-server"] From fbf5079c8b4d86bb538246f2bf6b9121692e9861 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Wed, 9 Sep 2020 18:51:56 +0800 Subject: [PATCH 2/4] Add deploy config file --- Dockerfile | 9 ++++++--- deploy/app.conf | 29 +++++++++++++++++++++++++++++ go.mod | 16 ++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 deploy/app.conf create mode 100644 go.mod diff --git a/Dockerfile b/Dockerfile index bf1c7fd..23cd531 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,11 +6,14 @@ MAINTAINER TommyLike COPY . /go/src/github.com/opensourceways/app-cla-server RUN cd /go/src/github.com/opensourceways/app-cla-server && CGO_ENABLED=1 go build -v -o ./cla-server main.go -# copy binary and config +# copy binary config and utils FROM golang:latest RUN apt-get update && apt-get install -y python-pip && mkdir -p /opt/app/ -COPY ./conf /opt/app/ +COPY ./conf /opt/app/conf +COPY ./util /opt/app/util +# overwrite config yaml +COPY ./deploy/app.conf /opt/app/conf COPY --from=BUILDER /go/src/github.com/opensourceways/app-cla-server/cla-server /opt/app -WORKDIR /opt/app/cla-server +WORKDIR /opt/app/ ENTRYPOINT ["/opt/app/cla-server"] diff --git a/deploy/app.conf b/deploy/app.conf new file mode 100644 index 0000000..5682737 --- /dev/null +++ b/deploy/app.conf @@ -0,0 +1,29 @@ +appname = app-cla-server +httpport = "${HTTP_PORT||8080}" +runmode = "${RUN_MODE||prod}" +autorender = false +copyrequestbody = true +EnableDocs = true + +python_bin = /usr/bin/python + +mongodb_conn = "$MONGODB_CONNECTION" +mongodb_db = cla + +verification_vode_expiry = 300 +api_token_expiry = 300 +api_token_key = "$API_TOKEN_KEY" + +pdf_org_signature_dir = ./conf/pdfs/org_signature_pdf +pdf_out_dir = ./conf/pdfs/output + +code_platforms = ./conf/platforms/code_platforms.yaml +email_platforms = ./conf/platforms/email.yaml + +[blank_signature] +language = english +pdf = ./conf/blank_signature/english_blank_signature.pdf + +[pdf_template_corporation] +welcome = ./conf/pdf_template_corporation/welcome.tmpl +declaration = ./conf/pdf_template_corporation/declaration.tmpl diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1554c3a --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module github.com/opensourceways/app-cla-server + +go 1.13 + +require ( + gitee.com/openeuler/go-gitee v0.0.0-20200506042249-a91b6e6ed1b1 + github.com/antihax/optional v1.0.0 + github.com/astaxie/beego v1.12.2 + github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/huaweicloud/golangsdk v0.0.0-20200907093635-5934c79d40de + github.com/jung-kurt/gofpdf v1.16.2 + go.mongodb.org/mongo-driver v1.4.1 + golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 + google.golang.org/api v0.31.0 + sigs.k8s.io/yaml v1.2.0 +) \ No newline at end of file From 845dcb8811bb6b3d6f16b699051923b8be964bb3 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Wed, 9 Sep 2020 18:58:32 +0800 Subject: [PATCH 3/4] Fix incorrect of log level --- Dockerfile | 2 +- main.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 23cd531..673d54c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN cd /go/src/github.com/opensourceways/app-cla-server && CGO_ENABLED=1 go buil FROM golang:latest RUN apt-get update && apt-get install -y python-pip && mkdir -p /opt/app/ COPY ./conf /opt/app/conf -COPY ./util /opt/app/util +COPY ./util/merge-signature.py /opt/app/util # overwrite config yaml COPY ./deploy/app.conf /opt/app/conf COPY --from=BUILDER /go/src/github.com/opensourceways/app-cla-server/cla-server /opt/app diff --git a/main.go b/main.go index 507fb7d..0b990b2 100644 --- a/main.go +++ b/main.go @@ -22,26 +22,27 @@ func main() { beego.AppConfig.String("mongodb_conn"), beego.AppConfig.String("mongodb_db")) if err != nil { + beego.Error(err) return } dbmodels.RegisterDB(c) path := beego.AppConfig.String("email_platforms") if err = email.RegisterPlatform(path); err != nil { - beego.Info(err) + beego.Error(err) return } path = beego.AppConfig.String("code_platforms") if err := platformAuth.RegisterPlatform(path); err != nil { - beego.Info(err) + beego.Error(err) return } language := beego.AppConfig.String("blank_signature::language") path = beego.AppConfig.String("blank_signature::pdf") if err := pdf.UploadBlankSignature(language, path); err != nil { - beego.Info(err) + beego.Error(err) return } @@ -52,7 +53,7 @@ func main() { beego.AppConfig.String("pdf_template_corporation::welcome"), beego.AppConfig.String("pdf_template_corporation::declaration"), ); err != nil { - beego.Info(err) + beego.Error(err) return } From bcbec9755670ebd456afd0b75bd1a2f6522ce101 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Wed, 9 Sep 2020 19:41:20 +0800 Subject: [PATCH 4/4] Return none zero code when failed to start --- deploy/app.conf | 2 +- main.go | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/deploy/app.conf b/deploy/app.conf index 5682737..81c0378 100644 --- a/deploy/app.conf +++ b/deploy/app.conf @@ -3,7 +3,7 @@ httpport = "${HTTP_PORT||8080}" runmode = "${RUN_MODE||prod}" autorender = false copyrequestbody = true -EnableDocs = true +EnableDocs = false python_bin = /usr/bin/python diff --git a/main.go b/main.go index 0b990b2..60aa1e6 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "os" + "github.com/astaxie/beego" platformAuth "github.com/opensourceways/app-cla-server/code-platform-auth" @@ -23,27 +25,27 @@ func main() { beego.AppConfig.String("mongodb_db")) if err != nil { beego.Error(err) - return + os.Exit(1) } dbmodels.RegisterDB(c) path := beego.AppConfig.String("email_platforms") if err = email.RegisterPlatform(path); err != nil { beego.Error(err) - return + os.Exit(1) } path = beego.AppConfig.String("code_platforms") if err := platformAuth.RegisterPlatform(path); err != nil { beego.Error(err) - return + os.Exit(1) } language := beego.AppConfig.String("blank_signature::language") path = beego.AppConfig.String("blank_signature::pdf") if err := pdf.UploadBlankSignature(language, path); err != nil { beego.Error(err) - return + os.Exit(1) } if err := pdf.InitPDFGenerator( @@ -54,7 +56,7 @@ func main() { beego.AppConfig.String("pdf_template_corporation::declaration"), ); err != nil { beego.Error(err) - return + os.Exit(1) } worker.InitEmailWorker(pdf.GetPDFGenerator())