Merge branch 'dockerfile'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ mysite/__pycache__
|
||||
venv
|
||||
polls/__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:
|
||||
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:
|
||||
image: postgres
|
||||
image: postgres:14
|
||||
restart: always
|
||||
# set shared memory limit when using docker compose
|
||||
shm_size: 128mb
|
||||
@@ -10,15 +25,13 @@ services:
|
||||
# target: /dev/shm
|
||||
# tmpfs:
|
||||
# size: 134217728 # 128*2^20 bytes = 128Mb
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
container_name: postgres
|
||||
volumes:
|
||||
- pg-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_USER: sa
|
||||
POSTGRES_PASSWORD: example
|
||||
POSTGRES_PORT: 5432
|
||||
|
||||
adminer:
|
||||
image: adminer
|
||||
restart: always
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
pg-data:
|
||||
|
||||
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
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
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/
|
||||
|
||||
# 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!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
ALLOWED_HOSTS = ["localhost"]
|
||||
|
||||
|
||||
# Application definition
|
||||
@@ -78,11 +79,11 @@ WSGI_APPLICATION = "mysite.wsgi.application"
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql",
|
||||
"OPTIONS": {
|
||||
"service": "my_service",
|
||||
"passfile": ".pgpass",
|
||||
},
|
||||
"PASSWORD":"example",
|
||||
'NAME': os.getenv('DATABASE_NAME', 'sa'),
|
||||
'USER': os.getenv('DATABASE_USERNAME', 'sa'),
|
||||
"PASSWORD": os.getenv('DATABASE_PASSWORD', "example"),
|
||||
'HOST': os.getenv('DATABASE_HOST', 'db'),
|
||||
'PORT': os.getenv('DATABASE_PORT', 5432),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,20 @@ li a {
|
||||
}
|
||||
|
||||
body {
|
||||
background: white url("images/background.jpg") no-repeat;
|
||||
background: white;
|
||||
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' %}">
|
||||
|
||||
<h1>Different votes</h1>
|
||||
|
||||
{% if latest_question_list %}
|
||||
<div>
|
||||
<ul>
|
||||
{% for question in latest_question_list %}
|
||||
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>No polls are available.</p>
|
||||
{% endif %}
|
||||
|
||||
@@ -2,5 +2,8 @@ asgiref==3.8.1
|
||||
Django==5.2.1
|
||||
django-debug-toolbar==5.2.0
|
||||
pip==23.0.1
|
||||
psycopg==3.2.9
|
||||
psycopg-binary==3.2.9
|
||||
setuptools==66.1.1
|
||||
sqlparse==0.5.3
|
||||
typing_extensions==4.14.0
|
||||
|
||||
Reference in New Issue
Block a user