Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travis CI configuration #114

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .cilibs/build.sh
Original file line number Diff line number Diff line change
@@ -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}

31 changes: 31 additions & 0 deletions .cilibs/calculate_code_coverage.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions .cilibs/check_linting.sh
Original file line number Diff line number Diff line change
@@ -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

36 changes: 36 additions & 0 deletions .cilibs/compile_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash -e

GATE_VERSION=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_VERSION=${OPTARG}
;;
esac
done

echo "Compile code"
if [ -z "$TRAVIS_BRANCH" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what about "$CIRCLECI_BRANCH" part ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was messed up, should work now.

then
export RELEASE=$(echo $CIRCLE_TAG | sed 's/^v[0-9]\+\.[0-9]\+\.[0-9]\+-\?//')
else
export RELEASE=$CIRCLE_BRANCH
fi
rparadowski marked this conversation as resolved.
Show resolved Hide resolved
env GOOS=${BUILD_OS} GOARCH=${BUILD_ARCH} go build -ldflags \
"-X github.com/codilime/floodgate/version.GitCommit=$TRAVIS_COMMIT \
-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-//') \
"

7 changes: 7 additions & 0 deletions .cilibs/copy_binaries_for_later_use.sh
Original file line number Diff line number Diff line change
@@ -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

4 changes: 4 additions & 0 deletions .cilibs/examine_source_code_with_go_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

echo "Examine source code with go vet"
go vet -v ./...
4 changes: 4 additions & 0 deletions .cilibs/execute_go_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

echo "Execute go tests"
go test -v ./... -coverprofile cover.out
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions .cilibs/generate_checksum.sh
Original file line number Diff line number Diff line change
@@ -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

6 changes: 6 additions & 0 deletions .cilibs/generate_gateapi_go_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

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


14 changes: 14 additions & 0 deletions .cilibs/generate_swagger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -e

GATE_API_BRANCH=$1

.cilibs/prepare_extra_directories.sh

.cilibs/setup_swagger_codegen.sh

.cilibs/get_gate_code.sh $GATE_API_BRANCH

.cilibs/generate_swagger_json.sh

.cilibs/generate_gateapi_go_code.sh

7 changes: 7 additions & 0 deletions .cilibs/generate_swagger_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -e

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
5 changes: 5 additions & 0 deletions .cilibs/get_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e

echo "Get dependencies"
go mod download
go get -u golang.org/x/lint/golint
7 changes: 7 additions & 0 deletions .cilibs/get_gate_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -e

GATE_API_BRANCH=$1

echo "Get gate code"
git clone https://github.com/spinnaker/gate.git -b ${GATE_API_BRANCH} /floodgate/gate

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -22,6 +26,10 @@ 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
Expand Down
13 changes: 13 additions & 0 deletions .cilibs/install_spinnaker_and_configure_floodgate.sh
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions .cilibs/install_toolset.sh
Original file line number Diff line number Diff line change
@@ -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/
File renamed without changes.
16 changes: 16 additions & 0 deletions .cilibs/prepare_directories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -e

BUILD_OS=linux
BUILD_ARCH=amd64

echo "Prepare directories"
sudo mkdir /floodgate
rparadowski marked this conversation as resolved.
Show resolved Hide resolved
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

6 changes: 6 additions & 0 deletions .cilibs/prepare_extra_directories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

echo "Prepare extra directories"
mkdir /floodgate
chmod 777 /floodgate
mkdir /floodgate/bin
9 changes: 9 additions & 0 deletions .cilibs/setup_swagger_codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e

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/
File renamed without changes.
31 changes: 31 additions & 0 deletions .cilibs/start_spinnaker.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions .cilibs/test_floodgate_against_running_spinnaker_instance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -e

FLOODGATE_EXTRA_PARAMS=$1

echo Test Floodgate against running Spinnaker instance
/floodgate/bin/floodgate --version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can add some info about what is happening before executing this commands?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added printing as was in .circleci/config.yml

/floodgate/bin/floodgate version
/floodgate/bin/floodgate $FLOODGATE_EXTRA_PARAMS --config ~/floodgate.yaml compare && exit 1 || echo "Found changes"
/floodgate/bin/floodgate $FLOODGATE_EXTRA_PARAMS --config ~/floodgate.yaml sync
/floodgate/bin/floodgate $FLOODGATE_EXTRA_PARAMS --config ~/floodgate.yaml compare

53 changes: 53 additions & 0 deletions .cilibs/trigger-pipelines.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .cilibs/update_hosts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e

echo "Update /etc/hosts"
sudo bash -c 'echo "127.1.2.3 spinnaker" >> /etc/hosts'

Loading