Created
December 17, 2017 19:10
-
-
Save jugatsu/3843d83bc707f4d6118ade4c2c34bbc6 to your computer and use it in GitHub Desktop.
gitlab-reddit-deploy-ci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: alpine:latest | |
stages: | |
- test | |
- staging | |
- production | |
test: | |
stage: test | |
script: | |
- exit 0 | |
only: | |
- triggers | |
- branches | |
staging: | |
stage: staging | |
script: | |
- install_dependencies | |
- ensure_namespace | |
- install_tiller | |
- deploy | |
variables: | |
KUBE_NAMESPACE: staging | |
environment: | |
name: staging | |
url: http://staging | |
only: | |
refs: | |
- master | |
kubernetes: active | |
except: | |
- triggers | |
production: | |
stage: production | |
script: | |
- install_dependencies | |
- ensure_namespace | |
- install_tiller | |
- deploy | |
variables: | |
KUBE_NAMESPACE: production | |
environment: | |
name: production | |
url: http://production | |
only: | |
refs: | |
- master | |
kubernetes: active | |
.auto_devops: &auto_devops | | |
# Auto DevOps variables and functions | |
[[ "$TRACE" ]] && set -x | |
export CI_REGISTRY="index.docker.io" | |
export CI_APPLICATION_REPOSITORY=$CI_REGISTRY/$CI_PROJECT_PATH | |
export CI_APPLICATION_TAG=$CI_COMMIT_REF_SLUG | |
export CI_CONTAINER_NAME=ci_job_build_${CI_JOB_ID} | |
export TILLER_NAMESPACE="kube-system" | |
function deploy() { | |
echo $KUBE_NAMESPACE | |
track="${1-stable}" | |
name="$CI_ENVIRONMENT_SLUG" | |
helm dep build reddit | |
# for microservice in $(helm dep ls | grep "file://" | awk '{print $1}') ; do | |
# SET_VERSION="$SET_VERSION \ --set $microservice.image.tag='$(curl http://gitlab-gitlab/$CI_PROJECT_NAMESPACE/ui/raw/master/VERSION)' " | |
helm upgrade --install \ | |
--wait \ | |
--set ui.ingress.host="$host" \ | |
--set ui.image.tag="$(curl http://gitlab-gitlab/$CI_PROJECT_NAMESPACE/ui/raw/master/VERSION)" \ | |
--set post.image.tag="$(curl http://gitlab-gitlab/$CI_PROJECT_NAMESPACE/post/raw/master/VERSION)" \ | |
--set comment.image.tag="$(curl http://gitlab-gitlab/$CI_PROJECT_NAMESPACE/comment/raw/master/VERSION)" \ | |
--namespace="$KUBE_NAMESPACE" \ | |
--version="$CI_PIPELINE_ID-$CI_JOB_ID" \ | |
"$name" \ | |
} | |
function install_dependencies() { | |
apk add -U openssl curl tar gzip bash ca-certificates git | |
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub | |
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.23-r3/glibc-2.23-r3.apk | |
apk add glibc-2.23-r3.apk | |
rm glibc-2.23-r3.apk | |
curl https://kubernetes-helm.storage.googleapis.com/helm-v2.7.2-linux-amd64.tar.gz | tar zx | |
mv linux-amd64/helm /usr/bin/ | |
helm version --client | |
curl -L -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl | |
chmod +x /usr/bin/kubectl | |
kubectl version --client | |
} | |
function ensure_namespace() { | |
kubectl describe namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE" | |
} | |
function install_tiller() { | |
echo "Checking Tiller..." | |
helm init --upgrade | |
kubectl rollout status -n "$TILLER_NAMESPACE" -w "deployment/tiller-deploy" | |
if ! helm version --debug; then | |
echo "Failed to init Tiller." | |
return 1 | |
fi | |
echo "" | |
} | |
function delete() { | |
track="${1-stable}" | |
name="$CI_ENVIRONMENT_SLUG" | |
helm delete "$name" || true | |
} | |
before_script: | |
- *auto_devops |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment