Skip to content

Commit

Permalink
Merge pull request #392 from cncf/Fix_Travis_bugs_#384
Browse files Browse the repository at this point in the history
Add support for using Packet.net for executing CI Jobs. #384
  • Loading branch information
wvwatson authored Sep 9, 2020
2 parents e9aea3f + 806153a commit bddfcd6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
63 changes: 45 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
- stage: K8s
before_script:
- |
if [ -z "$KUBECONFIG" ]; then
if [ -z "${SSH_KEY+x}" ]; then
echo "SSH Key not found, using Travis Runner"
# Download and install go
wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
tar -xvf go1.13.linux-amd64.tar.gz
Expand All @@ -21,29 +22,55 @@ jobs:
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
# Download and install KinD
GO111MODULE=on go get sigs.k8s.io/kind
# Download and install Crystal
sudo apt update && sudo apt install -y libevent-dev
wget https://github.com/crystal-lang/crystal/releases/download/0.35.1/crystal-0.35.1-1-linux-x86_64.tar.gz
tar -xvf crystal-*.tar.gz
export PATH=$(pwd)/crystal-0.35.1-1/bin:$PATH
crystal version
# Create a new Kubernetes cluster using KinD
kind create cluster
# Download and install kubectl
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/
# Run Crystal Spec
git fetch --tags
shards install
crystal spec -v || travis_terminate 1;
else
# Write Kubeconfig
echo "$KUBECONFIG" | base64 -d | tee ./kubeconfig >/dev/null
export KUBECONFIG=$(pwd)/kubeconfig
echo "SSH Key found, using Packet Runner"
base64 -d <<< $SSH_KEY > ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa
touch $(pwd)/.github-env
cat <<< "export GITHUB_USER=$GITHUB_USER" > $(pwd)/.github-env
cat <<< "export GITHUB_TOKEN=$GITHUB_TOKEN" >> $(pwd)/.github-env
export TIME=$(date +%s)$RANDOM
# Install CNF-Conformance
scp -o StrictHostKeyChecking=no -rp $(pwd) root@$SSH_HOST:/tmp/$TIME
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST "cd /tmp/$TIME ; git fetch --tags" || travis_terminate 1
# Download and install go
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz || travis_terminate 1
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST tar -xvf go1.13.linux-amd64.tar.gz || travis_terminate 1
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST mv go /tmp/$TIME/go || travis_terminate 1
# Download and install KinD
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST GOROOT=/tmp/$TIME/go GOPATH=\$HOME/go PATH=\$GOPATH/bin:\$GOROOT/bin:\$PATH GO111MODULE=on go get sigs.k8s.io/kind || travis_terminate 1
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST GOROOT=/tmp/$TIME/go GOPATH=\$HOME/go PATH=\$GOPATH/bin:\$GOROOT/bin:\$PATH kind create cluster --kubeconfig /tmp/$TIME/kubeconfig --name $TIME || travis_terminate 1
# Setup ephemeral dev env
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST "cd /tmp/$TIME ; docker run --rm -it -v \$(pwd):/workspace -w /workspace crystallang/crystal:0.35.1-alpine shards install" || travis_terminate 1
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST "cd /tmp/$TIME ; docker run --rm -it -v \$(pwd):/workspace -w /workspace crystallang/crystal:0.35.1-alpine crystal build tools/ephemeral_env/ephemeral_env.cr --release --static --link-flags '-lxml2 -llzma'" || travis_terminate 1
cat <<< "/tmp/$TIME/ephemeral_env command alias \$@" > ./crystal
chmod +x ./crystal
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST mkdir -p /tmp/$TIME/crystal_dir || travis_terminate 1
scp -o StrictHostKeyChecking=no $(pwd)/crystal root@$SSH_HOST:/tmp/$TIME/crystal_dir/crystal
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST "cd /tmp/$TIME/ ; \$(pwd)/ephemeral_env setup -b \$(pwd)/ephemeral_env" || travis_terminate 1
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST "cd /tmp/$TIME/ ; source .github-env ; \$(pwd)/ephemeral_env create_env -n $TIME -k /tmp/$TIME/kubeconfig" || travis_terminate 1
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST PATH=/tmp/$TIME/crystal_dir:\$PATH CRYSTAL_DEV_ENV=$TIME crystal version || travis_terminate 1
ssh -o StrictHostKeyChecking=no -t root@$SSH_HOST "export PATH=/tmp/$TIME/crystal_dir:\$PATH CRYSTAL_DEV_ENV=$TIME ; cd /tmp/$TIME ; crystal spec -v" || travis_terminate 1
fi
# Download and install Crystal
- sudo apt update && sudo apt install -y libevent-dev
- wget https://github.com/crystal-lang/crystal/releases/download/0.35.1/crystal-0.35.1-1-linux-x86_64.tar.gz
- tar -xvf crystal-*.tar.gz
- export PATH=$(pwd)/crystal-0.35.1-1/bin:$PATH
- crystal version
# Download and install kubectl
- 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/
# It's possible to download and install KinD using curl, similar as for kubectl
# This is useful in cases when Go toolchain isn't available or you prefer running stable version
# Binaries for KinD are available on GitHub Releases: https://github.com/kubernetes-sigs/kind/releases
# - curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/0.0.1/kind-linux-amd64 && chmod +x kind && sudo mv kind /usr/local/bin/
script:
- shards install
- crystal spec -v || travis_terminate 1;
- docker pull crystallang/crystal:0.35.1-alpine
- docker run --rm -it -v $PWD:/workspace -w /workspace crystallang/crystal:0.35.1-alpine shards install
- docker run --rm -it -v $PWD:/workspace -w /workspace crystallang/crystal:0.35.1-alpine crystal build src/cnf-conformance.cr --release --static --link-flags "-lxml2 -llzma"
- |
if [ -z "${GITHUB_USER+x}" ] || [ -z "${GITHUB_TOKEN+x}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion tools/ephemeral_env/ephemeral_env.cr
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ elsif ARGV[0]? && ARGV[0] == "create_env"
puts "Required argument missing [-n, --name]"
else
puts "Creating ENV For: \n Name: #{env_name} \n Kubeconfig: #{kubeconfig}"
`docker run --name #{env_name} -d -v $(pwd):/cnf-conformance -v #{kubeconfig}:/root/.kube/config -ti cnf-test /bin/sleep infinity`
`docker run --name #{env_name} --network host -d -e GITHUB_USER=$GITHUB_USER -e GITHUB_TOKEN=$GITHUB_TOKEN -v $(pwd):/cnf-conformance -v #{kubeconfig}:/root/.kube/config -ti cnf-test /bin/sleep infinity`
puts `docker ps -f name=#{env_name}`
end

Expand Down

0 comments on commit bddfcd6

Please sign in to comment.