This is repository that builds Docker Image with all scripts needed to deploy to Kubernetes from GitLab CI.
It is used to give the GitLab Demo which contains detailed instructions to reproduce.
It basically consist of two stages:
- Build stage where a Docker Image is built,
- Deploy stage where a previously built Docker Image is run on Kubernetes and exposed on hostname.
The build script does:
- Check if the repository has
Dockerfile
, - If yes, use
docker build
to build Docker Image, - If no, use herokuish to build and package a buildpack based application,
- Login to GitLab Container Registry,
- Push build image to GitLab Container Registry.
The deploy script does:
- Create a new namespace if does not exist already,
- Deploy Postgres database with preconfigured username, password and database name,
- Deploy an application with most recent Docker Image,
- Create or update ingress to expose the application under hostname.
During deployment automatically PostgreSQL
is provisioned unless DISABLE_POSTGRES
is specified.
We currently use preconfigured credentials. These credentials are used for defining DATABASE_URL
of format: postgres://user:password@postgres-host:postgres-port/postgres-database
.
- GitLab Runner using Docker or Kubernetes executor with privileged mode enabled,
- Service account for existing Kubernetes cluster,
- DNS wildcard domain to host deployed applications.
- Public and private docker images can be deployed, but credentials are accessible during deployment,
- There is no ability to pass environment variables to deployed application,
- Provisioned database uses immutable storage: all data will be lost after container restart,
DISABLE_POSTGRES: "yes"
: disable automatic deployment of PostgreSQL,POSTGRES_USER: "my-user"
: use custom username for PostgreSQL,POSTGRES_PASSWORD: "password"
: use custom password for PostgreSQL,POSTGRES_DB: "my database"
: use custom database name for PostgreSQL,
You can see existing working examples:
Simply fork this repository. As soon as you push your changes, the new docker image with all scripts will be build. You can then start using your own docker image hosted on your Container Registry.
Basically, configure Kubernetes Service in your project settings and
copy-paste this .gitlab-ci.yml
.
This project uses latest version of kubectl
in order to fix problems with kubectl rollout status
.
As of today it is v1.7.0-alpha-3
.
MIT, GitLab, 2016-2017