Commit 09e0429c authored by David Foucher's avatar David Foucher
Browse files

Docker

parent f4ba506d
......@@ -9,3 +9,6 @@ dist/
.coverage
htmlcov/
.envrc
backoffice/node_modules/
backoffice/dist/
*.log
image: python:3.6
#TODO test docker image with https://github.com/aelsabbahy/goss
cache:
paths:
- ~/.cache/pip/
api publish:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
stage: build
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context ${CI_PROJECT_DIR}/docker --dockerfile $CI_PROJECT_DIR/docker/dockerfile_trefle --build-arg TREFLE_VERSION=$CI_COMMIT_TAG --build-arg TREFLE_GIT=${CI_PROJECT_URL} --destination ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
only:
- /^api-v[0-9.]+$/
before_script:
- python setup.py develop
- pip install -r requirements-dev.txt
backoffice publish:
variables:
TREFLE_OLD_VERSION: "api-v0.6.1"
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
stage: build
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context ${CI_PROJECT_DIR}/docker --dockerfile ${CI_PROJECT_DIR}/docker/dockerfile_backoffice --build-arg TREFLE_BACK_VERSION=${CI_COMMIT_TAG} --build-arg TREFLE_OLD_VERSION=${TREFLE_OLD_VERSION} --build-arg TREFLE_GIT=${CI_PROJECT_URL} --destination ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
only:
- /^backoffice-v[0-9.]+$/
test:
image: python:3.6
cache:
paths:
- ~/.cache/pip/
before_script:
- python setup.py develop
- pip install -r requirements-dev.txt
stage: test
script:
- py.test -v --cov
- behave -D coverage-format=long
- py.test -v --cov
- behave -D coverage-format=long
only:
- branches
- master
......@@ -59,3 +59,24 @@ Get a detailed coverage report:
Get a more detailed coverage report:
behave -D coverage-format=long
## Build project in PROD mode
Go to docker file
Add this env var:
VERSION api-vX.X.X
OLD_VERSION api-vX.X.X
BACK_VERSION backoffice-vX.X.X
LBF_CHARMAP "sA,4B,RC,cD,oE,gF,yG,wH,mI,HJ,7K,EL,aM,YN,XO,8P,GQ,BR,kS,iT,IU,AV,TW,DX,pY,JZ,2a,Lb,Mc, d,de,Cf,Qg,fh,ri,Pj,Nk,Vl,vm,0n,Ko,ep,jq,Zr,9s,ht,Fu,tv,-w,Ux,1y,xz,30,u1,52,q3,W4,S5,66,n7,b8,O9,_+,l/,z "
CATALOG_USER {ASK-YOUR-LBF-CATALOG-API-USER}
CATALOG_KEY {ASK-YOUR-LBF-CATALOG-API-KEY}
CATALOG_URL https://labonneformation.pole-emploi.fr/api/v1/detail
TREFLE_GIT https://git.beta.pole-emploi.fr/open-source/trefle.git
where X.X.X is a tag of the TREFLE_GIT
OLD_VERSION and BACK_VERSION must be compatible
docker-compose up --build -d
logs are in docker/logs
server {
listen 80 default_server;
server_name trefle.pole-emploi.fr trefle.beta.pole-emploi.fr trefle-labonneformation.beta.pole-emploi.fr trefle-labonneformation.pole-emploi.fr;
charset utf-8;
client_max_body_size 25M;
location @gunicorn-master {
proxy_pass http://trefle:8000;
proxy_redirect off;
proxy_set_header Host $host;
}
location = / {
root /srv/trefle/trefle;
rewrite ^/$ /0.7/explorer last;
}
location /0.7 {
root /srv/trefle/trefle;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location /0.7/explorer {
alias /srv/trefle/trefle/explorer;
index index.html;
}
rewrite /0.7/(.*) /$1 break;
try_files $uri @gunicorn-master;
}
location /api-moteur/0.7 {
rewrite /api-moteur/0.7/(.*) /$1 break;
try_files $uri @gunicorn-master;
}
location ^~ {
rewrite ^/(.*)$ /0.7/$1 last;
}
#previous API version
location @gunicorn-old {
proxy_pass http://trefle-old:8000;
proxy_redirect off;
proxy_set_header Host $host;
}
location /0.6 {
root /srv/trefle-old/trefle;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location /0.6/explorer {
alias /srv/trefle-old/trefle/explorer;
index index.html;
}
rewrite /0.6/(.*) /$1 break;
try_files $uri @gunicorn-old;
}
location /api-moteur/0.6 {
rewrite /api-moteur/0.6/(.*) /$1 break;
try_files $uri @gunicorn-old;
}
}
version: "3.3"
services:
trefle:
restart: unless-stopped
build:
context: .
dockerfile: dockerfile_trefle
args:
- TREFLE_VERSION=${VERSION}
- TREFLE_GIT=${TREFLE_GIT:-https://git.beta.pole-emploi.fr/open-source/trefle.git}
volumes:
- ./log/trefle:/srv/log
environment:
- LBF_CHARMAP=${LBF_CHARMAP}
- CATALOG_USER=${CATALOG_USER}
- CATALOG_KEY=${CATALOG_KEY}
- CATALOG_URL=${CATALOG_URL}
#version majeur précédente
trefle-old:
restart: unless-stopped
build:
context: .
dockerfile: dockerfile_trefle
args:
- TREFLE_VERSION=${OLD_VERSION}
- TREFLE_GIT=${TREFLE_GIT:-https://git.beta.pole-emploi.fr/open-source/trefle.git}
volumes:
- ./log/trefle-old:/srv/log
environment:
- LBF_CHARMAP=${LBF_CHARMAP}
- CATALOG_USER=${CATALOG_USER}
- CATALOG_KEY=${CATALOG_KEY}
- CATALOG_URL=${CATALOG_URL}
backoffice:
restart: unless-stopped
build:
context: .
dockerfile: dockerfile_backoffice
args:
- TREFLE_GIT=${TREFLE_GIT:-https://git.beta.pole-emploi.fr/open-source/trefle.git}
- TREFLE_VERSION=${VERSION}
- TREFLE_OLD_VERSION=${OLD_VERSION}
depends_on:
- trefle
- trefle-old
volumes:
- ./backoffice/etc/nginx/sites-enabled:/etc/nginx/sites-enabled
- ./log/nginx:/var/log/nginx
dns:
- 1.1.1.1
ports:
- ${PORT:-80}:80
environment:
- VERSION=${VERSION}
- HOST=trefle
- OLD_VERSION=${OLD_VERSION}
- OLD_HOST=trefle-old
FROM ubuntu:xenial
LABEL maintainer="labonneformation@pole-emploi.fr"
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -y install \
apt-utils\
software-properties-common\
unzip \
nginx \
vim \
bzip2 \
cron \
logrotate \
iptables \
git \
dnsutils
ARG TREFLE_GIT
ARG TREFLE_VERSION
RUN git clone -b ${TREFLE_VERSION} ${TREFLE_GIT} /srv/trefle && \
chown -R www-data: /srv/trefle && \
chmod -R u+rwx /srv/trefle
ARG TREFLE_GIT
ARG TREFLE_OLD_VERSION
RUN git clone -b ${TREFLE_OLD_VERSION} ${TREFLE_GIT} /srv/trefle-old && \
chown -R www-data: /srv/trefle-old && \
chmod -R u+rwx /srv/trefle-old
CMD service nginx start; \
cron -f
FROM python:3.6
LABEL MAINTAINER "labonneformation@pole-emploi.fr"
ENV LANG C.UTF-8
ENV PYTHON_VERSION 3.6
ENV TREFLE_LOG_DIR /srv/log
ARG TREFLE_VERSION
ARG TREFLE_GIT
RUN apt-get update && apt-get -y install \
software-properties-common\
unzip \
vim \
bzip2 \
git\
pkg-config\
logrotate\
cron
# setup system
RUN mkdir -p ${TREFLE_LOG_DIR}
WORKDIR /srv
COPY trefle/etc/logrotate.d/gunicorn.logrotate /etc/logrotate.d/gunicorn
#deploy
COPY trefle/srv/gunicorn.conf.py ./gunicorn.conf.py
# setup virtualenv
RUN pip install pip -U && \
pip install gunicorn && \
pip install git+${TREFLE_GIT}@${TREFLE_VERSION}
#start
COPY trefle/start.sh .
ENTRYPOINT ./start.sh
/srv/log/* {
weekly
rotate 52
missingok
notifempty
compress
sharedscripts
postrotate
killall -s USR1 gunicorn
endscript
}
worker_class = 'roll.worker.Worker'
workers = 4
bind = '0.0.0.0:8000'
worker_tmp_dir = '/dev/shm'
log_level = 'debug'
#!/bin/sh
set -e
#start or reload gunicorn
if pgrep -x "gunicorn" > /dev/null
then
killall -HUP gunicorn
else
gunicorn trefle.api:app --config gunicorn.conf.py \
--error-logfile log/gunicorn-error.log \
--capture-output
fi
#NOTE : see https://stackoverflow.com/a/20214015 for why gunicorn-access.log not in use
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment