diff --git a/.cilibs/build.sh b/.cilibs/build.sh new file mode 100755 index 0000000..46a2085 --- /dev/null +++ b/.cilibs/build.sh @@ -0,0 +1,40 @@ +#!/bin/bash -e + +GATE_VERSION=release-1.20.x +BUILD_OS=linux +BUILD_ARCH=amd64 + + +while getopts "o:a:g:c:" opt; do + case ${opt} in + o) #Build OS + BUILD_OS=${OPTARG} + ;; + a) #Build arch + BUILD_ARCH=${OPTARG} + ;; + g) #Gate version + GATE_VERSION=${OPTARG} + ;; + c) #Send Coverity + SEND_COVERITY=${OPTARG} + ;; + esac +done + +.cilibs/get_dependencies.sh + +.cilibs/examine_source_code_with_go_get.sh + +.cilibs/execute_go_tests.sh + +.cilibs/compile_code.sh -o ${BUILD_OS} -a ${BUILD_ARCH} -g ${GATE_VERSION} + +.cilibs/calculate_code_coverage.sh $SEND_COVERITY + +.cilibs/check_linting.sh + +.cilibs/copy_binaries_for_later_use.sh + +.cilibs/generate_checksum.sh -o ${BUILD_OS} -a ${BUILD_ARCH} -g ${GATE_VERSION} + diff --git a/.cilibs/calculate_code_coverage.sh b/.cilibs/calculate_code_coverage.sh new file mode 100755 index 0000000..9829e1f --- /dev/null +++ b/.cilibs/calculate_code_coverage.sh @@ -0,0 +1,31 @@ +#!/bin/bash -e + +SEND_COVERITY=$1 +COMMIT_ID="${CIRCLE_SHA1:-$TRAVIS_COMMIT}" + + +echo "Calculate code coverage" +REQUIREDCODECOVERAGE=60 +go tool cover -func cover.out | tee codecoverage.txt +CURRENTCODECOVERAGE=$(grep 'total:' codecoverage.txt | awk '{print substr($3, 1, length($3)-1)}') + +echo "Send coverity report to SeriesCI" +if [[ $SEND_COVERITY == "send" ]] +then + curl \ + --header "Authorization: Token ${SERIESCI_TOKEN}" \ + --header "Content-Type: application/json" \ + --data "{\"value\":\"${CURRENTCODECOVERAGE} %\",\"sha\":\"${COMMIT_ID}\"}" \ + https://seriesci.com/api/codilime/floodgate/coverage/one +else + echo "Skipping" +fi +if [ ${CURRENTCODECOVERAGE%.*} -lt ${REQUIREDCODECOVERAGE} ] +then + echo "Not enough code coverage!" + echo "Current code coverage: ${CURRENTCODECOVERAGE}%" + echo "Required code coverage: ${REQUIREDCODECOVERAGE}%" + exit 1 +else + echo "Code coverage is at least ${REQUIREDCODECOVERAGE}% : OK" +fi diff --git a/.cilibs/check_linting.sh b/.cilibs/check_linting.sh new file mode 100755 index 0000000..c20fbbc --- /dev/null +++ b/.cilibs/check_linting.sh @@ -0,0 +1,8 @@ +#!/bin/bash -e + +echo "Check linting" +for GOSRCFILE in $( find . -type f -name '*.go' -not -path './gateapi/*') +do + golint -set_exit_status $GOSRCFILE +done + diff --git a/.cilibs/compile_code.sh b/.cilibs/compile_code.sh new file mode 100755 index 0000000..0971101 --- /dev/null +++ b/.cilibs/compile_code.sh @@ -0,0 +1,42 @@ +#!/bin/bash -e + +GATE_VERSION=release-1.20.x +BUILD_OS=linux +BUILD_ARCH=amd64 +COMMIT_ID="${CIRCLE_SHA1:-$TRAVIS_COMMIT}" + + +while getopts "o:a:g:" opt; do + case ${opt} in + o) #Build OS + BUILD_OS=${OPTARG} + ;; + a) #Build arch + BUILD_ARCH=${OPTARG} + ;; + g) #Gate version + GATE_VERSION=${OPTARG} + ;; + esac +done + +if [ ! -z "$TRAVIS_BRANCH" ] +then + export RELEASE=$TRAVIS_BRANCH +elif [ -z "$CIRCLE_BRANCH" ] +then + export RELEASE=$(echo $CIRCLE_TAG | sed 's/^v[0-9]\+\.[0-9]\+\.[0-9]\+-\?//') +else + export RELEASE=$CIRCLE_BRANCH +fi + +echo "Compile code" + +env GOOS=${BUILD_OS} GOARCH=${BUILD_ARCH} go build -ldflags \ +"-X github.com/codilime/floodgate/version.GitCommit=$COMMIT_ID \ +-X github.com/codilime/floodgate/version.BuiltDate=$(date +%Y-%m-%d_%H:%M:%S) \ +-X github.com/codilime/floodgate/version.Release=$RELEASE \ +-X github.com/codilime/floodgate/version.GoVersion=$GOLANG_VERSION \ +-X github.com/codilime/floodgate/version.GateVersion=$(echo ${GATE_API_BRANCH} | sed 's/release-//') \ +" + diff --git a/.cilibs/copy_binaries_for_later_use.sh b/.cilibs/copy_binaries_for_later_use.sh new file mode 100755 index 0000000..8e6f02f --- /dev/null +++ b/.cilibs/copy_binaries_for_later_use.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +echo "Copy binaries for later use" +mkdir -p /floodgate/bin +chmod 777 /floodgate/bin +cp /go/src/github.com/codilime/floodgate/floodgate /floodgate/bin/floodgate + diff --git a/.cilibs/examine_source_code_with_go_get.sh b/.cilibs/examine_source_code_with_go_get.sh new file mode 100755 index 0000000..a0456e2 --- /dev/null +++ b/.cilibs/examine_source_code_with_go_get.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e + +echo "Examine source code with go vet" +go vet -v ./... diff --git a/.cilibs/execute_go_tests.sh b/.cilibs/execute_go_tests.sh new file mode 100755 index 0000000..831f3ae --- /dev/null +++ b/.cilibs/execute_go_tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e + +echo "Execute go tests" +go test -v ./... -coverprofile cover.out diff --git a/.cilibs/generate_checksum.sh b/.cilibs/generate_checksum.sh new file mode 100755 index 0000000..32a4153 --- /dev/null +++ b/.cilibs/generate_checksum.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +GATE_API_BRANCH=release-1.20.x +BUILD_OS=linux +BUILD_ARCH=amd64 + + +while getopts "o:a:g:" opt; do + case ${opt} in + o) #Build OS + BUILD_OS=${OPTARG} + ;; + a) #Build arch + BUILD_ARCH=${OPTARG} + ;; + g) #Gate version + GATE_API_BRANCH=${OPTARG} + ;; + esac +done + +echo "Generate checksum" +cd /go/src/github.com/codilime/floodgate/ +cp floodgate floodgate-$GATE_API_BRANCH.$BUILD_OS.$BUILD_ARCH +sha1sum floodgate-$GATE_API_BRANCH.$BUILD_OS.$BUILD_ARCH > floodgate-$GATE_API_BRANCH.$BUILD_OS.$BUILD_ARCH.sha1sum + diff --git a/.cilibs/generate_swagger.sh b/.cilibs/generate_swagger.sh new file mode 100755 index 0000000..52583df --- /dev/null +++ b/.cilibs/generate_swagger.sh @@ -0,0 +1,8 @@ +#!/bin/bash -e + +GATE_API_BRANCH=$1 + +.cilibs/prepare_extra_directories.sh + +.cilibs/setup_swagger.sh $GATE_API_BRANCH + diff --git a/.cilibs/get_dependencies.sh b/.cilibs/get_dependencies.sh new file mode 100755 index 0000000..b6a6122 --- /dev/null +++ b/.cilibs/get_dependencies.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +echo "Get dependencies" +go mod download +go get -u golang.org/x/lint/golint diff --git a/.circleci/libs/install-and-run-spinnaker.sh b/.cilibs/install-and-run-spinnaker.sh similarity index 69% rename from .circleci/libs/install-and-run-spinnaker.sh rename to .cilibs/install-and-run-spinnaker.sh index d22373d..9f457d6 100755 --- a/.circleci/libs/install-and-run-spinnaker.sh +++ b/.cilibs/install-and-run-spinnaker.sh @@ -1,8 +1,12 @@ -#!/bin/bash -xe +#!/bin/bash -e EXEC_DIR=$(dirname "$0") HAL_VERSION=${HAL_VERSION:-1.35.0} +# Install packages +sudo apt update +sudo apt install -y jq + # Install Halyard curl -O https://raw.githubusercontent.com/spinnaker/halyard/master/install/debian/InstallHalyard.sh USERNAME=`whoami` @@ -10,7 +14,7 @@ sudo bash InstallHalyard.sh --version ${HAL_VERSION} --user $USERNAME -y hal -v # Create Kind cluster -kind create cluster --config="${EXEC_DIR}/kind-cluster-config.yaml" +kind create cluster --config="${EXEC_DIR}/templates/kind-cluster-config.yaml" kubectl config use-context kind-kind kubectl cluster-info @@ -22,12 +26,16 @@ GATE_PASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo '') hal -q config provider kubernetes enable CONTEXT=$(kubectl config current-context) hal -q config provider kubernetes account add my-k8s-v2-account --provider-version v2 --context $CONTEXT +## Configure account for inner kind communication +cp ~/.kube/config ~/.kube/kind +sed -i "s/server:\ .*/server:\ https:\/\/10.96.0.1:443/g" ~/.kube/kind +hal -q config provider kubernetes account add inner-kind --provider-version v2 --context $CONTEXT --kubeconfig-file ~/.kube/kind hal -q config deploy edit --type distributed --account-name my-k8s-v2-account ## Install minio kubectl create namespace spinnaker -sed -i 's/LoadBalancer/ClusterIP/g' "${EXEC_DIR}/minio-standalone.yaml" -kubectl -n spinnaker create -f "${EXEC_DIR}/minio-standalone.yaml" +sed -i 's/LoadBalancer/ClusterIP/g' "${EXEC_DIR}/templates/minio-standalone.yaml" +kubectl -n spinnaker create -f "${EXEC_DIR}/templates/minio-standalone.yaml" mkdir -p ~/.hal/default/profiles echo "spinnaker.s3.versioning: false" >> ~/.hal/default/profiles/front50-local.yml @@ -47,8 +55,8 @@ hal config security api edit --override-base-url='http://spinnaker/api/v1' echo 'window.spinnakerSettings.authEnabled = true;' > ~/.hal/default/profiles/settings-local.js mkdir -p ~/.hal/default/service-settings echo 'healthEndpoint: /api/v1/health' > ~/.hal/default/service-settings/gate.yml -sed -i "s/GATE_PASS/${GATE_PASS}/g" "${EXEC_DIR}/gate-local.yml" -cp "${EXEC_DIR}/gate-local.yml" ~/.hal/default/profiles/gate-local.yml +sed -i "s/GATE_PASS/${GATE_PASS}/g" "${EXEC_DIR}/templates/gate-local.yml" +cp "${EXEC_DIR}/templates/gate-local.yml" ~/.hal/default/profiles/gate-local.yml # Install Spinnaker hal -q deploy apply @@ -58,11 +66,11 @@ do done # Install Ingress controller -kubectl apply -f "${EXEC_DIR}/ingress-mandatory.yaml" -kubectl apply -f "${EXEC_DIR}/ingress-service-nodeport.yaml" +kubectl apply -f "${EXEC_DIR}/templates/ingress-mandatory.yaml" +kubectl apply -f "${EXEC_DIR}/templates/ingress-service-nodeport.yaml" kubectl patch deployments -n ingress-nginx nginx-ingress-controller -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx-ingress-controller","ports":[{"containerPort":80,"hostPort":80},{"containerPort":443,"hostPort":443}]}],"nodeSelector":{"ingress-ready":"true"},"tolerations":[{"key":"node-role.kubernetes.io/master","operator":"Equal","effect":"NoSchedule"}]}}}}' -kubectl -n spinnaker apply -f "${EXEC_DIR}/spinnaker-ingress.yaml" +kubectl -n spinnaker apply -f "${EXEC_DIR}/templates/spinnaker-ingress.yaml" # Generate Floodgate config file -sed -i "s/GATE_PASS/${GATE_PASS}/g" "${EXEC_DIR}/floodgate-config.yaml" -cp "${EXEC_DIR}/floodgate-config.yaml" ~/floodgate.yaml +sed -i "s/GATE_PASS/${GATE_PASS}/g" "${EXEC_DIR}/templates/floodgate-config.yaml" +cp "${EXEC_DIR}/templates/floodgate-config.yaml" ~/floodgate.yaml diff --git a/.cilibs/install_spinnaker_and_configure_floodgate.sh b/.cilibs/install_spinnaker_and_configure_floodgate.sh new file mode 100755 index 0000000..a253fcb --- /dev/null +++ b/.cilibs/install_spinnaker_and_configure_floodgate.sh @@ -0,0 +1,13 @@ +#!/bin/bash -e + +GATE_API_BRANCH=$1 + +echo Install Spinnaker and configure Floodgate +export NEED_SPINNAKER_VERSION=$( echo $GATE_API_BRANCH | egrep -o "[0-9]\.[0-9]+" ) +.cilibs/install-and-run-spinnaker.sh +until [ $( curl -w '%{http_code}' -o /dev/null http://spinnaker/api/v1 ) -eq 302 ] +do + echo "Waiting for Spinnaker" + sleep 10 +done + diff --git a/.cilibs/install_toolset.sh b/.cilibs/install_toolset.sh new file mode 100755 index 0000000..3561ae7 --- /dev/null +++ b/.cilibs/install_toolset.sh @@ -0,0 +1,8 @@ +#!/bin/bash -e + +curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(uname)-amd64 +chmod +x ./kind +sudo mv ./kind /usr/local/bin/ +curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl +chmod +x ./kubectl +sudo mv ./kubectl /usr/local/bin/ diff --git a/.cilibs/prepare_directories.sh b/.cilibs/prepare_directories.sh new file mode 100755 index 0000000..89a882b --- /dev/null +++ b/.cilibs/prepare_directories.sh @@ -0,0 +1,13 @@ +#!/bin/bash -e + +BUILD_OS=linux +BUILD_ARCH=amd64 + +sudo bash -c "source .cilibs/prepare_extra_directories.sh" +mkdir -p /floodgate/libs +mkdir -p /floodgate/resources +cp -r sponnet /floodgate/libs/ +cp -r examples /floodgate/resources/ +cp floodgate /floodgate/bin/ +chmod +x /floodgate/bin/floodgate + diff --git a/.cilibs/prepare_extra_directories.sh b/.cilibs/prepare_extra_directories.sh new file mode 100755 index 0000000..5148d25 --- /dev/null +++ b/.cilibs/prepare_extra_directories.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +echo "Prepare extra directories" +mkdir -p /floodgate/bin +chmod 777 -R /floodgate diff --git a/.cilibs/setup_swagger.sh b/.cilibs/setup_swagger.sh new file mode 100755 index 0000000..fc457ca --- /dev/null +++ b/.cilibs/setup_swagger.sh @@ -0,0 +1,23 @@ +#!/bin/bash -e +export TERM=${TERM:-dumb} #Needed because sudo is used in CircleCi +GATE_API_BRANCH=$1 + +echo "Setup swagger-codegen" +SWAGGER_VERSION=$(cat gateapi/.swagger-codegen/VERSION) +wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/${SWAGGER_VERSION}/swagger-codegen-cli-${SWAGGER_VERSION}.jar -O swagger-codegen-cli.jar +wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/${SWAGGER_VERSION}/swagger-codegen-cli-${SWAGGER_VERSION}.jar.sha1 -O swagger-codegen-cli.jar.sha1 +echo ' swagger-codegen-cli.jar' >> swagger-codegen-cli.jar.sha1 +sha1sum -c swagger-codegen-cli.jar.sha1 +mv swagger-codegen-cli.jar /floodgate/bin/ + +echo "Get gate code" +git clone https://github.com/spinnaker/gate.git -b ${GATE_API_BRANCH} /floodgate/gate + +echo "Generate swagger.json" +cd /floodgate/gate +./gradlew clean +./gradlew gate-web:test --tests *GenerateSwagger* --max-workers 2 +cat gate-web/swagger.json | json_pp > ./gate-swagger.json + +echo "Generate gateapi go code" +java -jar /floodgate/bin/swagger-codegen-cli.jar generate -l go -i /floodgate/gate/gate-swagger.json -o /floodgate/gateapi diff --git a/.cilibs/start_spinnaker.sh b/.cilibs/start_spinnaker.sh new file mode 100755 index 0000000..2e2adea --- /dev/null +++ b/.cilibs/start_spinnaker.sh @@ -0,0 +1,31 @@ +#!/bin/bash -e + +while getopts "o:a:g:e:" opt; do + case ${opt} in + o) #Build OS + BUILD_OS=${OPTARG} + ;; + a) #Build arch + BUILD_ARCH=${OPTARG} + ;; + g) #Gate version + GATE_VERSION=${OPTARG} + ;; + e) #Floodgate extra params + FLOODGATE_EXTRA_PARAMS=${OPTARG} + ;; + esac +done + + +.cilibs/prepare_directories.sh + +.cilibs/install_toolset.sh + +.cilibs/update_hosts.sh + +.cilibs/wait_for_dpkg.sh + +.cilibs/install_spinnaker_and_configure_floodgate.sh $GATE_API_BRANCH + +.cilibs/test_floodgate_against_running_spinnaker_instance.sh $FLOODGATE_EXTRA_PARAMS diff --git a/.circleci/libs/floodgate-config.yaml b/.cilibs/templates/floodgate-config.yaml similarity index 100% rename from .circleci/libs/floodgate-config.yaml rename to .cilibs/templates/floodgate-config.yaml diff --git a/.circleci/libs/gate-local.yml b/.cilibs/templates/gate-local.yml similarity index 100% rename from .circleci/libs/gate-local.yml rename to .cilibs/templates/gate-local.yml diff --git a/.circleci/libs/ingress-mandatory.yaml b/.cilibs/templates/ingress-mandatory.yaml similarity index 100% rename from .circleci/libs/ingress-mandatory.yaml rename to .cilibs/templates/ingress-mandatory.yaml diff --git a/.circleci/libs/ingress-service-nodeport.yaml b/.cilibs/templates/ingress-service-nodeport.yaml similarity index 100% rename from .circleci/libs/ingress-service-nodeport.yaml rename to .cilibs/templates/ingress-service-nodeport.yaml diff --git a/.circleci/libs/kind-cluster-config.yaml b/.cilibs/templates/kind-cluster-config.yaml similarity index 100% rename from .circleci/libs/kind-cluster-config.yaml rename to .cilibs/templates/kind-cluster-config.yaml diff --git a/.circleci/libs/minio-standalone.yaml b/.cilibs/templates/minio-standalone.yaml similarity index 100% rename from .circleci/libs/minio-standalone.yaml rename to .cilibs/templates/minio-standalone.yaml diff --git a/.circleci/libs/spinnaker-ingress.yaml b/.cilibs/templates/spinnaker-ingress.yaml similarity index 100% rename from .circleci/libs/spinnaker-ingress.yaml rename to .cilibs/templates/spinnaker-ingress.yaml diff --git a/.cilibs/test_floodgate_against_running_spinnaker_instance.sh b/.cilibs/test_floodgate_against_running_spinnaker_instance.sh new file mode 100755 index 0000000..c1eb28d --- /dev/null +++ b/.cilibs/test_floodgate_against_running_spinnaker_instance.sh @@ -0,0 +1,17 @@ +#!/bin/bash -e + +FLOODGATE_EXTRA_PARAMS=$1 + +echo Test Floodgate against running Spinnaker instance + +echo "Print version using version flag" +/floodgate/bin/floodgate --version +echo "Print version using version command" +/floodgate/bin/floodgate version +echo "Comare changes - clean Spinnaker" +/floodgate/bin/floodgate $FLOODGATE_EXTRA_PARAMS --config ~/floodgate.yaml compare && exit 1 || echo "Found changes" +echo "Apply local resources" +/floodgate/bin/floodgate $FLOODGATE_EXTRA_PARAMS --config ~/floodgate.yaml sync +echo "Compare changes - synced resources" +/floodgate/bin/floodgate $FLOODGATE_EXTRA_PARAMS --config ~/floodgate.yaml compare + diff --git a/.cilibs/trigger-pipelines.sh b/.cilibs/trigger-pipelines.sh new file mode 100755 index 0000000..d7686ea --- /dev/null +++ b/.cilibs/trigger-pipelines.sh @@ -0,0 +1,53 @@ +#!/bin/bash -e +for PIPELINE in $@ ; do + + PASS=`cat ~/.hal/default/profiles/gate-local.yml | grep password` + PASS=${PASS#*:\ } + USER=`cat ~/.hal/default/profiles/gate-local.yml | grep name` + USER=${USER#*:\ } + ALL_APPS=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications" | jq -r .[].name` + MAX_ATTEMPTS=20 + + echo "Triggering pipeline with source $PIPELINE" + EVENT_ID=`curl -s -X POST -H "content-type: application/json" -d "{ }" http://spinnaker/api/v1/webhooks/webhook/$PIPELINE | jq -r .eventId` + echo "eventId: $EVENT_ID" + + for APP in $ALL_APPS ; do + PIPELINE_NAME=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications/$APP/executions/search?triggerTypes=webhook&eventId=$EVENT_ID" | jq -r .[].name` + ATTEMPTS=0 + + while [[ $PIPELINE_NAME != "" ]] && [ $ATTEMPTS -lt $MAX_ATTEMPTS ] ; do + echo "Checking pipeline $PIPELINE_NAME status" + STATUS=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications/$APP/executions/search?triggerTypes=webhook&eventId=$EVENT_ID" | jq -r .[].status` + + case $STATUS in + + "NOT_STARTED") + echo "Waiting for pipeline $PIPELINE_NAME to start" + sleep 3 + ;; + + "RUNNING") + echo "Waiting for pipeline $PIPELINE_NAME to finish" + sleep 3 + ;; + + "SUCCEEDED") + echo "$Pipeline PIPELINE_NAME succeded" + break + ;; + + *) + echo "Pipeline $PIPELINE_NAME exited with status $STATUS" + exit 1 + ;; + esac + ((++ATTEMPTS)) + done + + if [ $ATTEMPTS -ge $MAX_ATTEMPTS ] ; then + echo "Check timed out" + exit 1 + fi + done +done diff --git a/.cilibs/update_hosts.sh b/.cilibs/update_hosts.sh new file mode 100755 index 0000000..9cc58b2 --- /dev/null +++ b/.cilibs/update_hosts.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +echo "Update /etc/hosts" +sudo bash -c 'echo "127.1.2.3 spinnaker" >> /etc/hosts' + diff --git a/.cilibs/wait_for_dpkg.sh b/.cilibs/wait_for_dpkg.sh new file mode 100755 index 0000000..6e77cb4 --- /dev/null +++ b/.cilibs/wait_for_dpkg.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +sleep 10 +while systemctl status apt-daily >/dev/null || systemctl status apt-daily-upgrade >/dev/null || sudo fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock; do +echo "waiting 30s for dpkg locks..." +sleep 30 +done diff --git a/.circleci/config.yml b/.circleci/config.yml index deb6e6b..8a8f930 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,25 +24,14 @@ commands: steps: - run: name: Install tools - command: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv ./kind /usr/local/bin/ - curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl - chmod +x ./kubectl - sudo mv ./kubectl /usr/local/bin/ + command: .cilibs/install_toolset.sh wait_for_dpkg: description: "Wait for packaging operations to finish" steps: - run: name: Wait for packaging operations to finish - command: | - sleep 10 - while systemctl status apt-daily >/dev/null || systemctl status apt-daily-upgrade >/dev/null || sudo fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock; do - echo "waiting 30s for dpkg locks..." - sleep 30 - done + command: .cilibs/wait_for_dpkg.sh jobs: generate_swagger: @@ -53,32 +42,10 @@ jobs: - checkout - run: name: Prepare extra directories - command: | - sudo mkdir /floodgate - sudo chmod 777 /floodgate - mkdir /floodgate/bin + command: sudo .cilibs/prepare_extra_directories.sh - run: - name: Setup swagger-codegen - command: | - SWAGGER_VERSION=$(cat gateapi/.swagger-codegen/VERSION) - wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/${SWAGGER_VERSION}/swagger-codegen-cli-${SWAGGER_VERSION}.jar -O swagger-codegen-cli.jar - wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/${SWAGGER_VERSION}/swagger-codegen-cli-${SWAGGER_VERSION}.jar.sha1 -O swagger-codegen-cli.jar.sha1 - echo ' swagger-codegen-cli.jar' >> swagger-codegen-cli.jar.sha1 - sha1sum -c swagger-codegen-cli.jar.sha1 - mv swagger-codegen-cli.jar /floodgate/bin/ - - run: - name: Get gate code - command: git clone https://github.com/spinnaker/gate.git -b << parameters.gate_api_branch >> /floodgate/gate - - run: - name: Generate swagger.json - command: | - cd /floodgate/gate - ./gradlew clean - ./gradlew gate-web:test --tests *GenerateSwagger* --max-workers 2 - cat gate-web/swagger.json | json_pp > ./gate-swagger.json - - run: - name: Generate gateapi go code - command: java -jar /floodgate/bin/swagger-codegen-cli.jar generate -l go -i /floodgate/gate/gate-swagger.json -o /floodgate/gateapi + name: Setup swagger + command: .cilibs/setup_swagger.sh << parameters.gate_api_branch >> - persist_to_workspace: root: /floodgate paths: @@ -117,77 +84,30 @@ jobs: at: ./ - run: name: Get dependencies - command: | - go mod download - go get -u golang.org/x/lint/golint + command: .cilibs/get_dependencies.sh - run: name: Examine source code with go vet - command: go vet -v ./... + command: .cilibs/examine_source_code_with_go_get.sh - run: name: Execute go tests - command: go test -v ./... -coverprofile cover.out + command: .cilibs/execute_go_tests.sh - run: name: Compile code - command: | - if [ -z "$CIRCLE_BRANCH" ] - then - export RELEASE=$(echo $CIRCLE_TAG | sed 's/^v[0-9]\+\.[0-9]\+\.[0-9]\+-\?//') - else - export RELEASE=$CIRCLE_BRANCH - fi - env GOOS=<< parameters.build_os >> GOARCH=<< parameters.build_arch >> go build -ldflags \ - "-X github.com/codilime/floodgate/version.GitCommit=$CIRCLE_SHA1 \ - -X github.com/codilime/floodgate/version.BuiltDate=$(date +%Y-%m-%d_%H:%M:%S) \ - -X github.com/codilime/floodgate/version.Release=$RELEASE \ - -X github.com/codilime/floodgate/version.GoVersion=$GOLANG_VERSION \ - -X github.com/codilime/floodgate/version.GateVersion=$(echo '<< parameters.gate_api_branch >>' | sed 's/release-//') \ - " + command: .cilibs/compile_code.sh -o << parameters.build_os >> -a << parameters.build_arch >> -g << parameters.gate_api_branch >> - run: name: Calculate code coverage environment: REQUIREDCODECOVERAGE: 60 - command: | - go tool cover -func cover.out | tee codecoverage.txt - CURRENTCODECOVERAGE=$(grep 'total:' codecoverage.txt | awk '{print substr($3, 1, length($3)-1)}') - echo "Send coverity report to SeriesCI" - if [[ "<< parameters.send_coverity >>" == "send" ]] - then - curl \ - --header "Authorization: Token ${SERIESCI_TOKEN}" \ - --header "Content-Type: application/json" \ - --data "{\"value\":\"${CURRENTCODECOVERAGE} %\",\"sha\":\"${CIRCLE_SHA1}\"}" \ - https://seriesci.com/api/codilime/floodgate/coverage/one - else - echo "Skipping" - fi - if [ ${CURRENTCODECOVERAGE%.*} -lt ${REQUIREDCODECOVERAGE} ] - then - echo "Not enough code coverage!" - echo "Current code coverage: ${CURRENTCODECOVERAGE}%" - echo "Required code coverage: ${REQUIREDCODECOVERAGE}%" - exit 1 - else - echo "Code coverage is at least ${REQUIREDCODECOVERAGE}% : OK" - fi + command: .cilibs/calculate_code_coverage.sh << parameters.send_coverity >> - run: name: Check linting - command: | - for GOSRCFILE in $( find . -type f -name '*.go' -not -path './gateapi/*') - do - golint -set_exit_status $GOSRCFILE - done + command: .cilibs/check_linting.sh - run: name: Copy binaries for later use - command: | - sudo mkdir -p /floodgate/bin - sudo chmod 777 /floodgate/bin - cp /go/src/github.com/codilime/floodgate/floodgate /floodgate/bin/floodgate + command: sudo .cilibs/copy_binaries_for_later_use.sh - run: name: Generate checksum - command: | - cd /go/src/github.com/codilime/floodgate/ - cp floodgate floodgate-<< parameters.gate_api_branch >>.<< parameters.build_os >>.<< parameters.build_arch >> - sha1sum floodgate-<< parameters.gate_api_branch >>.<< parameters.build_os >>.<< parameters.build_arch >> > floodgate-<< parameters.gate_api_branch >>.<< parameters.build_os >>.<< parameters.build_arch >>.sha1sum + command: .cilibs/generate_checksum.sh -o << parameters.build_os >> -a << parameters.build_arch >> -g << parameters.gate_api_branch >> - persist_to_workspace: root: /floodgate/bin paths: @@ -216,44 +136,18 @@ jobs: at: ./ - run: name: Prepare directories - command: | - sudo mkdir /floodgate - sudo chmod 777 /floodgate - mkdir -p /floodgate/bin - mkdir -p /floodgate/libs - mkdir -p /floodgate/resources - cp -r sponnet /floodgate/libs/ - cp -r examples /floodgate/resources/ - cp floodgate /floodgate/bin/ - chmod +x /floodgate/bin/floodgate + command: .cilibs/prepare_directories.sh - install_toolset - run: name: Update /etc/hosts - command: sudo bash -c 'echo "127.1.2.3 spinnaker" >> /etc/hosts' + command: .cilibs/update_hosts.sh - wait_for_dpkg - run: name: Install Spinnaker and configure Floodgate - command: | - export NEED_SPINNAKER_VERSION=$( echo << parameters.gate_api_branch >> | egrep -o "[0-9]\.[0-9]+" ) - .circleci/libs/install-and-run-spinnaker.sh - until [ $( curl -w '%{http_code}' -o /dev/null http://spinnaker/api/v1 ) -eq 302 ] - do - echo "Waiting for Spinnaker" - sleep 10 - done + command: .cilibs/install_spinnaker_and_configure_floodgate.sh << parameters.gate_api_branch >> - run: name: Test Floodgate against running Spinnaker instance - command: | - echo "Print version using version flag" - /floodgate/bin/floodgate --version - echo "Print version using version command" - /floodgate/bin/floodgate version - echo "Comare changes - clean Spinnaker" - /floodgate/bin/floodgate << parameters.floodgate_extra_params >> --config ~/floodgate.yaml compare && exit 1 || echo "Found changes" - echo "Apply local resources" - /floodgate/bin/floodgate << parameters.floodgate_extra_params >> --config ~/floodgate.yaml sync - echo "Compare changes - synced resources" - /floodgate/bin/floodgate << parameters.floodgate_extra_params >> --config ~/floodgate.yaml compare + command: .cilibs/test_floodgate_against_running_spinnaker_instance.sh << parameters.floodgate_extra_params >> workflows: periodic: diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..21604d3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,40 @@ +dist: xenial +language: go +go: + - 1.14.1 +env: | + REALESE_BRANCHES="release-v[0-9]+\.[0-9]+\.x" + RELEASE_TAGS="v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?" + BUILD_OS="$([ $TRAVIS_EVENT_TYPE == cron ] || [[ $TRAVIS_BRANCH =~ $RELEASE_BRANCHES ]] || [[ $TRAVIS_TAG =~ $RELEASE_TAGS ]] && echo darwin) linux" + BUILD_ARCH=amd64 + GATE_API_BRANCH=release-1.20.x + SEND_COVERITY=send +services: + - docker + +before_script: + - docker pull openjdk:11.0.3-stretch + - docker run -u root -w /workspace -v `pwd`:/workspace --entrypoint /workspace/.cilibs/generate_swagger.sh --rm openjdk:11.0.3-stretch release-1.20.x + +script: | + docker pull golang:1.14.1-stretch + for o in $BUILD_OS + do + for a in $BUILD_ARCH + do + docker run -e SERIESCI_TOKEN=$SERIESCI_TOKEN \ + -e TRAVIS_COMMIT=$TRAVIS_COMMIT \ + -u root \ + -w /go/src/github.com/codilime/floodgate \ + -v `pwd`:/go/src/github.com/codilime/floodgate \ + --entrypoint /go/src/github.com/codilime/floodgate/.cilibs/build.sh \ + --rm golang:1.14.1-stretch \ + -g $GATE_API_BRANCH -o $o -a $a -c $SEND_COVERITY + done + done + sudo chown $SUDO_USER:$SUDO_USER -R . + .cilibs/start_spinnaker.sh -a `echo $BUILD_ARCH | cut -d" " -f1` \ + -o `echo $BUILD_OS | cut -d" " -f1` \ + -g $GATE_API_BRANCH \ + -e $FLOODGATE_EXTRA_PARAMS +