Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
78 lines (52 sloc) 4.2 KB

Pushing to the APPUiO registry

In order to be able to push to the APPUiO registry, we will need to configure our APPUiO project and integrate it with our Gitlab repository. This requires some configurative steps using the OpenShift command line interface, which are described in the following sections.

Creating a service account

After logging in, our first task is creating login credentials such that Gitlab CI is able to login to the internal APPUiO registry. As we cannot and would not want to use our own login credentials, we will have to create a so called Service Account (SA), which will then have limited permissions and its own credentials.

$ oc create sa gitlab
serviceaccount "gitlab" created

After the successful creation of the service account we have to grant it permission to push images.

$ oc policy add-role-to-user system:image-pusher system:serviceaccount:docs_example:gitlab
role "system:image-pusher" added: "system:serviceaccount:docs_example:gitlab"

To retrieve the login token for the created service account, we can use oc sa get-token gitlab. Using this token, we can now return to Gitlab and configure it such that it can push to the APPUiO registry.

Configuring the Kubernetes Integration (optional)

To configure the integration, go to your GitLab repository and choose Integrations in the upper right settings menu. Once there, click on Kubernetes in the list of integrations and enter the configuration as can be seen in the image below:


Extending .gitlab-ci.yml

After we have successfully added the Kubernetes integration to our Gitlab repository, we can go on and extend our CI configuration such that it pushes to the APPUiO registry. We will use a custom Gitlab CI runner with installed OpenShift CLI, as we need to interact with the APPUiO API from within our job.

What happens in this snippet is that we login to APPUiO using the OpenShift CLI, specifying the parameters that we set in the Kubernetes integration as URL and login token. We then login to the internal APPUiO registry with the username serviceaccount (doesn't matter what your SA is actually called) and a password that we get directly from the OC CLI using oc whoami -t.

Important to know is that Gitlab CI will only inject KUBE_URL and KUBE_TOKEN as environment variables if the job is classified as a deployment job (which means that it has to contain an environment: xyz property). For more information about deployment jobs and variables see #2.

The URL to the registry as well as the name of the image we will be building are specified as CI variables in lines 1-3. The custom runner we introduced in the snippet (image: appuio/gitlab-runner-oc:3.9.0) simply extends the official docker:latest with the OC CLI.