diff --git a/.travis.yml b/.travis.yml index 670ddec..de11351 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,9 @@ deploy: tags: true all_branches: true + - provider: script + skip_cleanup: true + script: bash -ex ./scripts/deploy_on_k8s.sh + on: + tags: true + all_branches: true diff --git a/scripts/deploy_on_k8s.sh b/scripts/deploy_on_k8s.sh new file mode 100644 index 0000000..36e46ce --- /dev/null +++ b/scripts/deploy_on_k8s.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +if [ -z "${TRAVIS_TAG}" ]; then + echo "Variable \$TRAVIS_TAG not set or empty. Skiping deploying new version on k8s" + exit 0 +fi +if ! [[ "${TRAVIS_TAG}" =~ ^v[0-9]\.[0-9]\.[0-9]$ ]]; then + echo "Variable \$TRAVIS_TAG does not match with vx.y.z format. Skiping deploying new version on k8s" + exit 0 +fi + +curl -L https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -o /tmp/kubectl +chmod +x /tmp/kubectl + +mkdir -p ~/.kube +cat< ~/.kube/config +apiVersion: v1 +clusters: +- cluster: + certificate-authority-data: ${KUBE_CERTIFICATE_AUTHORITY_DATA} + server: ${KUBE_SERVER} + name: cluster +contexts: +- context: + cluster: cluster + namespace: ${KUBE_NAMESPACE} + user: ${KUBE_USER} + name: cluster +current-context: cluster +kind: Config +preferences: {} +users: +- name: ${KUBE_USER} + user: + client-key-data: ${KUBE_CLIENT_KEY_DATA} + token: ${KUBE_TOKEN} +EOF + +# Patch deployed versions in k8s cluster +/tmp/kubectl patch deployment marketplace-client-commons -p\ + "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"marketplace-commons\",\"image\":\"oceanprotocol/commons_client:${TRAVIS_TAG}\"}]}}}}" + +/tmp/kubectl patch deployment marketplace-server-commons -p\ + "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"marketplac-server-commons\",\"image\":\"oceanprotocol/commons_server:${TRAVIS_TAG}\"}]}}}}"