Odoo Devops Documentation: It-Projects LLC
Odoo Devops Documentation: It-Projects LLC
IT-Projects LLC
1 Docker 3
2 Kubernetes 5
2.1 Kubernetes solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Minikube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 GitLab CI/CD 7
3.1 Gitlab - Kubernetes integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 GitLab Runner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Github 11
4.1 Creating Pull Requests in batch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Merge bot for GitHub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Review bot for GitHub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4 Notifications to Telegram Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5 IFTTT 17
5.1 GitHub Integration with IFTTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6 Lint Checks 21
6.1 Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.2 Running checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7 Remote Development 23
7.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.2 Containers administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
i
ii
Odoo DevOps Documentation
Note: The project is moved to https://itpp.dev/ops/ and will be shutdown here soon
Contents: 1
Odoo DevOps Documentation
2 Contents:
CHAPTER 1
Docker
3
Odoo DevOps Documentation
4 Chapter 1. Docker
CHAPTER 2
Kubernetes
There is a lot of ways to run your Kubernetes cluster on different platforms including single-node Minikube with
completely automated setup on your own laptop or managed cluster on Google Compute Engine.
In this documentation we will consider intallation of Minikube cluster on your server or personal computer to give you
an idea of how quickly configure minimal working cluster on one machine.
Different platforms and solutions you can find in official kubernetes documentation
There should be no difference in where and how you set up your cluster. So you can pick up any of the solutions
presented instead.
2.2 Minikube
Minikube is easiest way to run single-node Kubernetes cluster locally. Setup is completely automated so it is just
matter of installation and starting the cluster.
5
Odoo DevOps Documentation
minikube start
Depending on the hypervisor you want to use you can specifiy it by –vm-driver option and choose amount of memory
you want Minikube to use:
Minikube also supports a –vm-driver=none option that runs the Kubernetes components on the host and not in a VM.
In this case you should have Docker installed.
And you can get the API with curl or any browser:
curl http://localhost:8001/api/
2.2.4 Dashboard
Minikube automaticly have Kubernetes Dashboard - web-based UI for Kubernetes clusters. It allows you to monitor
and manage aplications on your cluster.
To access dashboard you can just type in console:
minikube dashboard
minikube stop
6 Chapter 2. Kubernetes
CHAPTER 3
GitLab CI/CD
You can easily connect existing Kubernetes cluster to your GitLab project. With connected cluster you can use Review
Apps, deploy your applications and run your pipelines.
7
Odoo DevOps Documentation
GitLab provides a one-click install for some applications which will be added directly to your connected Kubernetes
cluster.
To one-click install applications:
• Navigate to your project’s Operations > Kubernetes page.
• Click on your connected cluster.
• Click install button beside the application you need.
You need to install Helm Tiller before you install any other application
If your Kubernetes cluster is connected to your GitLab project you can just:
• Navigate to your project’s Operations > Kubernetes page.
• Click on your connected cluster.
• Install Helm Tiller by clicking the install button beside it.
• Install GitLab Runner by clicking the install button beside it.
If you want to cofigure everything yourself, you can deploy runner manually.
First you need to create namespace for your future deployment:
apiVersion: v1
kind: ConfigMap
metadata:
name: gitlab-runner-cm
namespace: gitlab-runner-ns
data:
config.toml: |
concurrent = 10
check_interval = 30
entrypoint: |
#!/bin/bash
set -xe
cp /scripts/config.toml /etc/gitlab-runner/
For sake of not showing your token in clear in your deployment file we need to create secret.yaml with token as base
64 string:
echo -n "your_token" | base64
apiVersion: v1
kind: Secret
metadata:
name: gitlab-runner-secret
namespace: gitlab-runner-ns
type: Opaque
data:
runner-registration-token: <your token as base 64 string>
For creating runners gitlab needs ClusterRoleBinding with cluster-admin role. So before deploying we creating cluster
role:
Github
4.1.1 Prerequisites
4.1.2 Script
# DEVELOPER INFO
USERNAME=yelizariev
# WHERE TO CLONE
DIRECTORY_CLONE=$(pwd)
REPOS=(
misc-addons
saas-addons
(continues on next page)
11
Odoo DevOps Documentation
The script gives the right to a certain circle of people to merge branches in the repository by sending the certain
comment in the pull request.
12 Chapter 4. Github
Odoo DevOps Documentation
• If – Service Webhooks.
Use {event} from Prepare IFTTT's hooks of this instruction. For example: Event Name =
travis-not-finished-pr, Event Name = travis-failed-pr.
• Then – whatever you like. For actions with text ingredients use following for failed, success and not finished
checks:
– Value1 – Author of the merge
– Value2 – Author of the pull-request
– Value3 – Link to pull-request
4.2.4 Logs
This github bot posts review of pull-requests with odoo modules: list of updated files (installable and non-installable),
new features to test (according to doc/changelog.rst file)
mkdir /tmp/github-review-bot
cd /tmp/github-review-bot
wget https://gitlab.com/itpp/odoo-devops/raw/master/tools/github-review-bot/
˓→text_tree.py
zip -r /tmp/github-review-bot.zip *
– Then set Code Entry type to Upload a .zip file and select the created zip file
• Basic settings
– Change time running function to 50 sec – Timeout (default 3 sec)
14 Chapter 4. Github
Odoo DevOps Documentation
4.3.2 Logs
4.3.3 Roadmap
In this example we make a bot, that will send notifications to telegram group on new issues. You can slightly change
the script to use other type of events.
4.4.3 Secrets
Create .github/workflows/main.yml file (you can also use [Set up a workflow yourself] button
at Actions tab of the repository page)
on:
issues:
types: [opened, reopened, deleted, closed]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send notifications to Telegram
run: curl -s -X POST https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/
˓→sendMessage -d chat_id=${{ secrets.TELEGRAM_CHAT_ID }} -d text="${MESSAGE}" >> /dev/
˓→null
env:
MESSAGE: "Issue ${{ github.event.action }}: \n${{ github.event.issue.html_url
˓→}}"
16 Chapter 4. Github
CHAPTER 5
IFTTT
17
Odoo DevOps Documentation
• Trigger
Use API Gateway. Once you configure it and save, you will see API endpoint under Api Gateway details
section. Use option Open
Now register the URL as webhook at github: https://developer.github.com/webhooks/creating/. Use following
webhook settings:
– Payload URL – the URL
– Content Type: application/json
– Which events would you like to trigger this webhook? – Let me select individual events and then select
[x] Check runs
• Function Code
– Copy-paste this code: https://gitlab.com/itpp/odoo-devops/raw/master/tools/github-ifttt/lambda_function.
py
• If – Service Webhooks
Use {event} from Prepare IFTTT's hooks of this instruction. For example: Event
Name = travis-success-pr, Event Name = travis-failed-pr and Event Name =
travis-failed-branch
• Then – whatever you like. For actions with text ingredients use following:
– Value1 – Author of the pull-request
– Value2 – Link to pull-request
– Value3 – Link to the travis check
and for checks of stable branch:
– Value1 – Name of the branch
– Value2 – Name of the repo
– Value3 – Link to the travis check
Travis settings
• Update .travis.yml to get a notification in lambda when travis check is finished. You can configure either
always notify on failure or only when previous check was successful. Check Travis Documentation for details:
https://docs.travis-ci.com/user/notifications/#configuring-webhook-notifications
• Look it for example:
notifications:
webhooks:
on_failure: change
urls:
- "https://9ltrkrik2l.execute-api.eu-central-1.amazonaws.com/default/
˓→TriggerTravis/"
18 Chapter 5. IFTTT
Odoo DevOps Documentation
Logs
20 Chapter 5. IFTTT
CHAPTER 6
Lint Checks
6.1 Preparation
Execute once per computer
cd
git clone https://github.com/it-projects-llc/maintainer-quality-tools.git
cd maintainer-quality-tools/travis
LINT_CHECK="1" sudo -E bash -x travis_install_nightly 8.0
cd YOUR-PATH/TO/REPOSTORY
LINT_CHECK="1" TRAVIS_BUILD_DIR="." VERSION="12.0" travis_run_tests 12.0
21
Odoo DevOps Documentation
Remote Development
The section contains instructions to setup remote development environment. That is developer runs odoo and probably
other tools on remote server rather on his machine. Advantages of this approach are:
• easy way to provide big computing capacity
• the same environment from any device
• easy way to demonstrate work
7.1 Usage
To send commit or get access to private repositories you can use either login-password authentication or ssh keys. In
later case you can face a problem to do it on remote server, because your private ssh key is not installed there. The
good news is that you don’t need to do it. You can “forward ssh keys”. Just add -A to your ssh command or add
following lines to your ssh config (~/.ssh/config) on your (local) computer:
Host your.dev.server.example.com
ForwardAgent yes
ssh -T [email protected]
23
Odoo DevOps Documentation
sshfs
# to unmount:
fusermount -u /PATH/TO/REMOTE/FOLDER
References
• https://superuser.com/questions/616182/how-to-mount-local-directory-to-remote-like-sshfs
x2go allows you to run remotely browser (or any other application on x-server)
• Connect to your server:
• install x2go server :
X2GO Client
• install x2goclient
Ubuntu:
sudo add-apt-repository ppa:x2go/stable && \
sudo apt-get update && \
sudo apt-get install x2goclient
References:
– https://www.howtoforge.com/tutorial/x2go-server-ubuntu-14-04/
– http://wiki.x2go.org/doku.php/doc:installation:x2goclient
• Run client:
x2goclient
• create a new session with the settings below and connect to it (we assume that you have user named “noroot”
with ssh keys configured):
Host : YOUHOST
Port : 22
Session type: LXDE
[x] Try auto Login
Input / Output: Use Whole Display
Username: noroot
# Based on:
# lxd + docker: https://stgraber.org/2016/04/13/lxd-2-0-docker-in-lxd-712/
# lxd network (static ip): https://stgraber.org/2016/10/27/network-management-with-
˓→lxd-2-3/
LXD_NETWORK="dev-network2"
add-apt-repository ppa:ubuntu-lxc/lxd-stable
apt-get update
apt-get dist-upgrade
apt-get install lxd
# init lxd
lxd init
# init network
lxc network create ${LXD_NETWORK}
lxc network show ${LXD_NETWORK} # check ipv4.address field
############################
# Per each Developer
GITHUB_USERNAME="yelizariev"
CONTAINER="${GITHUB_USERNAME}"
SERVER_DOMAIN="${GITHUB_USERNAME}.dev.it-projects.info"
NGINX_CONF="dev-${GITHUB_USERNAME}.conf"
LOCAL_IP="10.37.82.100" # use one from network subnet
PORT="10100" # unique per each developer
# https://discuss.linuxcontainers.org/t/docker-cannot-write-to-devices-allow/998/3
read -r -d '' RAW_LXC <<EOF
lxc.apparmor.profile=unconfined
lxc.mount.auto="proc:rw sys:rw cgroup:rw"
lxc.cgroup.devices.allow=a
lxc.cap.drop=
EOF
lxc init ubuntu-daily:18.04 ${CONTAINER} -p default && \
lxc network attach ${LXD_NETWORK} ${CONTAINER} eth0 && \
lxc config device set ${CONTAINER} eth0 ipv4.address ${LOCAL_IP} && \
lxc config set ${CONTAINER} security.privileged true && \
# allow run docker in previliged mode.
# https://discuss.linuxcontainers.org/t/failed-to-write-a-rwm-to-devices-allow-
˓→operation-not-permitted-in-privileged-container/925/3
# colorize prompt:
lxc exec ${CONTAINER} -- sed -i "s/#force_color_prompt=yes/force_color_prompt=yes/" /
˓→root/.bashrc && \ (continues on next page)
###################
# Control commands
# delete container
lxc delete CONTAINER-NAME