What is travis you already know from the previous post. But what the kubernetes is?
According to the docs:
"Kubernetes is a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available"
Get the long things shorter: kubernetes is the way to upload applications to google cloud, and also it can do lots of other things.
My Goal
So, my goal was: to get things published to cloud after all the testing stuff was done. (or after the travis finished)
Google cloud builder - another google cloud tool can be activated in response to push to some branch or in response to publishing some tag
After Success Hook
Fortunately I found that travis has a after_success hook which I can utilise for my scenario:
language: node_js
node_js:
- "9"
sudo: required
branches:
except:
- /^v.*\_.*/
dist: trusty
addons:
chrome: stable
cache:
directories:
- $HOME/.npm
env:
matrix:
- MONGODB=3.6.6
before_install:
- export GITHUBKEY=put-here-your-github-auth-token-key
install:
...
...
script:
# run build script specified in package.json
- npm run tslint
- npm run test
- npm run build
after_success:
# CREATE GIT TAG
- bash ./scripts/push_tag.sh
And here is the bash script code:
#!/bin/sh
git config --global user.email "koko@moko.com"
git config --global user.name "koko"
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
# should start cloud build only on prod test dev branches
if [[ "${TRAVIS_BRANCH}" = prod || "${TRAVIS_BRANCH}" = test || "${TRAVIS_BRANCH}" = dev ]]; then
export GIT_TAG="v${PACKAGE_VERSION}_${TRAVIS_BUILD_NUMBER}"
echo "tag is ${GIT_TAG}"
git tag $GIT_TAG -a -m "Generated tag from TravisCI build $TRAVIS_BUILD_NUMBER [ci skip]" $TRAVIS_BRANCH
git push --tags https://$GITHUBKEY@github.com/oyrname/yourrepo
fi
Notice, that travis will react to the tag pushed by himself unless except entry configured properly:
branches:
except:
- /^v.*\_.*/
No comments:
Post a Comment