Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 4c2511c

Browse files
author
Thomas Preud'homme
committed
[LNT] Add docker containerization files
LNT already strive to be easy to use both locally and in server mode. This patch adds containerization files in a new docker/ directory (which can later be renamed container/docker if more container gets supported). Creating the image becomes as easy as docker-compose build and running it is done via docker-compose up. The service described in docker-compose.yml uses postgres but the LNT image is controlled via DB_ variables and thus should work with any database engine. Note: I'm quite new to Docker so some reviews on Docker best practice would be much welcome. Reviewers: MatzeB, danilaml, kristof.beyls, cmatthews Reviewed By: cmatthews Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D65794 git-svn-id: https://llvm.org/svn/llvm-project/lnt/trunk@372354 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7b4c1dc commit 4c2511c

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

docker/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DB_USER=lntuser
2+
DB_BASE=lnt

docker/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:2.7-alpine
2+
3+
RUN apk update \
4+
&& apk add --no-cache --virtual .build-deps git g++ postgresql-dev yaml-dev \
5+
&& apk add --no-cache libpq \
6+
&& git clone https://git.llvm.org/git/lnt /var/src/lnt \
7+
&& python /var/src/lnt/setup.py install --server \
8+
&& rm -rf /var/src \
9+
&& apk --purge del .build-deps \
10+
&& mkdir /var/log/lnt
11+
12+
COPY docker-entrypoint.sh wait_db /usr/local/bin/
13+
14+
VOLUME /var/log
15+
16+
EXPOSE 8000
17+
18+
ENV DB_ENGINE= DB_HOST= DB_USER= DB_PWD= DB_BASE=
19+
20+
ENTRYPOINT docker-entrypoint.sh

docker/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3'
2+
3+
services:
4+
lnt:
5+
build:
6+
context: .
7+
container_name: lnt
8+
image: lnt
9+
environment:
10+
- DB_ENGINE=postgres
11+
- DB_HOST=lnt-postgres
12+
- DB_PWD
13+
depends_on:
14+
- db
15+
deploy:
16+
restart_policy:
17+
condition: on-failure
18+
ports:
19+
- "8000:8000"
20+
21+
db:
22+
container_name: lnt-postgres
23+
image: postgres:alpine
24+
environment:
25+
- POSTGRES_PASSWORD=${DB_PWD}
26+
- POSTGRES_USER=${DB_USER}
27+
- POSTGRES_DB=${DB_BASE}

docker/docker-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
DB_PATH=${DB_ENGINE:-postgresql}://${DB_USER:-lntuser}:${DB_PWD:?}@${DB_HOST:?}
4+
DB_BASE=${DB_BASE:-lnt}
5+
6+
if [ ! -r /etc/lnt.cfg ]; then
7+
DB_BASE_PATH="${DB_PATH}/${DB_BASE}" wait_db
8+
lnt create /var/lib/lnt \
9+
--config /etc/lnt.cfg \
10+
--wsgi lnt_wsgi.py \
11+
--tmp-dir /tmp/lnt \
12+
--db-dir "${DB_PATH}" \
13+
--default-db "${DB_BASE}"
14+
fi
15+
16+
cd /var/lib/lnt
17+
exec gunicorn lnt_wsgi:application \
18+
--bind 0.0.0.0:8000 \
19+
--workers 8 \
20+
--timeout 300 \
21+
--name lnt_server \
22+
--log-file /var/log/lnt/lnt.log \
23+
--access-logfile /var/log/lnt/gunicorn_access.log \
24+
--max-requests 250000 "$@"

docker/wait_db

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
from sqlalchemy import create_engine
5+
6+
db_base_path = os.environ['DB_BASE_PATH']
7+
8+
engine = create_engine(db_base_path)
9+
started = False
10+
11+
while not started:
12+
try:
13+
engine.execute("SELECT 1")
14+
started = True
15+
except Exception as inst:
16+
pass

0 commit comments

Comments
 (0)