Skip to content
Snippets Groups Projects
Commit ca966b71 authored by Malte Bauch's avatar Malte Bauch Committed by Fabian Seidl
Browse files

Fix: Improve Dockerfiles and containerlab creation (especially in build and startup time)


See merge request !341

Co-authored-by: default avatarMalte Bauch <malte.bauch@extern.h-da.de>
parent bbedf774
No related branches found
No related tags found
2 merge requests!341Fix: Improve Dockerfiles and containerlab creation (especially in build and startup time),!333WIP: Develop
Pipeline #107287 passed
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
build-testing-image: build-testing-image:
script: script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - 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 buildx build -t "$GOSDN_TESTING_IMAGE" -f "${CI_PROJECT_DIR}/controller/controller.Dockerfile" --target "builder" --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" - docker push "$GOSDN_TESTING_IMAGE"
<<: *build <<: *build
build-image: build-image:
script: script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - 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" --build-arg "GOLANG_VERSION=$GOLANG_VERSION" --build-arg "BUILDARGS=$BUILDARGS" --build-arg "GITLAB_PROXY=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/" . - docker buildx build -t "$CI_REGISTRY_IMAGE:$TAG" -f "${CI_PROJECT_DIR}/controller/controller.Dockerfile" --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" - docker push "$CI_REGISTRY_IMAGE:$TAG"
# replace all slashes in the tag with hyphen, because slashes are not allowed in tags # replace all slashes in the tag with hyphen, because slashes are not allowed in tags
- NEWTAG=${CI_COMMIT_BRANCH//\//-} - NEWTAG=${CI_COMMIT_BRANCH//\//-}
......
...@@ -52,32 +52,49 @@ generate-csbi-yang-models: install-tools ...@@ -52,32 +52,49 @@ generate-csbi-yang-models: install-tools
../../$(TOOLS_DIR)/go-ygot-generator-generator config.yaml gostructs.go &&\ ../../$(TOOLS_DIR)/go-ygot-generator-generator config.yaml gostructs.go &&\
go generate go generate
build: pre build: pre build-gosdn build-gosdnc build-orchestrator
$(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/gosdn ./controller/cmd/gosdn
build-gosdn: pre
$(GOBUILD) -trimpath -o $(BUILD_ARTIFACTS_PATH)/gosdn ./controller/cmd/gosdn
build-gosdnc: pre
CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/gosdnc ./cli/ CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/gosdnc ./cli/
build-orchestrator: pre
CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/orchestrator ./csbi/cmd/csbi/ CGO_ENABLED=0 $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/orchestrator ./csbi/cmd/csbi/
start: build containerize-all: containerize-gosdn containerize-gosdnc containerize-orchestrator containerize-target
./$(BUILD_ARTIFACTS_PATH)/gosdn -l debug --config ./controller/configs/gosdn.toml
containerize-gosdn:
docker buildx build --rm -t gosdn -f controller/controller.Dockerfile .
containerize-gosdnc:
docker buildx build --rm -t gosdnc -f cli/cli.Dockerfile .
container: build containerize-orchestrator:
docker build -t gosdn -f controller/Dockerfile . docker buildx build --rm -t orchestrator -f csbi/csbi.Dockerfile .
docker build -t gosdnc -f cli/Dockerfile .
docker build -t orchestrator -f csbi/Dockerfile .
docker build -t gnmi-target -f csbi/gnmi-target/Dockerfile .
containerlab-start: container containerize-target:
docker buildx build --rm -t gnmi-target -f csbi/gnmi-target/gnmitarget.Dockerfile .
containerlab-start: containerize-all
sudo containerlab deploy --topo gosdn.clab.yaml sudo containerlab deploy --topo gosdn.clab.yaml
containerlab-stop: containerlab-stop:
sudo containerlab destroy --topo gosdn.clab.yaml sudo containerlab destroy --topo gosdn.clab.yaml
containerlab-graph: containerlab-graph:
sudo containerlab graph --topo gosdn.clab.yaml sudo containerlab graph --topo gosdn.clab.yaml
shell-gosdn: shell-gosdn:
docker exec -it clab-gosdn_csbi_arista_base-gosdn bash docker exec -it clab-gosdn_csbi_arista_base-gosdn bash
shell-orchestrator: shell-orchestrator:
docker exec -it clab-gosdn_csbi_arista_base-orchestrator bash docker exec -it clab-gosdn_csbi_arista_base-orchestrator bash
start: build-gosdn
./$(BUILD_ARTIFACTS_PATH)/gosdn -l debug --config ./controller/configs/gosdn.toml
clean: clean:
$(GOCLEAN) $(GOCLEAN)
rm -rf $(BUILD_ARTIFACTS_PATH) rm -rf $(BUILD_ARTIFACTS_PATH)
ARG GOLANG_VERSION=1.18
ARG BUILDARGS
ARG $GITLAB_PROXY
FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-buster AS installer
WORKDIR /gosdn/
COPY go.* ./
RUN go mod download
FROM installer as builder
COPY . .
RUN make build
FROM scratch as gosdnc
COPY --from=builder /gosdn/artifacts/gosdnc /
ENTRYPOINT ["/gosdnc"]
ARG GOLANG_VERSION=1.18
ARG BUILDARGS
ARG $GITLAB_PROXY
FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-alpine AS builder
WORKDIR /gosdn/
RUN apk add build-base
COPY . .
RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
make build-gosdnc
FROM scratch as gosdnc
COPY --from=builder /gosdn/artifacts/gosdnc /
ENTRYPOINT ["./gosdnc"]
.git
.gitlab
build
documentation
mocks
test
clab-gosdn_csbi_arista_base
.cobra.yaml
*.dockerignore
.gitlab-ci.yaml
ARCHITECTURE.md
CONTRIBUTING.md
README.md
artifacts
build-tools
models
csbi
ARG GOLANG_VERSION=1.18
ARG BUILDARGS
ARG $GITLAB_PROXY
FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-buster AS installer
WORKDIR /gosdn/
COPY go.* ./
RUN go mod download
FROM installer as builder
COPY . .
RUN make build
FROM builder as gosdn
COPY controller/configs/development-gosdn.toml.example /gosdn/configs/development-gosdn.toml
COPY controller/configs/containerlab-gosdn.toml.example /gosdn/configs/containerlab-gosdn.toml
ENTRYPOINT ["/gosdn/artifacts/gosdn"]
...@@ -36,16 +36,16 @@ start-insecure: clean build ...@@ -36,16 +36,16 @@ start-insecure: clean build
ENVIRONMENT=development ./$(BINARY_NAME) -l debug -s insecure ENVIRONMENT=development ./$(BINARY_NAME) -l debug -s insecure
unit-test: install-tools unit-test: install-tools
ENVIRONMENT=testing ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -coverprofile=coverage.out ENVIRONMENT=testing ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -trimpath -coverprofile=coverage.out
controller-test: install-tools controller-test: install-tools
ENVIRONMENT=testing ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun ENVIRONMENT=testing ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun
ci-unit-test: ci-install-tools ci-unit-test: ci-install-tools
ENVIRONMENT=testing gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -coverprofile=coverage.out -covermode atomic -timeout 30m ENVIRONMENT=testing gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -trimpath -coverprofile=coverage.out -covermode atomic -timeout 30m
ci-controller-test: ci-install-tools ci-controller-test: ci-install-tools
ENVIRONMENT=testing gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun -coverprofile=coverage.out ENVIRONMENT=testing gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun -trimpath -coverprofile=coverage.out
integration-test-nucleus: integration-test-nucleus:
ENVIRONMENT=testing &&\ ENVIRONMENT=testing &&\
......
ARG GOLANG_VERSION=1.18
ARG BUILDARGS
ARG $GITLAB_PROXY
FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-alpine as builder
WORKDIR /gosdn/
RUN apk add --no-cache build-base
RUN apk add --no-cache bash
COPY . .
RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
make build-gosdn
# NOTE: We probably want to make this smaller
FROM builder as gosdn
COPY controller/configs/development-gosdn.toml.example ./configs/development-gosdn.toml
COPY controller/configs/containerlab-gosdn.toml.example ./configs/containerlab-gosdn.toml
ENTRYPOINT ["./artifacts/gosdn"]
.git
.gitlab
build
documentation
mocks
test
clab-gosdn_csbi_arista_base
.cobra.yaml
.dockeringore
.gitlab-ci.yaml
ARCHITECTURE.md
CONTRIBUTING.md
README.md
artifacts
build-tools
models/YangModels
models/arista
...@@ -27,6 +27,7 @@ func BuildPlugin(path string, sourceFileNames []string, args ...string) error { ...@@ -27,6 +27,7 @@ func BuildPlugin(path string, sourceFileNames []string, args ...string) error {
"go", "go",
"build", "build",
"-buildmode=plugin", "-buildmode=plugin",
"-trimpath",
"-o", "-o",
pPath, pPath,
} }
......
...@@ -2,17 +2,19 @@ ARG GOLANG_VERSION=1.18 ...@@ -2,17 +2,19 @@ ARG GOLANG_VERSION=1.18
ARG BUILDARGS ARG BUILDARGS
ARG $GITLAB_PROXY ARG $GITLAB_PROXY
FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-buster AS installer FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-alpine AS builder
WORKDIR /gosdn/ WORKDIR /gosdn/
RUN apk add build-base
COPY ./models ./models
COPY ./forks ./forks
COPY ./Makefile .
COPY ./api ./api
COPY ./controller ./controller
COPY ./csbi ./csbi
COPY go.* ./ COPY go.* ./
RUN go mod download RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
FROM installer as builder make build-orchestrator
COPY . .
RUN make build
FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-alpine FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-alpine
RUN apk add --no-cache git make build-base RUN apk add --no-cache git make build-base
......
.git
.gitlab
build
documentation
mocks
test
clab-gosdn_csbi_arista_base
.cobra.yaml
.dockeringore
.gitlab-ci.yaml
ARCHITECTURE.md
CONTRIBUTING.md
README.md
artifacts
build-tools
models/YangModels/vendor
models/YangModels/experimental
.git
.gitlab
build
documentation
mocks
test
clab-gosdn_csbi_arista_base
.cobra.yaml
*.dockerignore
.gitlab-ci.yaml
ARCHITECTURE.md
CONTRIBUTING.md
README.md
artifacts
build-tools
models
cli
controller
api
scripts
forks
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment