Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docker services #15

Merged
merged 7 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,19 @@ What we have as a repository is a monorepo containing the *dashboard* (the web a
A web app built with [React](https://react.dev/) + [Typescript](https://www.typescriptlang.org/), to see more information check the dashboard [README](dashboard/README.md).

### Backend
A Python http server built with [Django](https://www.djangoproject.com/) + [DRF](https://www.django-rest-framework.org/), to see more information check the backend [README](/backend/README.md).
A Python http server built with [Django](https://www.djangoproject.com/) + [DRF](https://www.django-rest-framework.org/), to see more information check the backend [README](/backend/README.md).


# Build

Create secret files:
```sh
mkdir -p backend/runtime/secrets
uuidgen > backend/runtime/secrets/postgres_password_secret
```

Startup the services with
```sh
docker compose up --build -d
```

4 changes: 3 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ ipython_config.py
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock
# poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down Expand Up @@ -171,3 +171,5 @@ cython_debug/
#.idea/

# End of https://www.toptal.com/developers/gitignore/api/django

runtime/
45 changes: 45 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# syntax=docker/dockerfile:1

# Create server docker image (all non-code dependencies)
FROM alpine:3.20 as backend-base

WORKDIR /

ENV POETRY_HOME=/opt/poetry

RUN apk update \
&& apk add --no-cache \
python3 \
python3-dev \
gcc \
libffi-dev \
libc-dev \
libpq-dev \
postgresql \
&& python3 -m venv $POETRY_HOME \
&& $POETRY_HOME/bin/pip install poetry==1.8.3 \
&& ln -s $POETRY_HOME/bin/poetry /bin/poetry

FROM backend-base
COPY . /backend
COPY ./utils/docker/entrypoint.sh /entrypoint.sh
WORKDIR /backend

RUN poetry install --no-interaction --no-dev

ENV DJANGO_APP="kernelCI"

# Precompile Python modules
RUN O='0 1 2' \
PY_MAJMIN=`poetry run python -c "import sys; print('%s.%s'%sys.version_info[0:2])"` \
PY_D=`poetry env info --path` \
D="$PY_D $DJANGO_APP"; \
for N in $O; do \
echo "compile python $PY_MAJMIN byte code at -O$N: $D"; \
PYTHONOPTIMIZE=$N poetry run python -m compileall -q $D || exit 1; \
done

EXPOSE 8000

CMD ["--workers=5", "--forwarded-allow-ips=*", "--bind=0.0.0.0:8000"]
ENTRYPOINT ["/entrypoint.sh"]
34 changes: 29 additions & 5 deletions backend/kernelCI/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
"""

from pathlib import Path
import os
import json


def get_json_env_var(name, default):
var = os.environ.get(name)
if not var:
return default
try:
return json.loads(var)
except json.JSONDecodeError:
if isinstance(default, str):
return var
raise


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -25,7 +40,10 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = get_json_env_var(
'ALLOWED_HOSTS',
['localhost'],
)


# Application definition
Expand Down Expand Up @@ -76,10 +94,16 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
"default": get_json_env_var("DB_DEFAULT", {
"ENGINE": "django.db.backends.postgresql",
"NAME": "kernelci",
"USER": "kernelci",
"PASSWORD": "kernelci-db-password",
"HOST": "127.0.0.1",
"OPTIONS": {
"connect_timeout": 5,
},
})
}


Expand Down
Loading
Loading