diff --git a/.gitlab/ci/.build-container.yml b/.gitlab/ci/.build-container.yml index 648feba5377339f5ccd166ae88f13db9d18833c4..d4122a62259caca73b7a2cd97b496963c2007d1a 100644 --- a/.gitlab/ci/.build-container.yml +++ b/.gitlab/ci/.build-container.yml @@ -1,16 +1,12 @@ .build: &build stage: build - image: - name: gcr.io/kaniko-project/executor:debug - entrypoint: [""] + tags: + - shell-builder variables: - TAG: $CI_COMMIT_BRANCH + TAG: $CI_COMMIT_SHA before_script: # replace all slashes in the tag with hyphen, because slashes are not allowed in tags - - cd controller/ - TAG=${TAG//\//-} - - mkdir -p /kaniko/.docker - - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"},\"$CI_DEPENDENCY_PROXY_SERVER\":{\"username\":\"$CI_DEPENDENCY_PROXY_USER\",\"password\":\"$CI_DEPENDENCY_PROXY_TOKEN\"}}}" > /kaniko/.docker/config.json needs: [] build-testing-image: @@ -24,15 +20,9 @@ build-testing-image: BUILDARGS: -race - when: always script: - - /kaniko/executor - --cache=true - --context "$CI_PROJECT_DIR" - --dockerfile "Dockerfile" - --build-arg "GOLANG_VERSION=$GOLANG_VERSION" - --build-arg "BUILDARGS=$BUILDARGS" - --build-arg "GITLAB_PROXY=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/" - --destination "$GOSDN_TESTING_IMAGE" - --target "installer" + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker build -t "$GOSDN_TESTING_IMAGE" -f "${CI_PROJECT_DIR}/controller/Dockerfile" --target "installer" --build-arg "GOLANG_VERSION=$GOLANG_VERSION" --build-arg "BUILDARGS=$BUILDARGS" --build-arg "GITLAB_PROXY=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/" . + - docker push "$GOSDN_TESTING_IMAGE" <<: *build build-image: @@ -48,13 +38,7 @@ build-image: BUILDARGS: -race - when: always script: - - /kaniko/executor - --cache=true - --context "$CI_PROJECT_DIR" - --dockerfile "Dockerfile" - --build-arg "GOLANG_VERSION=$GOLANG_VERSION" - --build-arg "BUILDARGS=$BUILDARGS" - --build-arg "GITLAB_PROXY=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/" - --destination "$GOSDN_IMAGE" - --destination "$CI_REGISTRY_IMAGE:$TAG" + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker build -t "$CI_REGISTRY_IMAGE:$TAG" -f "${CI_PROJECT_DIR}/controller/Dockerfile" --target "installer" --build-arg "GOLANG_VERSION=$GOLANG_VERSION" --build-arg "BUILDARGS=$BUILDARGS" --build-arg "GITLAB_PROXY=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/" . + - docker push "$CI_REGISTRY_IMAGE:$TAG" <<: *build diff --git a/.gitlab/ci/.containerlab-ci.yml b/.gitlab/ci/.containerlab-ci.yml index a37e7243ed64139f927bf28d1afdfdd23ef4ad28..3b0c201e4b222782f60a3790be0f38f599544a4e 100644 --- a/.gitlab/ci/.containerlab-ci.yml +++ b/.gitlab/ci/.containerlab-ci.yml @@ -48,7 +48,7 @@ variables: containerlab:template:integration: extends: .containerlab_template variables: - CLAB_TEMPLATE: "${CI_PROJECT_DIR}/test/containerlab/int01.clab.tmpl.yml" + CLAB_TEMPLATE: "${CI_PROJECT_DIR}/controller/test/containerlab/int01.clab.tmpl.yml" containerlab:deploy:integration: extends: .containerlab_deploy diff --git a/.gitlab/ci/.test.yml b/.gitlab/ci/.test.yml index 226d5ce0b0ef158676e1714ed1350c0545e829c1..b494223a2b8104d7d37b9ba316348f815f633375 100644 --- a/.gitlab/ci/.test.yml +++ b/.gitlab/ci/.test.yml @@ -15,6 +15,7 @@ unit-test: script: + - cd controller - make ci-unit-test after_script: - go tool cover -func=coverage.out @@ -22,6 +23,7 @@ unit-test: controller-test: script: + - cd controller - make ci-controller-test <<: *test @@ -29,5 +31,5 @@ test-build: artifacts: when: never script: - - GOOS=linux go build $BUILDARGS ./cmd/gosdn + - make build <<: *test diff --git a/Makefile b/Makefile index f74b8561b7751d7742a6b729131a832c71d54d5c..8959a3a93e2be0a9cb6af690cebe5f633fd2ebce 100644 --- a/Makefile +++ b/Makefile @@ -28,9 +28,11 @@ ci-install-tools: build: pre CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/gosdn ./controller/cmd/gosdn CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/gosdnc ./cli/ + CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/orchestrator ./csbi/cmd/csbi/ container: build docker build -t gosdn -f controller/Dockerfile . + docker build -t orchestrator -f csbi/Dockerfile . clean: $(GOCLEAN) diff --git a/controller/Dockerfile b/controller/Dockerfile index a62551bad85002175b01294022e40fb7d28aaa17..355668ae40bc0beca422f5187b50f355435abe37 100644 --- a/controller/Dockerfile +++ b/controller/Dockerfile @@ -1,4 +1,21 @@ -FROM scratch +ARG GOLANG_VERSION=1.18 +ARG BUILDARGS +ARG $GITLAB_PROXY + +FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-buster AS installer + +WORKDIR /src/gosdn/controller +COPY go.* ./ +RUN go mod download + +FROM installer as builder + +COPY ./controller ./ + +RUN make build + + +FROM scratch as gosdn COPY artifacts/gosdn / diff --git a/csbi/Dockerfile b/csbi/Dockerfile index 2c84b5ec3c5d0ba890eee366105c109d13b3567c..371f74ec2d1627edb904fe2697506e1d28443a06 100644 --- a/csbi/Dockerfile +++ b/csbi/Dockerfile @@ -1,24 +1,23 @@ -# syntax = docker/dockerfile:1.2 +ARG GOLANG_VERSION=1.18 +ARG BUILDARGS +ARG $GITLAB_PROXY -FROM golang:1.18-alpine AS installer -WORKDIR /build -RUN apk add --no-cache git make build-base -RUN apk add --update --no-cache alpine-sdk -COPY go.mod . -COPY go.sum . +FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-buster AS installer + +WORKDIR /src/gosdn/controller +COPY go.* ./ RUN go mod download FROM installer as builder -COPY . . -RUN --mount=type=cache,target=/root/.cache/go-build \ -GOOS=linux go build -o orchestrator ./cmd/csbi/main.go -FROM golang:1.18-alpine -RUN apk add --no-cache git make build-base -RUN apk add --update --no-cache alpine-sdk -COPY --from=builder /build/orchestrator . -COPY --from=builder /build/models ./models -COPY --from=builder /build/resources ./resources +COPY ./csbi ./ + +RUN make build + +FROM scratch +COPY --from=builder artifacts/orchestrator . +COPY --from=builder csbi/models ./models +COPY --from=builder csbi/resources ./resources EXPOSE 55056 -ENTRYPOINT [ "./orchestrator" ] +ENTRYPOINT [ "/orchestrator" ] CMD [""] diff --git a/gosdn.clab.yml b/gosdn.clab.yml new file mode 100644 index 0000000000000000000000000000000000000000..52549881f5e58651901ec303f9e085f12e85ded9 --- /dev/null +++ b/gosdn.clab.yml @@ -0,0 +1,57 @@ +name: gosdn_csbi_arista_base + +mgmt: + network: csbi_csbi-dev-net + +topology: + kinds: + ceos: + image: registry.code.fbi.h-da.de/danet/gosdn/ceos:latest + nodes: + ceos0: + kind: ceos + ceos1a: + kind: ceos + gosdn: + kind: linux + image: gosdn-base + ports: + - "55055:55055" + - "8080:8080" + - "40000:40000" + cmd: ["--csbi-orchestrator", "orchestrator:55056"] + gnmi-target: + kind: linux + image: gnmi-target-base + ports: + - "7030:7030" + csbi-orchestrator: + kind: linux + image: csbi-orchestrator-base + ports: + - 55056:55056 + - 9338:9338 + binds: + - "/var/run/docker.sock:/var/run/docker.sock" + - ./.csbi.yml:/etc/.csbi.yml + cmd: ["--log-level", "trace", "--config", "/etc/.csbi.yml"] + + grafana: + kind: linux + image: grafana/grafana:8.1.2 + restart: unless-stopped + binds: + - ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources + - grafana-data:/var/lib/grafana + prometheus: + kind: linux + image: prom/prometheus:v2.29.1 + ports: + - 9000:9090 + binds: + - ./prometheus:/etc/prometheus + - prometheus-data:/prometheus + cmd: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml + + links: + - endpoints: ["ceos0:eth1", "ceos1a:eth1"]