diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 105784d85b11f231e4f6b2b3a7236f85673d9629..a6e281c4fa94f65595038ebdc89398733bccfd86 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,19 +5,14 @@ variables: GOLANG_VERSION: "1.16" stages: - - .pre - build - test + - analyze - apply - integration-test - deploy - .post -workflow: - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - when: never - - when: always include: - local: '/.gitlab/ci/.build-container.yml' diff --git a/.gitlab/ci/.build-container.yml b/.gitlab/ci/.build-container.yml index 99c7cb1e20520343f459e89396936463537e2d84..189e34f47c492cf28bb895130e1882df4e955134 100644 --- a/.gitlab/ci/.build-container.yml +++ b/.gitlab/ci/.build-container.yml @@ -5,6 +5,14 @@ entrypoint: [ "" ] variables: TAG: $CI_COMMIT_BRANCH + before_script: + # replace all slashes in the tag with hyphen, because slashes are not allowed in tags + - 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: rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH variables: @@ -14,14 +22,6 @@ TAG: develop BUILDARGS: -race - when: always - before_script: - # replace all slashes in the tag with hyphen, because slashes are not allowed in tags - - TAG=${TAG//\//-} - - mkdir -p /kaniko/.docker - - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" >/kaniko/.docker/config.json - needs: [] - -build-testing-image: script: - /kaniko/executor --cache=true @@ -29,11 +29,23 @@ build-testing-image: --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" <<: *build build-image: + rules: + - if: '$CI_PIPELINE_SOURCE != "merge_request_event"' + when: never + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + variables: + TAG: latest + - if: $CI_COMMIT_BRANCH == "develop" + variables: + TAG: develop + BUILDARGS: -race + - when: always script: - /kaniko/executor --cache=true @@ -41,6 +53,9 @@ build-image: --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" <<: *build + + #--build-arg "GITLAB_PROXY=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/" diff --git a/.gitlab/ci/.code-quality-ci.yml b/.gitlab/ci/.code-quality-ci.yml index dec181fcd6a0a091a2a368409530dedf2ed10316..3910d884c536da0059a8e09f41309fc4ae806eab 100644 --- a/.gitlab/ci/.code-quality-ci.yml +++ b/.gitlab/ci/.code-quality-ci.yml @@ -1,6 +1,6 @@ code-quality: - image: golangci/golangci-lint:latest-alpine - stage: test + image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/golangci/golangci-lint:latest-alpine + stage: analyze script: # writes golangci-lint output to gl-code-quality-report.json - golangci-lint run --config .gitlab/ci/.golangci-config/.golangci.yml --out-format code-climate | tee gl-code-quality-report.json diff --git a/.gitlab/ci/.containerlab-ci.yml b/.gitlab/ci/.containerlab-ci.yml index c3df1abacca1c42ba1feb8eaf4a0803b656c2ecd..f3a06f8ad8ef783f36b176cab610549781be6cac 100644 --- a/.gitlab/ci/.containerlab-ci.yml +++ b/.gitlab/ci/.containerlab-ci.yml @@ -5,6 +5,10 @@ variables: # Templates for Job Types .containerlab_deploy: &containerlab_deploy stage: apply + rules: + - if: '$CI_PIPELINE_SOURCE != "merge_request_event"' + when: never + - when: on_success tags: - shell before_script: @@ -16,8 +20,12 @@ variables: - docker pull ${CEOS_IMAGE} .containerlab_template: &containerlab_template - image: alpine:latest + image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/alpine:latest stage: build + rules: + - if: '$CI_PIPELINE_SOURCE != "merge_request_event"' + when: never + - when: on_success before_script: - export PATH="${PATH}:${CI_PROJECT_DIR}/.gitlab/ci/scripts" - firstOctet=$(generate_octet.sh $CI_COMMIT_SHA) @@ -61,6 +69,10 @@ containerlab:deploy:integration: containerlab:destroy: + rules: + - if: '$CI_PIPELINE_SOURCE != "merge_request_event"' + when: never + - when: always stage: .post tags: - shell @@ -72,7 +84,6 @@ containerlab:destroy: - docker volume rm -f ${CLAB_NAME}-volume - docker image rm -f ${GOSDN_IMAGE} allow_failure: true - when: always #containerlab:template:develop: diff --git a/.gitlab/ci/.deploy-k8s.yml b/.gitlab/ci/.deploy-k8s.yml index bac4bcbbe1e466d32866bdef4690632cdf451121..e2d8e52baae3834784bfd8cbe1a36f38d699b3bd 100644 --- a/.gitlab/ci/.deploy-k8s.yml +++ b/.gitlab/ci/.deploy-k8s.yml @@ -1,6 +1,6 @@ build:k8s-bot: stage: build - image: golang:$GOLANG_VERSION + image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/golang:$GOLANG_VERSION rules: - if: $CI_COMMIT_BRANCH == "develop" - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH @@ -14,7 +14,7 @@ build:k8s-bot: .deploy: &deploy image: - name: bitnami/kubectl:latest + name: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/bitnami/kubectl:latest entrypoint: [""] before_script: - echo "override global before script" diff --git a/.gitlab/ci/.integration-test.yml b/.gitlab/ci/.integration-test.yml index ef542259e7e7e2acd2ef8119cea98e2cf7eabefb..dc80d9815835f0c4231c5248234be38958da64dd 100644 --- a/.gitlab/ci/.integration-test.yml +++ b/.gitlab/ci/.integration-test.yml @@ -1,6 +1,10 @@ .integration-test: &integration-test image: $GOSDN_TESTING_IMAGE stage: integration-test + rules: + - if: '$CI_PIPELINE_SOURCE != "merge_request_event"' + when: never + - when: on_success needs: - job: "containerlab:deploy:integration" tags: diff --git a/.gitlab/ci/.security-and-compliance-ci.yml b/.gitlab/ci/.security-and-compliance-ci.yml index 3e98b739e62763538a6e6fe0d5bcf9259b91fbbd..a42c6695e77f10cfb7440e317bfbd0b73a629da9 100644 --- a/.gitlab/ci/.security-and-compliance-ci.yml +++ b/.gitlab/ci/.security-and-compliance-ci.yml @@ -1,3 +1,11 @@ +.rules: &rules + stage: analyze + rules: + - if: '$CI_PIPELINE_SOURCE != "merge_request_event"' + when: never + - when: always + needs: [] + sast: variables: SAST_ANALYZER_IMAGE_TAG: '2' @@ -8,3 +16,33 @@ include: - template: Security/SAST.gitlab-ci.yml - template: Dependency-Scanning.gitlab-ci.yml - template: Security/License-Scanning.gitlab-ci.yml +# - template: Security/Secret-Detection.gitlab-ci.yml + - template: Security/Container-Scanning.gitlab-ci.yml + +gemnasium-dependency_scanning: + <<: *rules + +gosec-sast: + <<: *rules + +license_scanning: + <<: *rules + +semgrep-sast: + <<: *rules + +#secret_detection: +# <<: *rules + +container_scanning: + stage: analyze + rules: + - if: '$CI_PIPELINE_SOURCE != "merge_request_event"' + when: never + - when: always + variables: + DOCKER_IMAGE: "${GOSDN_IMAGE}" + DOCKER_USER: "${CI_REGISTRY_USER}" + DOCKER_PASSWORD: "${CI_REGISTRY_PASSWORD}" + needs: + - build-image diff --git a/.gitlab/ci/.test.yml b/.gitlab/ci/.test.yml index 68b22dc6fd23a977476696aa803b78c1710a4adf..762da835770a5f8e3666f8287a18a1d83b6db509 100644 --- a/.gitlab/ci/.test.yml +++ b/.gitlab/ci/.test.yml @@ -1,6 +1,8 @@ .test: &test image: $GOSDN_TESTING_IMAGE stage: test + rules: + - when: on_success variables: GOSDN_LOG: "nolog" GOSDN_CHANGE_TIMEOUT: "100ms" @@ -24,3 +26,10 @@ controller-test: script: - gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun <<: *test + +test-build: + artifacts: + when: never + script: + - GOOS=linux go build $BUILDARGS ./cmd/gosdn + <<: *test diff --git a/.gitlab/ci/.uml-autogen-ci.yml b/.gitlab/ci/.uml-autogen-ci.yml index cd7db4c9dceb8716b47f27401b940159157b26d3..adaf8c99dc09056b5183d0177e7c3e7dfaf6a5b3 100644 --- a/.gitlab/ci/.uml-autogen-ci.yml +++ b/.gitlab/ci/.uml-autogen-ci.yml @@ -1,5 +1,5 @@ goplantuml: - image: golang:$GOLANG_VERSION + image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/golang:$GOLANG_VERSION stage: .post only: - develop diff --git a/Dockerfile b/Dockerfile index 48ab0f161f61439459a792aac584ee7c82132630..b583530d460522d176b4899f774ef7e73c546f80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ ARG GOLANG_VERSION=1.16 ARG BUILDARGS +ARG $GITLAB_PROXY -FROM golang:$GOLANG_VERSION-buster AS installer +FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-buster AS installer WORKDIR /src/gosdn COPY go.* ./ @@ -13,7 +14,7 @@ COPY . ./ RUN GOOS=linux go build $BUILDARGS ./cmd/gosdn -FROM debian:bullseye +FROM ${GITLAB_PROXY}debian:bullseye EXPOSE 8080 EXPOSE 55055 COPY --from=builder /src/gosdn/gosdn .