Terraform for running GitLab CI/CD jobs on cloud.gov or another CloudFoundry based PaaS.
-
Log in to cloud.gov and select your ORGNAME when prompted
cf login -a api.fr.cloud.gov --sso
-
Create a management space, if it does not already exist.
cf create-space SPACEPREFIX-mgmt
-
Create a cloud.gov service account with the
OrgManager
permission../create_service_account -s SPACEPREFIX-mgmt -u glr-local-deploy -m > secrets.auto.tfvars
-
Copy
vars.tfvars-example
tovars.auto.tfvars
.cp vars.tfvars-example vars.auto.tfvars
-
Edit
vars.auto.tfvars
and modify the values there as needed. In particular, you must:- for sandbox/developer deployments, set
cf_space_prefix
to the same asSPACEPREFIX
used for the management space - supply the
ci_server_token
provided when you configure the runner at the target GitLab URL - supply a docker hub username and personal access token to avoid rate limiting
- set
developer_emails
to whoever might need to debug this deployment - set
worker_egress_allowlist
to the package hosts needed for your supported programming languages
- for sandbox/developer deployments, set
-
Run
terraform init
-
Run
terraform validate
-
Run
terraform plan
and double check that the changes are what is expected. -
Apply your changes with
terraform apply
-
Check to see that the runner has registered itself in GitLab under your project repository under Settings -> CI/CD -> Runners (Expand)
At this point the runner should be available to run jobs. See Use GitLab - Use CI/CD to build your application - Getting started for much more on GitLab CI/CD and runners.
Problems with runner registration often requiring viewing it's logs.
cf logs --recent RUNNER-NAME
The manager and workers run in restricted-egress spaces. There are two places to edit in order to allow traffic.
- If the runner-manager cannot download something, or the runner-workers are failing during the
prepare.sh
steps then thelocal.devtools_egress_allowlist
inmain.tf
should be updated - If the runner-workers cannot download a dependency required because of the programming language in use by the project, then it should likely be added to the
var.worker_egress_allowlist
invars.auto.tfvars
It is also possible that additional configuration is required for the package manager in question to direct traffic over the proxy.
Recent versions of gitlab-runner
expose almost all initial configuration
variables for the register
subcommand as environment variables. This allows
us to do almost all configuration in manifest.yml
and skip modifying
command line options in runner/.profile
or having a .toml add on.