Skip to content
Snippets Groups Projects
Commit b3babef2 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

Merge branch 'refactor-container-deployment' into 'develop'

Refactor container deployment

See merge request cocsn/gosdn!123
parents a71d4d59 b603d6e7
Branches
Tags
3 merge requests!123Refactor container deployment,!122Resolve "Data Race HTTP API",!90Develop
Pipeline #67394 failed
...@@ -6,7 +6,7 @@ variables: ...@@ -6,7 +6,7 @@ variables:
DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_CERTDIR: "/certs"
DOCKER_IMAGE_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA DOCKER_IMAGE_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
.deploy: &deploy .build: &build
before_script: before_script:
- echo "override global before script" - echo "override global before script"
image: docker:19.03.12 image: docker:19.03.12
...@@ -18,54 +18,31 @@ variables: ...@@ -18,54 +18,31 @@ variables:
docker build \ docker build \
--build-arg GITLAB_USER=$GO_MODULES_USER \ --build-arg GITLAB_USER=$GO_MODULES_USER \
--build-arg GITLAB_TOKEN=$GO_MODULES_ACCESS_TOKEN \ --build-arg GITLAB_TOKEN=$GO_MODULES_ACCESS_TOKEN \
-t $DOCKER_IMAGE_SHA . -t $DOCKER_IMAGE_SHA $PATH
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker tag $DOCKER_IMAGE_SHA $TAG - docker tag $DOCKER_IMAGE_SHA $TAG
- docker push $TAG - docker push $TAG
deploy:develop: build:develop:
variables: variables:
TAG: $CI_REGISTRY_IMAGE:develop TAG: $CI_REGISTRY_IMAGE:develop
HOOK: $PORTAINER_HOOK_DEVELOP PATH: build/dockerfiles/staging
rules: rules:
- if: $CI_COMMIT_BRANCH == "develop" - if: $CI_COMMIT_BRANCH == "develop"
<<: *deploy <<: *build
deploy:latest: build:merge-request:
variables: variables:
TAG: $CI_REGISTRY_IMAGE:latest TAG: $CI_REGISTRY_IMAGE:merge-request
HOOK: $PORTAINER_HOOK_LATEST PATH: build/dockerfiles/staging
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
<<: *deploy
.deploy:mr: &deploy-mr
before_script:
- echo "override global before script"
image: docker:19.03.12
stage: build
tags:
- dind
script:
- >
docker build \
--build-arg GITLAB_USER=$GO_MODULES_USER \
--build-arg GITLAB_TOKEN=$GO_MODULES_ACCESS_TOKEN \
-t $DOCKER_IMAGE_SHA .
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker tag $DOCKER_IMAGE_SHA $TAG
- docker push $TAG
deploy:merge-request:master:
variables:
TAG: $CI_REGISTRY_IMAGE:mr-master
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "merge_request_event"
<<: *deploy-mr <<: *build
deploy:merge-mr:develop: build:latest:
variables: variables:
TAG: $CI_REGISTRY_IMAGE:mr-develop TAG: $CI_REGISTRY_IMAGE:latest
PATH: build/dockerfiles/production
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop' - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
<<: *deploy-mr <<: *build
\ No newline at end of file
...@@ -21,12 +21,9 @@ cache: ...@@ -21,12 +21,9 @@ cache:
- export TF_VAR_tls_cert=${DOCKER_TLS_CERT} - export TF_VAR_tls_cert=${DOCKER_TLS_CERT}
- export TF_VAR_tls_ca_cert=${DOCKER_TLS_CA} - export TF_VAR_tls_ca_cert=${DOCKER_TLS_CA}
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop')
variables: variables:
TF_VAR_container_tag: $CI_REGISTRY_IMAGE:mr-master TF_VAR_container_tag: $CI_REGISTRY_IMAGE:merge-request
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop'
variables:
TF_VAR_container_tag: $CI_REGISTRY_IMAGE:mr-develop
- if: $CI_COMMIT_BRANCH == "integration-test" - if: $CI_COMMIT_BRANCH == "integration-test"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
......
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 [""]
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 [""]
...@@ -47,19 +47,8 @@ func initialize() error { ...@@ -47,19 +47,8 @@ func initialize() error {
} }
// TODO: Start grpc listener here // TODO: Start grpc listener here
if err := httpAPI(); err != nil {
return err
}
attachDatabase()
return nil
}
// deprecated return httpAPI()
// attachDatabase connects to the database and passes the connection to the controller core
func attachDatabase() {
c.database = database.NewDatabaseClient()
} }
// createSouthboundInterfaces initializes the controller with its supported SBIs // createSouthboundInterfaces initializes the controller with its supported SBIs
...@@ -87,9 +76,11 @@ func createPrincipalNetworkDomain(sbi SouthboundInterface) error { ...@@ -87,9 +76,11 @@ func createPrincipalNetworkDomain(sbi SouthboundInterface) error {
// Run calls initialize to start the controller // Run calls initialize to start the controller
func Run(ctx context.Context) error { func Run(ctx context.Context) error {
var initError error var initError error
coreLock.Lock()
coreOnce.Do(func() { coreOnce.Do(func() {
initError = initialize() initError = initialize()
}) })
coreLock.Unlock()
if initError != nil { if initError != nil {
log.WithFields(log.Fields{}).Error(initError) log.WithFields(log.Fields{}).Error(initError)
return initError return initError
......
...@@ -9,12 +9,9 @@ import ( ...@@ -9,12 +9,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http" "net/http"
"net/url" "net/url"
"sync"
"time" "time"
) )
var httpOnce sync.Once
func stopHttpServer() error { func stopHttpServer() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
...@@ -34,16 +31,11 @@ func registerHttpHandler() { ...@@ -34,16 +31,11 @@ func registerHttpHandler() {
} }
// deprecated // deprecated
func httpAPI() (err error) { func httpAPI() error {
coreLock.Lock() registerHttpHandler()
defer coreLock.Unlock()
httpOnce.Do(registerHttpHandler)
c.httpServer = &http.Server{Addr: ":8080"} c.httpServer = &http.Server{Addr: ":8080"}
go func() { go func() {
err = c.httpServer.ListenAndServe() log.Info(c.httpServer.ListenAndServe())
if err != nil {
return
}
}() }()
return nil return nil
} }
......
...@@ -45,6 +45,12 @@ var gnmiAddress = "141.100.70.171:6030" ...@@ -45,6 +45,12 @@ var gnmiAddress = "141.100.70.171:6030"
// TODO: Move somewhere more sensible // TODO: Move somewhere more sensible
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
log.SetReportCaller(true) log.SetReportCaller(true)
if os.Getenv("GOSDN_LOG") == "nolog" {
log.SetLevel(log.PanicLevel)
}
gnmiMessages = map[string]pb.Message{ gnmiMessages = map[string]pb.Message{
"../test/proto/cap-resp-arista-ceos": &gpb.CapabilityResponse{}, "../test/proto/cap-resp-arista-ceos": &gpb.CapabilityResponse{},
"../test/proto/req-full-node": &gpb.GetRequest{}, "../test/proto/req-full-node": &gpb.GetRequest{},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment