From 20d22a8b6941b9b6b02d7eaa7644acbddbd7cddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Thu, 25 Apr 2024 21:32:59 +0800 Subject: [PATCH] test: add dockerfile --- Dockerfile | 26 ++++++++++++++++++++++++++ conf/appsettings.yaml | 4 ++-- conf/conf.go | 14 +++++--------- conf/node.go | 13 ++++++++----- internal/community/instance.go | 2 +- 5 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cf9ce75 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +## build +FROM golang:1.22.1-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 cnode + +## run +FROM alpine:3.19 + +RUN mkdir -p /aa && mkdir -p /aa/log + +WORKDIR /aa + +COPY --from=build-env /go/src/app /aa/ + +ENV PATH $PATH:/aa + +EXPOSE 80 +CMD ["/aa/cnode"] \ No newline at end of file diff --git a/conf/appsettings.yaml b/conf/appsettings.yaml index 1ab3311..27e7db8 100644 --- a/conf/appsettings.yaml +++ b/conf/appsettings.yaml @@ -12,7 +12,7 @@ jwt: node: genesis: true globalName: genesis-01 - externalAddr: 0.0.0.0 + externalAddr: "0.0.0.0" externalPort: 7946 - bindAddr: 0.0.0.0 + bindAddr: "0.0.0.0" bindPort: 7946 \ No newline at end of file diff --git a/conf/conf.go b/conf/conf.go index fe1c409..02d13d9 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -37,17 +37,13 @@ func getConfiguration(filePath *string) *Conf { return mappingEnvToConf(nil) } else { c := Conf{} - err := yaml.Unmarshal(file, &c) - if err != nil { - return mappingEnvToConf(&c) - } - - return &c + yaml.Unmarshal(file, &c) + return mappingEnvToConf(&c) } } -func mappingEnvToConf(fileConf *Conf) *Conf { - envConf := &Conf{ +func mappingEnvToConf(fileConf *Conf) (envConf *Conf) { + envConf = &Conf{ Web: Web{}, Db: DB{}, Jwt: JWT{}, @@ -150,5 +146,5 @@ func mappingEnvToConf(fileConf *Conf) *Conf { } } - return envConf + return } diff --git a/conf/node.go b/conf/node.go index 7e6d86a..0ba0845 100644 --- a/conf/node.go +++ b/conf/node.go @@ -9,11 +9,11 @@ import ( type Node struct { Genesis bool - ExternalAddr string - ExternalPort int - BindAddr string - BindPort int - GlobalName string + ExternalAddr string `yaml:"externalAddr"` + ExternalPort int `yaml:"externalPort"` + BindAddr string `yaml:"bindAddr"` + BindPort int `yaml:"bindPort"` + GlobalName string `yaml:"globalName"` } var node *Node @@ -27,6 +27,9 @@ func GetNode() *Node { node = &Node{ Genesis: j.Genesis, ExternalAddr: j.ExternalAddr, + ExternalPort: j.ExternalPort, + BindAddr: j.BindAddr, + BindPort: j.BindPort, GlobalName: func() string { if j.GlobalName == "" { return fmt.Sprintf("aa:%s", uuid.NewString()) diff --git a/internal/community/instance.go b/internal/community/instance.go index 1a62f79..b8c7a0f 100644 --- a/internal/community/instance.go +++ b/internal/community/instance.go @@ -41,7 +41,7 @@ func BindAccount(hashedAccount string, publicKey *string) error { PublicKey: *publicKey, RpcAddress: rpcAddress, RpcPort: rpcPort, - Version: *&version, + Version: version, }) } }