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 info

variables:
  POSTGRES_USER: odoo
  POSTGRES_PASSWORD: odoo

build:
  services:
  - docker:dind
  stage: build
  script:
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
  - docker build -t registry.gitlab.com/NAMESPACE/PROJECT_NAME .
  - docker push registry.gitlab.com/NAMESPACE/PROJECT_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