Merge pull request #263 from fpco/production-deployment

review-apps: Update gitlab-ci.yml to deploy helm production chart
This commit is contained in:
Deni Bertovic 2019-03-17 17:40:27 +01:00 committed by GitHub
commit 3f5c5e8647
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 53 deletions

View File

@ -13,8 +13,7 @@ stages:
variables:
STACK_ROOT: "${CI_PROJECT_DIR}/.stack-root"
#DEPLOYMENT_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
DEPLOYMENT_IMAGE: "registry.gitlab.fpcomplete.com/fpco-mirrors/stackage-server:master_4296"
DEPLOYMENT_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
DEPLOYMENT_NAME: "stackage-server-prod"
HOOGLE_DEPLOYMENT_NAME: "stackage-server-hoogle-prod"
CRON_DEPLOYMENT_NAME: "stackage-server-cron-prod"
@ -30,36 +29,30 @@ variables:
kubectl config set-cluster cluster --server="$KUBE_URL" --certificate-authority="$HOME/ca.pem" &&
kubectl config set-credentials cluster --token="$KUBE_TOKEN" && kubectl config set-context cluster --cluster=cluster --user=cluster --namespace="$KUBE_NAMESPACE" &&
kubectl config use-context cluster
- &KUBEAPPLY
kubectl apply -f <(envsubst <etc/kube/service_template.yaml) &&
kubectl apply -f <(envsubst <etc/kube/hoogle_service_template.yaml) &&
kubectl apply -f <(envsubst <etc/kube/deployment_template.yaml) &&
kubectl apply -f <(envsubst <etc/kube/cron_deployment_template.yaml) &&
kubectl apply -f <(envsubst <etc/kube/hoogle_deployment_template.yaml)
- &HELMUPGRADE
helm --tiller-namespace ${KUBE_NAMESPACE} upgrade -i "${DEPLOYMENT_NAME}" etc/helm --set name="${DEPLOYMENT_NAME}" --set app="${DEPLOYMENT_APP}" --set hoogleName="${HOOGLE_DEPLOYMENT_NAME}" --set hoogleApp="${HOOGLE_DEPLOYMENT_APP}" --set cronName="${CRON_DEPLOYMENT_NAME}" --set cronApp="${HOOGLE_DEPLOYMENT_APP}" --set image.image="${DEPLOYMENT_IMAGE}" --values etc/helm/values/$CI_ENVIRONMENT_NAME.yaml --namespace ${KUBE_NAMESPACE}
helm --tiller-namespace ${KUBE_NAMESPACE} upgrade --install "${DEPLOYMENT_NAME}" etc/helm --set name="${DEPLOYMENT_NAME}" --set app="${DEPLOYMENT_APP}" --set hoogleName="${HOOGLE_DEPLOYMENT_NAME}" --set hoogleApp="${HOOGLE_DEPLOYMENT_APP}" --set cronName="${CRON_DEPLOYMENT_NAME}" --set cronApp="${HOOGLE_DEPLOYMENT_APP}" --set image.image="${DEPLOYMENT_IMAGE}" --values etc/helm/values/$CI_ENVIRONMENT_NAME.yaml --namespace ${KUBE_NAMESPACE}
- &HELMCHECK
helm --tiller-namespace ${KUBE_NAMESPACE} ls &&
helm --tiller-namespace ${KUBE_NAMESPACE} status "${DEPLOYMENT_NAME}"
#build:
# stage: build
# script:
# # Clear *_TOKEN variables during code build so that compile-time code can't access them
# - apt-get update && apt-get install -y --no-install-recommends libpq-dev git rsync
# - CI_BUILD_TOKEN="" KUBE_TOKEN="" PROD_KUBE_TOKEN="" PROD_DOCKER_PASSWORD="" etc/scripts/stage_docker.sh --install-ghc --test
# - docker build -t "${DEPLOYMENT_IMAGE}" etc/docker
# - docker login -u gitlab-ci-token -p "${CI_BUILD_TOKEN}" "${CI_REGISTRY}"
# - docker push "${DEPLOYMENT_IMAGE}"
# - |
# if [[ "$CI_BUILD_REF_NAME" == "master" ]]; then
# docker tag "${DEPLOYMENT_IMAGE}" "${CI_REGISTRY_IMAGE}:latest"
# docker push "${CI_REGISTRY_IMAGE}:latest"
# fi
# if [[ "$CI_BUILD_REF_NAME" == "ci-cron" ]]; then
# docker tag "${DEPLOYMENT_IMAGE}" "${CI_REGISTRY_IMAGE}:ci-cron"
# docker push "${CI_REGISTRY_IMAGE}:ci-cron"
# fi
build:
stage: build
script:
# Clear *_TOKEN variables during code build so that compile-time code can't access them
- apt-get update && apt-get install -y --no-install-recommends libpq-dev git rsync
- CI_BUILD_TOKEN="" KUBE_TOKEN="" PROD_KUBE_TOKEN="" PROD_DOCKER_PASSWORD="" etc/scripts/stage_docker.sh --install-ghc --test
- docker build -t "${DEPLOYMENT_IMAGE}" etc/docker
- docker login -u gitlab-ci-token -p "${CI_BUILD_TOKEN}" "${CI_REGISTRY}"
- docker push "${DEPLOYMENT_IMAGE}"
- |
if [[ "$CI_BUILD_REF_NAME" == "master" ]]; then
docker tag "${DEPLOYMENT_IMAGE}" "${CI_REGISTRY_IMAGE}:latest"
docker push "${CI_REGISTRY_IMAGE}:latest"
fi
if [[ "$CI_BUILD_REF_NAME" == "ci-cron" ]]; then
docker tag "${DEPLOYMENT_IMAGE}" "${CI_REGISTRY_IMAGE}:ci-cron"
docker push "${CI_REGISTRY_IMAGE}:ci-cron"
fi
deploy_prod:
stage: deploy
@ -67,37 +60,28 @@ deploy_prod:
- master
when: manual
environment:
name: stackage-server-prod
name: production
url: https://www.stackage.org/
variables:
CRON_DEPLOYMENT_NAME: "stackage-server-cron-prod"
DEPLOYMENT_NAME: "stackage-server-prod"
HOOGLE_DEPLOYMENT_NAME: "stackage-server-hoogle-prod"
CRON_DEPLOYMENT_NAME: "stackage-server-cron-prod"
KUBE_NAMESPACE: "${PROD_KUBE_NAMESPACE}"
PROD_DEPLOYMENT_IMAGE: "fpco/stackage-server-prod:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
HOST: stackage.org
script:
- export
KUBE_CA_PEM="$PROD_KUBE_CA_PEM"
KUBE_URL="$PROD_KUBE_URL"
KUBE_TOKEN="$PROD_KUBE_TOKEN"
KUBE_NAMESPACE="$PROD_KUBE_NAMESPACE"
KUBE_CA_PEM="$PROD_V2_KUBE_CA_PEM"
KUBE_URL="$PROD_V2_KUBE_URL"
KUBE_TOKEN="$PROD_V2_KUBE_TOKEN"
KUBE_NAMESPACE="$PROD_V2_KUBE_NAMESPACE"
- *KUBELOGIN
- docker login -u "$PROD_DOCKER_USERNAME" -p "${PROD_DOCKER_PASSWORD}"
- docker tag "$DEPLOYMENT_IMAGE" "$PROD_DEPLOYMENT_IMAGE"
- docker push "$PROD_DEPLOYMENT_IMAGE"
- docker tag "$DEPLOYMENT_IMAGE" "fpco/stackage-server-prod:latest"
- docker push "fpco/stackage-server-prod:latest"
- kubectl set image "deployment/$DEPLOYMENT_NAME" stackage-server="$PROD_DEPLOYMENT_IMAGE"
- kubectl set image "deployment/$HOOGLE_DEPLOYMENT_NAME" stackage-server-hoogle="$PROD_DEPLOYMENT_IMAGE"
- kubectl set image "deployment/$CRON_DEPLOYMENT_NAME" stackage-server-cron="$PROD_DEPLOYMENT_IMAGE"
- kubectl rollout status "deployment/$DEPLOYMENT_NAME"
- kubectl rollout status "deployment/$HOOGLE_DEPLOYMENT_NAME"
- kubectl rollout status "deployment/$CRON_DEPLOYMENT_NAME"
- *HELMUPGRADE
- *HELMCHECK
deploy_ci:
stage: deploy
#only:
# - ci
only:
- ci
environment:
name: staging
url: https://ci.stackage.org/

