Skip to content

Instantly share code, notes, and snippets.

@hellosteadman
Created November 30, 2018 13:20
Show Gist options
  • Save hellosteadman/16f788aa28a173e0a854c0f1b11ad3c4 to your computer and use it in GitHub Desktop.
Save hellosteadman/16f788aa28a173e0a854c0f1b11ad3c4 to your computer and use it in GitHub Desktop.
Podiant pipeline
variables:
K8S_CONTEXT: core
stages:
- test
- build
- migrate
- deploy
test:
stage: test
image: ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest
services:
- postgres:9.3
script:
# Install prerequisites
- pip install -qr requirements-testing.txt
- pip install --no-cache-dir -qr requirements.txt
# Clear any coverage reports we already have
- coverage erase
# Run fast tests
- ENVIRONMENT=testing coverage run --parallel-mode --source podiant manage.py test podiant
# Spin up PostgreSQL to run slow tests
- python wait_for_postgres.py
# Run slow tests
- ENVIRONMENT=slowtests coverage run --parallel-mode --source podiant manage.py test podiant
# Combine coverage files from both test runs
- coverage combine
# Produce coverage report
- coverage report
code-quality:
stage: test
image: python:3.6.3
before_script:
# Install flake8
- pip install -e git+https://gitlab.com/pycqa/flake8@9631dac5#egg=flake8
script:
- flake8 ./podiant
build:
stage: build
image: docker:stable
services:
- docker:stable-dind
variables:
DOCKER_DRIVER: overlay2
before_script:
# Login to our Docker registry
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script:
# Download the latest cached version of the image
- docker pull ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
# Build a new version of the image
- docker build --cache-from ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG} -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG} -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8} .
# Push the image back to the repo
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8}
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
after_script:
# Clean up
- docker logout ${CI_REGISTRY}
migrate:
image: podiant/kubectl-deployer
stage: migrate
variables:
K8S_TIER: web
script:
# Find-and-replace the image definition from our job file, with the
# newly-tagged image, then pipe the output through to kubectl
- sed -e 's!image:\ .*$!image:\ '"${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8}"'!g' .k8s/migrate-job.yml | kubectl apply -f -
- kubectl wait --for=condition=complete jobs/core-migrate-job
- kubectl logs jobs/core-migrate-job
- kubectl delete jobs/core-migrate-job
only:
- master
collect-static:
image: podiant/kubectl-deployer
stage: migrate
variables:
K8S_TIER: web
script:
# Find-and-replace the image definition from our job file, with the
# newly-tagged image, then pipe the output through to kubectl
- sed -e 's!image:\ .*$!image:\ '"${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8}"'!g' .k8s/collectstatic-job.yml | kubectl apply -f -
- kubectl wait --for=condition=complete --timeout=15m jobs/core-collectstatic-job
- kubectl logs jobs/core-collectstatic-job
- kubectl delete jobs/core-collectstatic-job
only:
- master
rollout-web:
image: podiant/kubectl-deployer
stage: deploy
variables:
K8S_TIER: web
script:
- kubectl set image deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment ${K8S_TIER}=${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8}
- kubectl rollout status deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment
only:
- master
rollout-worker-default:
image: podiant/kubectl-deployer
stage: deploy
variables:
K8S_TIER: worker-default
script:
- kubectl set image deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment ${K8S_TIER}=${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8}
- kubectl rollout status deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment
only:
- master
rollout-worker-processing:
image: podiant/kubectl-deployer
stage: deploy
variables:
K8S_TIER: worker-processing
script:
- kubectl set image deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment ${K8S_TIER}=${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8}
- kubectl rollout status deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment
only:
- master
rollout-cron:
image: podiant/kubectl-deployer
stage: deploy
variables:
K8S_TIER: cron
script:
- kubectl set image deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment ${K8S_TIER}=${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_SHA:0:8}
- kubectl rollout status deployment/${K8S_CONTEXT}-${K8S_TIER}-deployment
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment