diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1ca81acf95e0e7ade693b0b2431b7962eedba884..8de33ee9869141beb2d80e46118830d25041f54f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,8 @@ variables: stages: - test - - documentation + - build + - deploy before_script: - git config --global url."https://$GO_MODULES_USER:$GO_MODULES_ACCESS_TOKEN@code.fbi.h-da.de".insteadOf "https://code.fbi.h-da.de" @@ -12,3 +13,4 @@ include: - local: '/build/ci/.code-quality-ci.yml' - local: '/build/ci/.documentation-ci.yml' - local: '/build/ci/.security-and-compliance-ci.yml' + - local: '/build/ci/.build-container.yml' \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..4e90a5a77bc40d69b7d43366173e76c3d6a251ef --- /dev/null +++ b/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/ci/.build-container.yml b/build/ci/.build-container.yml new file mode 100644 index 0000000000000000000000000000000000000000..0e21b40e8c80f14cf2eb4609807f23e06c3bb6e2 --- /dev/null +++ b/build/ci/.build-container.yml @@ -0,0 +1,47 @@ +variables: + DOCKER_IMAGE_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + +build:docker: + stage: build + tags: + - baremetal + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + script: + - > + docker build \ + --build-arg GITLAB_USER=$GO_MODULES_USER \ + --build-arg GITLAB_TOKEN=$GO_MODULES_ACCESS_TOKEN \ + -t $DOCKER_IMAGE_SHA . + +.deploy: &deploy + stage: deploy + needs: ["build:docker"] + tags: + - baremetal + script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - docker tag $DOCKER_IMAGE_SHA $TAG + - docker push $TAG + +deploy:develop: + variables: + TAG: $CI_REGISTRY_IMAGE:develop + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + <<: *deploy + +deploy:tagged: + variables: + TAG: $CI_REGISTRY_IMAGE:CI_COMMIT_TAG + rules: + - if: $CI_COMMIT_TAG + <<: *deploy + +deploy:latest: + variables: + TAG: $CI_REGISTRY_IMAGE:latest + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + <<: *deploy \ No newline at end of file diff --git a/build/ci/.documentation-ci.yml b/build/ci/.documentation-ci.yml index cd9bbc427f9afacd78c3f4ec6be1f3cf9544c844..23a5caf7f43f0601939a1740e3ca3803d37ae007 100644 --- a/build/ci/.documentation-ci.yml +++ b/build/ci/.documentation-ci.yml @@ -5,7 +5,7 @@ documentation:pdf: name: pandoc/latex entrypoint: - '' - stage: documentation + stage: deploy rules: - changes: - documentation/design/*.md @@ -22,7 +22,7 @@ documentation:pdf: - cargo install mdbook image: name: rust:latest - stage: documentation + stage: deploy script: - mdbook build documentation --dest-dir public cache: diff --git a/cmd/gosdn/main.go b/cmd/gosdn/main.go index 800252d804efd745aac2b87bd45ee5ce3df6ec66..0f3e798ba397c7bfdfe4c53283e3cc95b8d5358e 100644 --- a/cmd/gosdn/main.go +++ b/cmd/gosdn/main.go @@ -4,13 +4,12 @@ import ( "code.fbi.h-da.de/cocsn/gosdn/log" "code.fbi.h-da.de/cocsn/gosdn/nucleus" "flag" - "log/syslog" ) func main() { // register our supported flags - cliListenAddr := flag.String("cli-listen-addr", "localhost", "The IP address of the grpcCLI.") + cliListenAddr := flag.String("cli-listen-addr", "", "The IP address of the grpcCLI.") cliListenPort := flag.String("cli-server-port", "55055", "The port number of the grpcCLI") configFileName := flag.String("config-file", "", "Path to the config file") @@ -18,16 +17,6 @@ func main() { cliSocket := *cliListenAddr + ":" + *cliListenPort log.Loglevel(log.DEBUG) - syslogWriter, err := syslog.New(syslog.LOG_ALERT, "gosdn") - defer func() { - if err := syslogWriter.Close(); err != nil { - log.Fatal(err) - } - }() - if err != nil { - log.Fatal(err) - } - log.LoglevelOutput(log.INFO, syslogWriter) // Setup a channel to communicate if goSDN should shutdown. IsRunningChannel := make(chan bool)