Skip to content

Commit

Permalink
Create v14 config
Browse files Browse the repository at this point in the history
  • Loading branch information
m3r3nix committed Feb 2, 2024
1 parent 019537f commit 37e66e7
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
FROM debian:buster-slim
MAINTAINER Odoo S.A. <[email protected]>

SHELL ["/bin/bash", "-xo", "pipefail", "-c"]

# Generate locale C.UTF-8 for postgres and general locale data
ENV LANG C.UTF-8

# Install some deps, lessc and less-plugin-clean-css, and wkhtmltopdf
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
dirmngr \
fonts-noto-cjk \
git \
gnupg \
libssl-dev \
node-less \
npm \
python3-num2words \
python3-pdfminer \
python3-pip \
python3-phonenumbers \
python3-pyldap \
python3-qrcode \
python3-renderpm \
python3-setuptools \
python3-slugify \
python3-vobject \
python3-watchdog \
python3-xlrd \
python3-xlwt \
xz-utils \
&& curl -o wkhtmltox.deb -sSL https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb \
&& echo 'ea8277df4297afc507c61122f3c349af142f31e5 wkhtmltox.deb' | sha1sum -c - \
&& apt-get install -y --no-install-recommends ./wkhtmltox.deb \
&& rm -rf /var/lib/apt/lists/* wkhtmltox.deb

# install latest postgresql-client
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' > /etc/apt/sources.list.d/pgdg.list \
&& GNUPGHOME="$(mktemp -d)" \
&& export GNUPGHOME \
&& repokey='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8' \
&& gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "${repokey}" \
&& gpg --batch --armor --export "${repokey}" > /etc/apt/trusted.gpg.d/pgdg.gpg.asc \
&& gpgconf --kill all \
&& rm -rf "$GNUPGHOME" \
&& apt-get update \
&& apt-get install --no-install-recommends -y postgresql-client \
&& rm -f /etc/apt/sources.list.d/pgdg.list \
&& rm -rf /var/lib/apt/lists/*

# Install rtlcss (on Debian buster)
RUN npm install -g rtlcss

# Copy Odoo installation package downloaded in the previous GitHub Action step
COPY ./odoo.deb /

# Install Odoo
RUN apt-get update \
&& apt-get -y install --no-install-recommends ./odoo.deb \
&& rm -rf /var/lib/apt/lists/* odoo.deb

# Copy entrypoint script and Odoo configuration file
COPY ./entrypoint.sh /
COPY ./odoo.conf /etc/odoo/
COPY ./wait-for-psql.py /usr/local/bin/wait-for-psql.py

# Set permissions and Mount /var/lib/odoo to allow restoring filestore and /mnt/extra-addons for users addons
RUN chown odoo /etc/odoo/odoo.conf \
&& mkdir -p /mnt/extra-addons \
&& chown -R odoo /mnt/extra-addons
VOLUME ["/var/lib/odoo", "/mnt/extra-addons"]

# Expose Odoo services
EXPOSE 8069 8071 8072

# Set the default config file
ENV ODOO_RC /etc/odoo/odoo.conf

# Set default user when running the container
USER odoo

ENTRYPOINT ["/entrypoint.sh"]
CMD ["odoo"]
1 change: 1 addition & 0 deletions .devcontainer/URL.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://nightly.odoo.com/14.0/nightly/deb/odoo_14.0.latest_all.deb
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Odoo Dev Container",
"dockerComposeFile": "docker-compose.yml",
"service": "odoo",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}/custom",
"remoteUser": "root",
"forwardPorts": [8069],
"shutdownAction": "stopCompose",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"GitHub.copilot",
"GitHub.copilot-chat",
"DavidAnson.vscode-markdownlint",
"DotJoshJohnson.xml"
]
}
}
}
16 changes: 16 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.1'
services:
odoo:
image: "ghcr.io/m3r3nix/odoo-v14-community:latest"
depends_on:
- db
ports:
- "8069:8069"
volumes:
- ../custom:/mnt/extra-addons
db:
image: postgres:13
environment:
- POSTGRES_DB=postgres
- POSTGRES_PASSWORD=odoo
- POSTGRES_USER=odoo
49 changes: 49 additions & 0 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -e

if [ -v PASSWORD_FILE ]; then
PASSWORD="$(< $PASSWORD_FILE)"
fi

# set the postgres database host, port, user and password according to the environment
# and pass them as arguments to the odoo process if not present in the config file
: ${HOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}

DB_ARGS=()
function check_config() {
param="$1"
value="$2"
if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then
value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g')
fi;
DB_ARGS+=("--${param}")
DB_ARGS+=("${value}")
}
check_config "db_host" "$HOST"
check_config "db_port" "$PORT"
check_config "db_user" "$USER"
check_config "db_password" "$PASSWORD"

case "$1" in
-- | odoo)
shift
if [[ "$1" == "scaffold" ]] ; then
exec odoo "$@"
else
wait-for-psql.py ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}"
fi
;;
-*)
wait-for-psql.py ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}"
;;
*)
exec "$@"
esac

exit 1
37 changes: 37 additions & 0 deletions .devcontainer/odoo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[options]
addons_path = /mnt/extra-addons
data_dir = /var/lib/odoo
; admin_passwd = admin
; csv_internal_sep = ,
; db_maxconn = 64
; db_name = False
; db_template = template1
; dbfilter = .*
; debug_mode = False
; email_from = False
; limit_memory_hard = 2684354560
; limit_memory_soft = 2147483648
; limit_request = 8192
; limit_time_cpu = 60
; limit_time_real = 120
; list_db = True
; log_db = False
; log_handler = [':INFO']
; log_level = info
; logfile = None
; longpolling_port = 8072
; max_cron_threads = 2
; osv_memory_age_limit = 1.0
; osv_memory_count_limit = False
; smtp_password = False
; smtp_port = 25
; smtp_server = localhost
; smtp_ssl = False
; smtp_user = False
; workers = 0
; xmlrpc = True
; xmlrpc_interface =
; xmlrpc_port = 8069
; xmlrpcs = True
; xmlrpcs_interface =
; xmlrpcs_port = 8071
32 changes: 32 additions & 0 deletions .devcontainer/wait-for-psql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
import argparse
import psycopg2
import sys
import time


if __name__ == '__main__':
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--db_host', required=True)
arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--timeout', type=int, default=5)

args = arg_parser.parse_args()

start_time = time.time()
while (time.time() - start_time) < args.timeout:
try:
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname='postgres')
error = ''
break
except psycopg2.OperationalError as e:
error = e
else:
conn.close()
time.sleep(1)

if error:
print("Database connection failure: %s" % error, file=sys.stderr)
sys.exit(1)
96 changes: 96 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Build and Push Odoo Dev Container

on:
push:
paths:
- '.devcontainer/URL.conf'
workflow_dispatch:

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Download .deb package with curl from the provided URL in the ./devcontainer/URL.txt file
- name: Download odoo.deb package
if: github.event_name != 'pull_request'
run: |
curl -sSL -o .devcontainer/odoo.deb $(cat .devcontainer/URL.conf)
# Set environmet variables based on the downloaded .deb package version number
- name: Set Odoo version environment variable
if: github.event_name != 'pull_request'
run: |
export ODOO_DEB_VERSION=$(dpkg-deb -f .devcontainer/odoo.deb version)
echo "ODOO_DEB_VERSION=${ODOO_DEB_VERSION}" >> $GITHUB_ENV
echo "ODOO_MAIN_VERSION=${ODOO_DEB_VERSION:0:2}" >> $GITHUB_ENV
echo "ODOO_TYPE=$(echo $ODOO_DEB_VERSION | grep -q 'e' && echo 'enterprise' || echo 'community')" >> $GITHUB_ENV
# Use the tag 'latest' only if the downloaded .deb package is for the Enterprise version (Enterprise download URL only provides the latest build)
# or if the download URL includes the word 'latest' (for Community version you can use either latest or any specific date)
- name: Determine if latest tag should be used
if: github.event_name != 'pull_request'
run: |
if [[ "${{ env.ODOO_TYPE }}" == "enterprise" ]] || grep -q 'latest' .devcontainer/URL.conf; then
echo "IS_LATEST=true" >> $GITHUB_ENV
else
echo "IS_LATEST=false" >> $GITHUB_ENV
fi
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
if: ${{ github.event_name != 'pull_request' }}
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ github.actor }}/odoo-v${{ env.ODOO_MAIN_VERSION }}-${{ env.ODOO_TYPE }}
tags: |
type=raw,value=${{ env.ODOO_DEB_VERSION }}
type=raw,value=latest,enable=${{ env.IS_LATEST }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
if: ${{ github.event_name != 'pull_request' }}
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: ./.devcontainer
file: ./.devcontainer/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Loading

0 comments on commit 37e66e7

Please sign in to comment.