Skip to content

Commit 1c10ede

Browse files
authored
Merge pull request #30 from aboutcode-org/fix-docker
Fix docker-compose and dockerfile config
2 parents ea47351 + dbccf56 commit 1c10ede

File tree

7 files changed

+75
-40
lines changed

7 files changed

+75
-40
lines changed

Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,32 @@
66
# See https://github.com/nexB/federatedcode for support or download.
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
9-
FROM python:3.10
9+
10+
FROM python:3.10-slim
11+
12+
ENV APP_NAME federatedcode
13+
ENV APP_DIR /opt/$APP_NAME
14+
1015
# Python settings: Force unbuffered stdout and stderr (i.e. they are flushed to terminal immediately)
1116
ENV PYTHONUNBUFFERED 1
1217
# Python settings: do not write pyc files
1318
ENV PYTHONDONTWRITEBYTECODE 1
19+
# Add the app dir in the Python path for entry points availability
20+
ENV PYTHONPATH $PYTHONPATH:$APP_DIR
1421

15-
RUN pip install --upgrade pip
22+
RUN apt-get update \
23+
&& apt-get install -y --no-install-recommends \
24+
wait-for-it \
25+
git \
26+
&& apt-get clean \
27+
&& rm -rf /tmp/* /var/tmp/*
1628

17-
WORKDIR /federatedcode
29+
WORKDIR $APP_DIR
1830

19-
COPY requirements.txt pyproject.toml /federatedcode/
31+
RUN mkdir -p /var/$APP_NAME/static/
2032

21-
RUN pip install -r requirements.txt
33+
# Keep the dependencies installation before the COPY of the app/ for proper caching
34+
COPY setup.cfg setup.py requirements.txt pyproject.toml $APP_DIR/
35+
RUN pip install . -c requirements.txt
2236

23-
COPY . /federatedcode
37+
COPY . $APP_DIR

README.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@ security information.
99
Quick Installation
1010
--------------------
1111

12+
Run with Docker
13+
~~~~~~~~~~~~~~~
14+
15+
16+
Clone FederatedCode::
17+
18+
git clone https://github.com/aboutcode-org/federatedcode.git
19+
cd federatedcode
20+
21+
Build and run::
22+
23+
docker compose build
24+
docker compose up
25+
26+
27+
Local development installation
28+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
1230
On a Debian system, use this::
1331

1432
sudo apt-get install python3-venv python3-dev postgresql libpq-dev build-essential
15-
git clone https://github.com/nexB/federatedcode.git
33+
git clone https://github.com/aboutcode-org/federatedcode.git
1634
cd federatedcode
1735
make dev envfile postgresdb
1836
make test
@@ -163,9 +181,3 @@ funding is made available by the Swiss State Secretariat for Education, Research
163181
:target: https://nlnet.nl/discovery/
164182
:height: 40
165183
:alt: NGI Discovery logo
166-
167-
168-
169-
170-
171-

docker-compose.yml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
11
version: '3'
22

33
services:
4-
federatedcode_db:
5-
image: postgres:16
4+
db:
5+
image: postgres:13
66
env_file:
77
- docker.env
88
volumes:
9-
- federatedcode_db_data:/var/lib/postgresql/data/
9+
- db_data:/var/lib/postgresql/data/
1010

11-
federatedcode:
11+
web:
1212
build: .
13-
command: /bin/sh -c "
14-
apt-get update && apt-get install -y gunicorn &&
15-
python manage.py collectstatic --no-input --verbosity 0 --clear &&
16-
python manage.py migrate &&
17-
gunicorn federatedcode.wsgi:application -u nobody -g nogroup --bind :8000 --timeout 600 --workers 8"
13+
command: wait-for-it --strict --timeout=60 db:5432 -- sh -c "
14+
./manage.py migrate &&
15+
./manage.py collectstatic --no-input --verbosity 0 --clear &&
16+
gunicorn federatedcode.wsgi:application --bind :8000 --timeout 600 --workers 8"
1817
env_file:
1918
- docker.env
2019
expose:
2120
- 8000
22-
ports:
23-
- "8000:8000"
2421
volumes:
25-
- static:/var/federatedcode/static/
2622
- /etc/federatedcode/:/etc/federatedcode/
23+
- static:/var/federatedcode/static/
24+
- workspace:/var/federatedcode/workspace/
2725
depends_on:
28-
- federatedcode_db
26+
- db
2927

30-
federatedcode_nginx:
28+
nginx:
3129
image: nginx
30+
ports:
31+
- 80:80
32+
- 443:443
3233
env_file:
3334
- docker.env
3435
volumes:
35-
- ./etc/nginx/conf.d/:/etc/nginx/conf.d
36+
- ./etc/nginx/conf.d/:/etc/nginx/conf.d/
37+
- static:/var/federatedcode/static/
38+
- /var/www/html:/var/www/html
3639
depends_on:
37-
- federatedcode
40+
- web
3841

3942
volumes:
40-
federatedcode_db_data:
41-
federatedcode_static:
42-
federatedcode:
43-
43+
db_data:
44+
static:
45+
workspace:

docker.env

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
FEDERATEDCODE_WORKSPACE_LOCATION=/var/federatedcode
1+
POSTGRES_DB=federatedcode
2+
POSTGRES_USER=federatedcode
3+
POSTGRES_PASSWORD=federatedcode
4+
5+
FEDERATEDCODE_DB_HOST=db
6+
FEDERATEDCODE_STATIC_ROOT=/var/federatedcode/static/
7+
8+
FEDERATEDCODE_WORKSPACE_LOCATION=/var/federatedcode/workspace/
29
FEDERATEDCODE_CLIENT_ID=""
310
FEDERATEDCODE_CLIENT_SECRET=""
4-
NGINX_PORT=8080

docs/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "federatedcode.settings")
1717
os.environ.setdefault("SECRET_KEY", "dummy secret key for autodoc rtd documentation")
1818
os.environ.setdefault("FEDERATEDCODE_CLIENT_ID", "dummy secret key for autodoc rtd documentation")
19-
os.environ.setdefault("FEDERATEDCODE_CLIENT_SECRET", "dummy secret key for autodoc rtd documentation")
19+
os.environ.setdefault(
20+
"FEDERATEDCODE_CLIENT_SECRET", "dummy secret key for autodoc rtd documentation"
21+
)
2022

2123
sys.path.insert(0, os.path.abspath("../../."))
2224

etc/nginx/conf.d/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
upstream gunicorn_app {
2-
server federatedcode:8000;
2+
server web:8000;
33
}
44

55
server {

federatedcode/settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See https://github.com/nexB/federatedcode for support or download.
77
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
88
#
9-
import os
9+
1010
import sys
1111
from pathlib import Path
1212

@@ -30,8 +30,7 @@
3030
SECRET_KEY = env.str("SECRET_KEY")
3131

3232
ALLOWED_HOSTS = env.list(
33-
"ALLOWED_HOSTS",
34-
default=[".localhost", "127.0.0.1", "[::1]", "host.docker.internal"],
33+
"ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "[::1]", "host.docker.internal"]
3534
)
3635

3736
CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", default=[])

0 commit comments

Comments
 (0)