From 9bf121bdba9e3e77f33068744ae220fe35cbd855 Mon Sep 17 00:00:00 2001 From: Manuel Kieweg <manuel.kieweg@h-da.de> Date: Mon, 29 Mar 2021 14:56:36 +0100 Subject: [PATCH] merge --- build/dockerfiles/production/Dockerfile | 18 ++++++++++++++++++ build/dockerfiles/staging/Dockerfile | 18 ++++++++++++++++++ nucleus/controller.go | 3 ++- nucleus/http.go | 2 +- nucleus/http_test.go | 8 ++++---- .../{inizalize_test.go => initialise_test.go} | 6 ++++++ 6 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 build/dockerfiles/production/Dockerfile create mode 100644 build/dockerfiles/staging/Dockerfile rename nucleus/{inizalize_test.go => initialise_test.go} (98%) diff --git a/build/dockerfiles/production/Dockerfile b/build/dockerfiles/production/Dockerfile new file mode 100644 index 000000000..4e90a5a77 --- /dev/null +++ b/build/dockerfiles/production/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.15-alpine AS builder +ARG GITLAB_USER +ARG GITLAB_TOKEN +WORKDIR /src/gosdn +COPY . . +RUN apk add git +RUN git config --global url."https://$GITLAB_USER:$GITLAB_TOKEN@code.fbi.h-da.de".insteadOf "https://code.fbi.h-da.de" +RUN go mod download +RUN CGO_ENABLED=0 GOOS=linux go build ./cmd/gosdn + +FROM alpine:latest +EXPOSE 8443 +EXPOSE 55055 +COPY --from=builder /src/gosdn/gosdn . +COPY --from=builder /src/gosdn/configs ./configs + +ENTRYPOINT [ "./gosdn" ] +CMD [""] diff --git a/build/dockerfiles/staging/Dockerfile b/build/dockerfiles/staging/Dockerfile new file mode 100644 index 000000000..bb1503026 --- /dev/null +++ b/build/dockerfiles/staging/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.15-alpine AS builder +ARG GITLAB_USER +ARG GITLAB_TOKEN +WORKDIR /src/gosdn +COPY . . +RUN apk add git +RUN git config --global url."https://$GITLAB_USER:$GITLAB_TOKEN@code.fbi.h-da.de".insteadOf "https://code.fbi.h-da.de" +RUN go mod download +RUN CGO_ENABLED=0 GOOS=linux go build -race ./cmd/gosdn + +FROM alpine:latest +EXPOSE 8443 +EXPOSE 55055 +COPY --from=builder /src/gosdn/gosdn . +COPY --from=builder /src/gosdn/configs ./configs + +ENTRYPOINT [ "./gosdn" ] +CMD [""] diff --git a/nucleus/controller.go b/nucleus/controller.go index fc832735f..a633e4168 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -47,7 +47,6 @@ func initialize() error { } // TODO: Start grpc listener here - return httpAPI() } @@ -76,9 +75,11 @@ func createPrincipalNetworkDomain(sbi SouthboundInterface) error { // Run calls initialize to start the controller func Run(ctx context.Context) error { var initError error + coreLock.Lock() coreOnce.Do(func() { initError = initialize() }) + coreLock.Unlock() if initError != nil { log.WithFields(log.Fields{}).Error(initError) return initError diff --git a/nucleus/http.go b/nucleus/http.go index 1869f27e7..c4419fb79 100644 --- a/nucleus/http.go +++ b/nucleus/http.go @@ -31,7 +31,7 @@ func registerHttpHandler() { } // deprecated -func httpAPI() (err error) { +func httpAPI() error { registerHttpHandler() c.httpServer = &http.Server{Addr: ":8080"} go func() { diff --git a/nucleus/http_test.go b/nucleus/http_test.go index 35ce78254..00195b43e 100644 --- a/nucleus/http_test.go +++ b/nucleus/http_test.go @@ -36,6 +36,10 @@ func testSetupHTTP() { if err := c.pndc.add(pnd); err != nil { log.Fatal(err) } + if err := httpAPI(); err != nil { + log.Fatal(err) + return + } } func Test_httpApi(t *testing.T) { @@ -137,10 +141,6 @@ func Test_httpApi(t *testing.T) { wantErr: false, }, } - if err := httpAPI(); err != nil { - t.Errorf("httpApi() error = %v", err) - return - } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := http.Get(tt.request) diff --git a/nucleus/inizalize_test.go b/nucleus/initialise_test.go similarity index 98% rename from nucleus/inizalize_test.go rename to nucleus/initialise_test.go index e551b4472..16e0f2f02 100644 --- a/nucleus/inizalize_test.go +++ b/nucleus/initialise_test.go @@ -45,6 +45,12 @@ var gnmiAddress = "141.100.70.171:6030" // TODO: Move somewhere more sensible func TestMain(m *testing.M) { log.SetReportCaller(true) + + + if os.Getenv("GOSDN_LOG") == "nolog" { + log.SetLevel(log.PanicLevel) + } + gnmiMessages = map[string]pb.Message{ "../test/proto/cap-resp-arista-ceos": &gpb.CapabilityResponse{}, "../test/proto/req-full-node": &gpb.GetRequest{}, -- GitLab