indaclouds.fr

Some tips when I take time to write them down.

Part 4 - Use Gitlab to build our docker image


Today, we'll use Gitlab CI to be able to create a custom docker image of odoo with our addon ready to be installed in a new container.

Create a .gitlab-ci.yml file to the root folder of your addon/repo:

$ cd ~/odoo-docker/addons/my_awesome_addon
$ touch .gitlab-ci.yml

Fill it with this:

image: docker:latest

services:
- postgres:9.4

before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY

variables:
  POSTGRES_USER: odoo
  POSTGRES_PASSWORD: odoo

build:
  stage: build
  services:
  - docker:dind
  script:
  - docker build -t $CI_REGISTRY_IMAGE:latest .
  - docker tag $CI_REGISTRY_IMAGE:latest $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
  - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME

We can use shared runner from Gitlab to build our image or use a private runner able to build docker image, more information here.

Let's push this file and see the magic happening in the pipelines tab of Gitlab.

$ git add --all
$ git commit -m "Enable Gitlab CI"
$ git push

Once the build is finished, you can pull your new image from Gitlab registry:

$ docker login registry.gitlab.com
$ docker pull registry.gitlab.com/NAMESPACE/PROJECT_NAME

Then install your addon in a new container:

$ docker run -p 8069:8069 --name my-new-container --link db-docker:db registry.gitlab.com/NAMESPACE/PROJECT_NAME -d my-new-database -i my_awesome_addon