Merge branch 'dockerfile'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ mysite/__pycache__
|
|||||||
venv
|
venv
|
||||||
polls/__pycache__
|
polls/__pycache__
|
||||||
polls/migrations/__pycache__
|
polls/migrations/__pycache__
|
||||||
|
.env
|
||||||
|
|||||||
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
FROM python:3.11-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
COPY ./mysite ./mysite
|
||||||
|
COPY ./polls ./polls
|
||||||
|
COPY ./manage.py .
|
||||||
|
|
||||||
|
RUN ./manage.py makemigrations
|
||||||
|
# RUN ./manage.py migrate
|
||||||
|
|
||||||
|
COPY docker-entrypoint.sh .
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD [ "./docker-entrypoint.sh" ]
|
||||||
31
compose.yaml
31
compose.yaml
@@ -1,6 +1,21 @@
|
|||||||
services:
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
container_name: django-app
|
||||||
|
ports:
|
||||||
|
- "80:8000"
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
environment:
|
||||||
|
DATABASE_NAME: ${DATABASE_NAME}
|
||||||
|
DATABASE_USERNAME: ${DATABASE_USERNAME}
|
||||||
|
DATABASE_HOST: ${DATABASE_HOST}
|
||||||
|
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
|
||||||
|
DATABASE_PORT: ${DATABASE_PORT}
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
db:
|
db:
|
||||||
image: postgres
|
image: postgres:14
|
||||||
restart: always
|
restart: always
|
||||||
# set shared memory limit when using docker compose
|
# set shared memory limit when using docker compose
|
||||||
shm_size: 128mb
|
shm_size: 128mb
|
||||||
@@ -10,15 +25,13 @@ services:
|
|||||||
# target: /dev/shm
|
# target: /dev/shm
|
||||||
# tmpfs:
|
# tmpfs:
|
||||||
# size: 134217728 # 128*2^20 bytes = 128Mb
|
# size: 134217728 # 128*2^20 bytes = 128Mb
|
||||||
ports:
|
container_name: postgres
|
||||||
- "5432:5432"
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: sa
|
POSTGRES_USER: sa
|
||||||
POSTGRES_PASSWORD: example
|
POSTGRES_PASSWORD: example
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
|
||||||
adminer:
|
volumes:
|
||||||
image: adminer
|
pg-data:
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
|
|||||||
13
docker-entrypoint.sh
Executable file
13
docker-entrypoint.sh
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Collect static files
|
||||||
|
echo "Collect static files"
|
||||||
|
python manage.py collectstatic --noinput
|
||||||
|
|
||||||
|
# Apply database migrations
|
||||||
|
echo "Apply database migrations"
|
||||||
|
python manage.py migrate
|
||||||
|
|
||||||
|
# Start server
|
||||||
|
echo "Starting server"
|
||||||
|
python manage.py runserver 0.0.0.0:8000
|
||||||
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
@@ -20,12 +21,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = "django-insecure-7@a)l@%smekjdwtc%$)k=qs^5k8@fnmc+vxk)(!mi5ojrbhgn+"
|
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = ["localhost"]
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
@@ -78,11 +79,11 @@ WSGI_APPLICATION = "mysite.wsgi.application"
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
"OPTIONS": {
|
'NAME': os.getenv('DATABASE_NAME', 'sa'),
|
||||||
"service": "my_service",
|
'USER': os.getenv('DATABASE_USERNAME', 'sa'),
|
||||||
"passfile": ".pgpass",
|
"PASSWORD": os.getenv('DATABASE_PASSWORD', "example"),
|
||||||
},
|
'HOST': os.getenv('DATABASE_HOST', 'db'),
|
||||||
"PASSWORD":"example",
|
'PORT': os.getenv('DATABASE_PORT', 5432),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,20 @@ li a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background: white url("images/background.jpg") no-repeat;
|
background: white;
|
||||||
background-position: top;
|
background-position: top;
|
||||||
|
font-size: 200%;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
ul {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
<link rel="stylesheet" href="{% static 'polls/style.css' %}">
|
<link rel="stylesheet" href="{% static 'polls/style.css' %}">
|
||||||
|
|
||||||
|
<h1>Different votes</h1>
|
||||||
|
|
||||||
{% if latest_question_list %}
|
{% if latest_question_list %}
|
||||||
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
{% for question in latest_question_list %}
|
{% for question in latest_question_list %}
|
||||||
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
|
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No polls are available.</p>
|
<p>No polls are available.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -2,5 +2,8 @@ asgiref==3.8.1
|
|||||||
Django==5.2.1
|
Django==5.2.1
|
||||||
django-debug-toolbar==5.2.0
|
django-debug-toolbar==5.2.0
|
||||||
pip==23.0.1
|
pip==23.0.1
|
||||||
|
psycopg==3.2.9
|
||||||
|
psycopg-binary==3.2.9
|
||||||
setuptools==66.1.1
|
setuptools==66.1.1
|
||||||
sqlparse==0.5.3
|
sqlparse==0.5.3
|
||||||
|
typing_extensions==4.14.0
|
||||||
|
|||||||
Reference in New Issue
Block a user