Skip to content

Commit 4b3eb4d

Browse files
Poleg lokalne namestitve omogočil še Docker (#70)
Co-authored-by: Matija Pretnar <matija@pretnar.info>
1 parent 7554a7a commit 4b3eb4d

File tree

16 files changed

+132
-114
lines changed

16 files changed

+132
-114
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 54 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2-
// https://github.com/microsoft/vscode-dev-containers/tree/v0.101.0/containers/python-3
31
{
42
"name": "Nadlogar",
5-
"context": "..",
6-
"dockerFile": "Dockerfile",
7-
// Set *default* container specific settings.json values on container create.
3+
"dockerComposeFile": [
4+
"../docker-compose.yml",
5+
"docker-compose.yml"
6+
],
7+
"service": "web",
8+
"workspaceFolder": "/workspace",
89
"settings": {
910
"[python]": {
1011
"editor.codeActionsOnSave": {
@@ -14,10 +15,10 @@
1415
},
1516
"python.pythonPath": "/usr/local/bin/python",
1617
"python.analysis.extraPaths": [
17-
"nadlogar"
18+
"/src"
1819
],
1920
"python.autoComplete.extraPaths": [
20-
"nadlogar"
21+
"/src"
2122
],
2223
"python.formatting.provider": "black",
2324
"editor.formatOnSave": true,
@@ -31,17 +32,10 @@
3132
"python.sortImports.args": [
3233
"--profile",
3334
"black"
34-
],
35+
]
3536
},
36-
// Add the IDs of extensions you want installed when the container is created.
3737
"extensions": [
38-
"ms-python.python",
39-
"ms-python.vscode-pylance"
40-
]
41-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
42-
// "forwardPorts": [],
43-
// Use 'postCreateCommand' to run commands after the container is created.
44-
// "postCreateCommand": "pip install -r requirements.txt",
45-
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
46-
// "remoteUser": "vscode"
38+
"ms-python.python"
39+
],
40+
"remoteUser": "nadlogar"
4741
}

.devcontainer/docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: "3"
2+
3+
services:
4+
web:
5+
volumes:
6+
- .:/workspace:cached
7+
- ./nadlogar:/src:cached

.github/workflows/django.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@ on: [ push, pull_request ]
44

55
jobs:
66
build:
7-
7+
env:
8+
POSTGRES_VERSION: 12
9+
POSTGRES_DB: postgres
10+
POSTGRES_USER: postgres
11+
POSTGRES_PASSWORD: postgres
12+
HTTP_PORT: 8001
13+
ALLOWED_HOSTS: 127.0.0.1
14+
SECRET_KEY: t2-r&t0yj0b%q$b^@ptqya=13mq0rsz1_5&h^ub-=+(ueiqsql
15+
DJANGO_SETTINGS_MODULE: config.settings.docker
816
runs-on: ubuntu-latest
9-
strategy:
10-
max-parallel: 4
11-
matrix:
12-
python-version: [3.6, 3.7, 3.8]
13-
1417
steps:
1518
- uses: actions/checkout@v2
16-
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v1
18-
with:
19-
python-version: ${{ matrix.python-version }}
20-
- name: Install Dependencies
19+
- name: Pull Images
20+
run: |
21+
docker compose pull
22+
- uses: satackey/action-docker-layer-caching@v0.0.11
23+
continue-on-error: true
24+
- name: Build Containers
2125
run: |
22-
python -m pip install --upgrade pip
23-
pip install -r nadlogar/requirements.txt
24-
pip install black
26+
docker compose build
2527
- name: Run Tests
2628
run: |
27-
python nadlogar/manage.py test nadlogar
29+
docker compose run web python manage.py test .
2830
- name: Run Black
2931
run: |
30-
python -m black --check .
32+
docker compose run web python -m black --check .

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3"
2+
3+
services:
4+
db:
5+
image: postgres:${POSTGRES_VERSION}
6+
restart: always
7+
volumes:
8+
- ./data/db:/var/lib/postgresql/data
9+
environment:
10+
- POSTGRES_DB
11+
- POSTGRES_USER
12+
- POSTGRES_PASSWORD
13+
web:
14+
build: nadlogar
15+
restart: always
16+
ports:
17+
- "${HTTP_PORT}:8000"
18+
depends_on:
19+
- db
20+
environment:
21+
- DJANGO_SETTINGS_MODULE
22+
- ALLOWED_HOSTS
23+
- SECRET_KEY
24+
- POSTGRES_DB
25+
- POSTGRES_USER
26+
- POSTGRES_PASSWORD

example.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POSTGRES_VERSION=12
2+
POSTGRES_DB=postgres
3+
POSTGRES_USER=postgres
4+
POSTGRES_PASSWORD=postgres
5+
HTTP_PORT=8000
6+
ALLOWED_HOSTS=127.0.0.1
7+
SECRET_KEY=t2-r&t0yj0b%q$b^@ptqya=13mq0rsz1_5&h^ub-=+(ueiqsql
8+
DJANGO_SETTINGS_MODULE=config.settings.docker

nadlogar/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3
2+
ENV PYTHONUNBUFFERED=1
3+
RUN apt-get update && apt-get install -y texlive texlive-fonts-extra
4+
WORKDIR /src
5+
RUN groupadd -g 1000 nadlogar && useradd -m -u 1000 -g nadlogar nadlogar -s /bin/bash
6+
COPY requirements /src/requirements
7+
RUN pip install --no-cache-dir -r requirements/docker.txt
8+
COPY . /src/
9+
RUN chown -R nadlogar /src
10+
USER nadlogar
11+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

nadlogar/config/settings/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,15 @@
1010
https://docs.djangoproject.com/en/3.2/ref/settings/
1111
"""
1212

13+
import os
1314
from pathlib import Path
1415

1516
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16-
BASE_DIR = Path(__file__).resolve().parent.parent
17-
17+
BASE_DIR = Path(__file__).resolve().parent.parent.parent
1818

1919
# Quick-start development settings - unsuitable for production
2020
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
2121

22-
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = "t2-r&t0yj0b%q$b^@ptqya=13mq0rsz1_5&h^ub-=+(ueiqsql"
24-
25-
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
27-
28-
ALLOWED_HOSTS = []
29-
30-
3122
# Application definition
3223

3324
INSTALLED_APPS = [
@@ -75,17 +66,6 @@
7566
WSGI_APPLICATION = "config.wsgi.application"
7667

7768

78-
# Database
79-
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
80-
81-
DATABASES = {
82-
"default": {
83-
"ENGINE": "django.db.backends.sqlite3",
84-
"NAME": BASE_DIR / "db.sqlite3",
85-
}
86-
}
87-
88-
8969
# Password validation
9070
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
9171

nadlogar/config/settings/docker.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from .common import *
2+
import os
3+
4+
# SECURITY WARNING: keep the secret key used in production secret!
5+
SECRET_KEY = os.environ["SECRET_KEY"]
6+
7+
# SECURITY WARNING: don't run with debug turned on in production!
8+
DEBUG = True
9+
10+
ALLOWED_HOSTS = [os.environ["ALLOWED_HOSTS"]]
11+
12+
# Database
13+
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
14+
15+
DATABASES = {
16+
"default": {
17+
"ENGINE": "django.db.backends.postgresql",
18+
"NAME": os.environ["POSTGRES_DB"],
19+
"USER": os.environ["POSTGRES_USER"],
20+
"PASSWORD": os.environ["POSTGRES_PASSWORD"],
21+
"HOST": "db",
22+
"PORT": "5432",
23+
}
24+
}

0 commit comments

Comments
 (0)