GitLab autodeployment for testing

Requirements

  • openssl utility
  • kubectl
  • task
  • cluster interaction tool (one of):
    • gcloud
    • kind

Parameters

Parameters are passed via environment variables:

variable namerequireddefaultdescription
GITLAB_CHART_VERSIONnolatest availableChart version to use. Must align with the charts provided within TAG of the operator
GITLAB_CHART_REPOnohttps://gitlab.com/gitlab-org/charts/gitlabGitLab Helm Chart repository HTTP URI. Mainly used to fetch default KinD configs.
IMGnoregistry.gitlab.com/gitlab-org/cloud-native/gitlab-operatorOperator Container Image Name
TAGnomasterOperator Container Image Tag. Needs an override in most cases
GITLAB_CHART_DIRyes path to a clone of GitLab Chart repo
GITLAB_OPERATOR_DIRno.path to a clone of GitLab Operator repo
GITLAB_OPERATOR_MANIFESTno Optional reference to manifest for Operator deployment, if empty - auto-generated from ${GITLAB_OPERATOR_DIR}. To note: to reference proper image and tag set up IMG and TAG environment variables
GITLAB_CR_DEPLOY_MODEnoselfsignedSelect mode of deployment: selfsigned or certmanager
GITLAB_OPERATOR_DOMAINno ${LOCAL_IP}.nip.io for KinD, cloud-native.win for other platformsDomain for GitLab (operator) deployment
GITLAB_HOSTno*.${GITLAB_OPERATOR_DOMAIN}Common name to use for GitLab endpoint self-signed cert
GITLAB_KEY_FILEnogitlab.keySelf-signed cert key file
GITLAB_CERT_FILEnogitlab.crtSelf-signed cert file
GITLAB_PAGES_HOSTno*.pages.${GITLAB_OPERATOR_DOMAIN}Common name to use for GitLab Pages endpoint self-signed cert
GITLAB_PAGES_KEY_FILEnopages.keySelf-signed cert key file
GITLAB_PAGES_CERT_FILEnopages.crtSelf-signed cert file
GITLAB_ACME_EMAILnooutput of git config user.email Email used for cert-manager. Not necessary in KinD deployments
GITLAB_RUNNER_TOKENno Runner Token, if empty it’s auto-retrieved from running GitLab Instance
KINDnokindcommand line executable name for KinD
KIND_CLUSTER_NAMEnogitlabKinD cluster name
KIND_IMAGEnokindest/node:v1.18.19value of --image argument for KinD
KIND_LOCAL_IPyes, for KinD Local IP required to provision Certs etc for the domain ${LOCAL_IP}.nip.io
KUBECTLnokubectlpath to kubectl command
HELMnohelmpath to helm command
TASKnotaskpath to task command

Tool pointer variables ($KIND, $KUBECTL, $HELM, etc.)

Main use of tool pointer variables is to point to particular tool path or path to a wrapper script (like k for kubectl, for example).

One of the alternative uses for any one of those variables is to get some debugging info:

KUBECTL="echo kubectl" provision_and_deploy.sh deploy_operator

However, this can also be achieved by using bash -x provision_and_deploy.sh.

GCP

Example with Cert-Manager (ran from the root of gitlab-operator repo):

export GITLAB_CHART_DIR=~/work/gitlab \
       GITLAB_OPERATOR_DOMAIN="mydomain.k8s-ft.win" \
       GITLAB_ACME_EMAIL="somebody@gitlab.com" \
       GITLAB_CR_DEPLOY_MODE="certmanager"

# https://docs.gitlab.com/charts/installation/cloud/gke.html
PROJECT="gcp-project-123" CLUSTER_NAME="mydomain" \
    bash ${GITLAB_CHART_DIR}/scripts/gke_bootstrap_script.sh up

# ...wait for provisioning to complete
scripts/provision_and_deploy.sh generic_deploy

Alternatively, use a CR generated by a pipeline (downloaded into ./123-my-branch.yaml, for example):

cd scripts
export GITLAB_CHART_DIR=~/work/gitlab \
       GITLAB_OPERATOR_DIR=~/work/gitlab-operator \
       GITLAB_OPERATOR_MANIFEST=./123-my-branch.yaml \
       GITLAB_OPERATOR_DOMAIN="mydomain.k8s-ft.win" \
       GITLAB_ACME_EMAIL="somebody@gitlab.com" \
       GITLAB_CR_DEPLOY_MODE="certmanager"

PROJECT="gcp-project-123" CLUSTER_NAME="mydomain" \
    bash ${GITLAB_CHART_DIR}/scripts/gke_bootstrap_script.sh up

# ...wait for provisioning to complete
./provision_and_deploy.sh generic_deploy

The command above has been run from the within scripts/ directory (note the use of GITLAB_OPERATOR_DIR).

One can deploy with self-signed certs, in which case KIND_LOCAL_IP should be provided (use “cluster IP”) and not GITLAB_OPERATOR_DOMAIN.

KinD

By default deployment is done with Self-Signed cert:

export KIND_CLUSTER_NAME=gitlab \
       KIND_LOCAL_IP=192.168.3.194 \
       GITLAB_CHART_DIR=~/work/gitlab

scripts/provision_and_deploy.sh kind_deploy

Alternatively, use a CR generated by a pipeline in build manifest job (downloaded into ./123-my-branch.yaml, for example):

export KIND_CLUSTER_NAME=gitlab \
       KIND_LOCAL_IP=192.168.3.194 \
       GITLAB_CHART_DIR=~/work/gitlab \
       GITLAB_OPERATOR_MANIFEST=./123-my-branch.yaml \
       GITLAB_OPERATOR_DIR=~/work/gitlab-operator

scripts/provision_and_deploy.sh kind_deploy

That’s it! You should now be able to navigate to https://gitlab.(your IP).nip.io and log in with the root password.

NOTE: Use of cert-manager for generating certificates for Ingresses in KinD is not possible unless your KinD instance is publicly accessible.

Runner deployment

Once base deployment has been performed do the runner deployment (retaining same exported variables):

scripts/provision_and_deploy.sh runner_deploy

Alternatively, do everything in one go (we’ll use kind deploy for example):

scripts/provision_and_deploy.sh kind_deploy runner_deploy