View File

@ -1,3 +1,4 @@
{{- if .Values.cron.enabled -}}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
@ -14,7 +15,7 @@ spec:
release: {{ .Release.Name }}
spec:
imagePullSecrets:
- name: registry-key
- name: {{ .Values.registrySecretName }}
volumes:
- name: stackage-server-cron-volume
secret:
@ -62,3 +63,4 @@ spec:
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
{{- end }}

View File

@ -12,7 +12,7 @@ spec:
release: {{ .Release.Name }}
spec:
imagePullSecrets:
- name: registry-key
- name: {{ .Values.registrySecretName }}
containers:
- name: stackage-server
image: {{ .Values.image.image }}

View File

@ -12,7 +12,7 @@ spec:
release: {{ .Release.Name }}
spec:
imagePullSecrets:
- name: registry-key
- name: {{ .Values.registrySecretName }}
containers:
- name: stackage-server-hoogle
image: {{ .Values.image.image }}

View File

@ -6,10 +6,14 @@
#cronApp: stackage-server-cron-prod
image:
replicas: 1
replicas: 2
replicasHoggle: 2
env:
approot: "stackage.org"
approot: "https://stackage.org"
ingress:
hosts:
- stackage.org
stackageResources:
resources:
@ -28,3 +32,8 @@ cronResources:
limits:
cpu: 300m
memory: 4096Mi
cron:
enabled: true
registrySecretName: gitlab-ci-registrykey

View File

@ -7,7 +7,7 @@
image:
replicas: 1
replicasHoggle: 2
replicasHoggle: 1
env:
approot: "https://ci.stackage.org"
@ -32,3 +32,5 @@ cronResources:
limits:
cpu: 200m
memory: 2096Mi
registrySecretName: registry-key