Compare commits
10 Commits
6b635955eb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e0675c8684 | |||
| 4b18769137 | |||
| 90b7bb0dee | |||
| 8cfe5c6f9b | |||
| 9397c2d4f2 | |||
| 313702f9fe | |||
|
|
49199b7184 | ||
|
|
c17e3e85f2 | ||
|
|
be54afa093 | ||
|
|
fd5414bd5a |
@@ -1,6 +1,6 @@
|
||||
services:
|
||||
web:
|
||||
command: gunicorn -b 0.0.0.0:8000 website.wsgi:application
|
||||
command: gunicorn --capture-output --enable-stdio-inheritance -b 0.0.0.0:8000 website.wsgi:application
|
||||
volumes:
|
||||
- ./src:/src
|
||||
env_file:
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#NGINX
|
||||
NGINX_HOSTNAME=localhost
|
||||
|
||||
# Django
|
||||
DJANGO_SETTINGS_MODULE=website.settings
|
||||
DJANGO_SECRET_KEY=CWHZCAZBNV57tDkwGHJwTUu3PCSnGG45
|
||||
DEBUG=TRUE
|
||||
ALLOWED_HOSTS=localhost
|
||||
#ALLOWED_HOSTS=localhost
|
||||
|
||||
# Database (PostgreSQL)
|
||||
POSTGRES_USER=test_user
|
||||
|
||||
@@ -3,7 +3,6 @@ run-name: ${{ gitea.actor }}
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- pre-prod
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
|
||||
17
.gitea/workflows/test.yaml
Normal file
17
.gitea/workflows/test.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Gitea Test.
|
||||
run-name: ${{ gitea.actor }}
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- pre-prod
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: test
|
||||
run: make test
|
||||
16
Makefile
16
Makefile
@@ -1,6 +1,6 @@
|
||||
prod:
|
||||
docker compose down
|
||||
docker compose -f ./compose.yaml -f ./.docker-compose-files/compose.prod.yaml up -d --build
|
||||
docker compose --env-file .env -f ./compose.yaml -f ./.docker-compose-files/compose.prod.yaml up -d --build
|
||||
docker exec quatsh-website-web-1 python manage.py collectstatic --noinput
|
||||
docker exec quatsh-website-web-1 python manage.py check --deploy
|
||||
docker exec quatsh-website-web-1 python manage.py migrate
|
||||
@@ -11,6 +11,16 @@ dev:
|
||||
docker exec quatsh-website-web-1 python manage.py collectstatic --noinput
|
||||
docker exec -it quatsh-website-web-1 sh
|
||||
|
||||
test:
|
||||
docker compose --env-file .env.template -f ./compose.yaml -f ./.docker-compose_files up --build --abort-on-container-exit --exit-code-from web
|
||||
dev_restart:
|
||||
docker compose down
|
||||
docker compose -f ./compose.yaml -f ./.docker-compose-files/compose.dev.yaml up -d
|
||||
docker exec -it quatsh-website-web-1 sh
|
||||
|
||||
dev_restart_with_logs:
|
||||
docker compose down
|
||||
docker compose -f ./compose.yaml -f ./.docker-compose-files/compose.dev.yaml up
|
||||
|
||||
|
||||
test:
|
||||
docker compose --env-file .env.template -f ./compose.yaml -f ./.docker-compose-files/compose.test.yaml up --build --abort-on-container-exit --exit-code-from web
|
||||
|
||||
|
||||
39
README.md
39
README.md
@@ -1,44 +1,65 @@
|
||||
# Quatsh-Website
|
||||
|
||||
## Requirements:
|
||||
## Requirements
|
||||
|
||||
### Install make
|
||||
|
||||
Running this requires the use of "make" and docker.
|
||||
|
||||
"make" tends to come pre-installed on linux but not on Windows, to install it on Windows I recommend using Chocolatey as follows: \
|
||||
|
||||
```
|
||||
choco install make
|
||||
```
|
||||
|
||||
### Install docker
|
||||
https://docs.docker.com/get-started/get-docker/
|
||||
|
||||
<https://docs.docker.com/get-started/get-docker/>
|
||||
|
||||
## Running for the first time
|
||||
|
||||
### Env
|
||||
|
||||
Before running the container environment has to be setup first, so first run:
|
||||
|
||||
```
|
||||
cp .env.template .env
|
||||
```
|
||||
Then make any nessecary adjustments to the .env file.
|
||||
|
||||
### Running the website:
|
||||
Then make any changes to the .env file.
|
||||
|
||||
### Running the website
|
||||
|
||||
To run the website 3 options have been provided
|
||||
#### Development:
|
||||
|
||||
#### Development
|
||||
|
||||
For development purposes only as the src folder has been mounted in the container to allow for the making of changes without rebuilding the entire image.
|
||||
```
|
||||
Properly utilising this also requires the DEBUG environment variable to be set to TRUE.
|
||||
|
||||
```shell
|
||||
make dev
|
||||
```
|
||||
|
||||
#### Testing
|
||||
|
||||
Runs the testing environment and exits.
|
||||
```
|
||||
|
||||
```shell
|
||||
make test
|
||||
```
|
||||
|
||||
#### Production
|
||||
|
||||
Using `make prod` is identical but preferred here.
|
||||
```
|
||||
|
||||
```shell
|
||||
make prod
|
||||
# or
|
||||
```
|
||||
|
||||
Or
|
||||
|
||||
```shell
|
||||
make
|
||||
```
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Django==6.0.3
|
||||
gunicorn==25.1.0
|
||||
psycopg [binary] ==3.3.3
|
||||
django-browser-reload
|
||||
django-watchfiles
|
||||
|
||||
11
src/polls/templates/polls/detail.html
Normal file
11
src/polls/templates/polls/detail.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>My test page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hey This is a test of watchfiles + browser reload!</h1>
|
||||
{{ question }}
|
||||
</body>
|
||||
</html>
|
||||
19
src/polls/templates/polls/index.html
Normal file
19
src/polls/templates/polls/index.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>My test page</title>
|
||||
</head>
|
||||
<body>
|
||||
{% if latest_question_list %}
|
||||
<ul>
|
||||
{% for question in latest_question_list %}
|
||||
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No polls are available.</p>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,5 +3,12 @@ from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
# ex: /polls/
|
||||
path("", views.index, name="index"),
|
||||
# ex: /polls/5/
|
||||
path("<int:question_id>/", views.detail, name="detail"),
|
||||
# ex: /polls/5/results/
|
||||
path("<int:question_id>/results/", views.results, name="results"),
|
||||
# ex: /polls/5/vote/
|
||||
path("<int:question_id>/vote/", views.vote, name="vote"),
|
||||
]
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from .models import Question
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("Hello, world. You're at the polls index.")
|
||||
latest_question_list = Question.objects.order_by("-pub_date")[:5]
|
||||
context = {"latest_question_list": latest_question_list}
|
||||
return render(request, "polls/index.html", context)
|
||||
|
||||
|
||||
# Create your views here.
|
||||
def detail(request, question_id):
|
||||
question = get_object_or_404(Question, pk=question_id)
|
||||
return render(request, "polls/detail.html", {"question": question})
|
||||
|
||||
|
||||
def results(request, question_id):
|
||||
response = "You're looking at the results of question %s."
|
||||
return HttpResponse(response % question_id)
|
||||
|
||||
|
||||
def vote(request, question_id):
|
||||
return HttpResponse("You're voting on question %s." % question_id)
|
||||
|
||||
@@ -40,6 +40,8 @@ INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django_browser_reload",
|
||||
"django_watchfiles",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -50,6 +52,7 @@ MIDDLEWARE = [
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"django_browser_reload.middleware.BrowserReloadMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "website.urls"
|
||||
|
||||
@@ -19,6 +19,7 @@ from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path("__reload__/", include("django_browser_reload.urls")),
|
||||
path("polls/", include("polls.urls")),
|
||||
path("admin/", admin.site.urls),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user