Skip to content

Commit

Permalink
Merge pull request #328 from warsztatywww/solutions
Browse files Browse the repository at this point in the history
Implement solution uploads
  • Loading branch information
cytadela8 authored Feb 24, 2021
2 parents 129e43f + 6cc782f commit ccbb3fa
Show file tree
Hide file tree
Showing 30 changed files with 1,170 additions and 272 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
media
uploads
htmlcov
.mypy_cache
venv
database.sqlite3
.env
.coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local_settings.py
db.sqlite3
db.sqlite3-journal
/media
/uploads

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
Expand Down
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM node:current-alpine AS build_frontend
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci
COPY webpack.config.js .
COPY frontend ./frontend
RUN npm run build



FROM python:alpine
WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev libffi-dev zlib-dev jpeg-dev

RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN pip install gunicorn

COPY . .
COPY --from=build_frontend /app/static/dist static/dist

RUN echo "import os" > wwwapp/local_settings.py
RUN echo "SECRET_KEY = os.environ['SECRET_KEY']" >> wwwapp/local_settings.py
RUN echo "ALLOWED_HOSTS = ['*']" >> wwwapp/local_settings.py
RUN echo "DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'HOST': 'db', 'NAME': 'aplikacjawww', 'USER': 'app', 'PASSWORD': 'app'}}" >> wwwapp/local_settings.py
RUN echo "GOOGLE_ANALYTICS_KEY = None" >> wwwapp/local_settings.py
RUN echo "MEDIA_ROOT = os.environ['MEDIA_ROOT']" >> wwwapp/local_settings.py
RUN echo "SENDFILE_ROOT = os.environ['SENDFILE_ROOT']" >> wwwapp/local_settings.py
RUN echo "USE_X_FORWARDED_HOST = True" >> wwwapp/local_settings.py
RUN echo "SESSION_COOKIE_SECURE = False" >> wwwapp/local_settings.py
RUN echo "CSRF_COOKIE_SECURE = False" >> wwwapp/local_settings.py

CMD gunicorn wwwapp.wsgi:application --bind 0.0.0.0:8000
ENTRYPOINT ["./entrypoint.sh"]
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '3.7'

services:
django:
build: .
volumes:
- static_volume:/usr/src/static
- media_volume:/usr/src/media
- uploads_volume:/usr/src/uploads
expose:
- 8000
environment:
- DJANGO_SETTINGS_MODULE=wwwapp.settings_prod
- MEDIA_ROOT=/usr/src/media
- SENDFILE_ROOT=/usr/src/uploads
- SECRET_KEY=test123
- SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=${SOCIAL_AUTH_GOOGLE_OAUTH2_KEY}
- SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=${SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET}
- SOCIAL_AUTH_FACEBOOK_KEY=${SOCIAL_AUTH_FACEBOOK_KEY}
- SOCIAL_AUTH_FACEBOOK_SECRET=${SOCIAL_AUTH_FACEBOOK_SECRET}
depends_on:
- db
db:
image: postgres:alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=aplikacjawww
- POSTGRES_USER=app
- POSTGRES_PASSWORD=app
nginx:
image: nginx:alpine
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
- static_volume:/usr/share/nginx/static
- media_volume:/usr/share/nginx/media
- uploads_volume:/usr/share/nginx/uploads
- ${INTERNETY:-/dev/null}:/usr/share/nginx/internet
ports:
- 8000:8000
depends_on:
- django

volumes:
postgres_data:
static_volume:
media_volume:
uploads_volume:
14 changes: 14 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

echo "Collecting static files"
rm -rf /usr/src/static/*
python manage.py collectstatic

echo "Waiting for postgres..."
while ! nc -z db 5432; do
sleep 0.1
done
echo "PostgreSQL started"
python manage.py migrate

exec "$@"
35 changes: 14 additions & 21 deletions frontend/css/custom-bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,24 @@ legend {
}

/* Status page */
@media (max-width: 1199px) {
.small-on-md {
font-size: 65%;
}
@include media-breakpoint-down(md) {
.small-on-md {
font-size: 65%;
}
}

@include media-breakpoint-down(sm) {
.w-100-on-sm {
width: 100%;
}
}

/* Program */
.btn-circle {
width: 30px;
height: 30px;
text-align: center;
padding: 6px 0;
font-size: 12px;
line-height: 1.428571429;
border-radius: 15px;
}

.btn-circle.btn-m {
width: 50px;
height: 50px;
padding: 8px 12px;
font-size: 20px;
line-height: 1.2;
border-radius: 28px;
color: white !important;
width: 50px;
height: 50px;
border-radius: 25px;
color: white !important;
}

/* Sticky footer styles */
Expand Down
4 changes: 2 additions & 2 deletions frontend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'bootstrap/dist/js/bootstrap.js';
// Font Awesome
// Explicitly specify the used icons to make the bundle size smaller
import { library, dom } from "@fortawesome/fontawesome-svg-core";
import { faCheckCircle, faTimesCircle, faMinusCircle, faExclamationCircle, faQuestionCircle, faPlus, faMinus, faCheck, faHome, faFile, faPencilAlt, faSignOutAlt, faEye, faEyeSlash, faColumns, faCopy, faFileExcel, faFilePdf, faPrint, faSave, faCloudUploadAlt } from "@fortawesome/free-solid-svg-icons";
library.add(faCheckCircle, faTimesCircle, faMinusCircle, faExclamationCircle, faQuestionCircle, faPlus, faMinus, faCheck, faHome, faFile, faPencilAlt, faSignOutAlt, faEye, faEyeSlash, faColumns, faCopy, faFileExcel, faFilePdf, faPrint, faSave, faCloudUploadAlt);
import { faCheckCircle, faTimesCircle, faMinusCircle, faExclamationCircle, faQuestionCircle, faPlus, faMinus, faCheck, faHome, faFile, faPencilAlt, faSignOutAlt, faEye, faEyeSlash, faColumns, faCopy, faFileExcel, faFilePdf, faPrint, faSave, faCloudUploadAlt, faPaperPlane, faTasks } from "@fortawesome/free-solid-svg-icons";
library.add(faCheckCircle, faTimesCircle, faMinusCircle, faExclamationCircle, faQuestionCircle, faPlus, faMinus, faCheck, faHome, faFile, faPencilAlt, faSignOutAlt, faEye, faEyeSlash, faColumns, faCopy, faFileExcel, faFilePdf, faPrint, faSave, faCloudUploadAlt, faPaperPlane, faTasks);
dom.watch();


Expand Down
3 changes: 2 additions & 1 deletion frontend/js/warsztatywww.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ window.handle_registration_change = function(workshop_name_txt, register) {
window.location.href = json.redirect;
}
if (json.content) {
$("#" + workshop_name_txt).find(".button-div").replaceWith(json.content);
$("#" + workshop_name_txt).replaceWith(json.content);
$("#" + workshop_name_txt).find('.enable-tooltip').tooltip();
}
},
error: function(xhr, errmsg, errcode) {
Expand Down
74 changes: 74 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ResourceYearPermission config example:
# display_name=Internet WWW11, access_url=http://localhost:8080/internet/www11, path=internet/www11, year=2015

server {
listen 8000;
listen [::]:8000;
server_name localhost;

client_max_body_size 32M;

location / {
proxy_pass http://django:8000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location = /resource_auth/ {
internal; # disallow external access to this endpoint
proxy_pass http://django:8000/resource_auth/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Original-URI $request_uri;
proxy_set_header Content-Length "";
proxy_pass_request_body off;
}
}

location /static {
alias /usr/share/nginx/static/;
}

location /media {
alias /usr/share/nginx/media/;
}

location /uploads {
internal; # only allow access through X-Accel-Redirect
alias /usr/share/nginx/uploads/;
}

location /internet {
alias /usr/share/nginx/internet/;
index index.html index.htm;
autoindex on;

auth_request /resource_auth/;
error_page 403 =200 /login/;
disable_symlinks on;

# Earlier internets don't have any specific configuration

location /internet/www14/ {
# We need to fix the paths because a lot of things were specified relative to / ¯\_(ツ)_/¯
sub_filter 'href="/' 'href="/internet/www14/';
sub_filter 'src="/' 'src="/internet/www14/';
sub_filter 'href=\\"/' 'href=\\"/internet/www14/';
sub_filter 'src=\\"/' 'src=\\"/internet/www14/';
sub_filter 'Index of /internet/www14/' 'Index of /'; # required for the scripts to correctly detect the root index page
sub_filter_once off;
sub_filter_types text/plain; # text/html is always included, but we also need to process the cancer1.txt and cancer2.txt files

# Our magical header/footer config
location ~* ^/internet/www14.*/$ {
add_before_body /internet/www14/cancer1.txt;
add_after_body /internet/www14/cancer2.txt;
}
}

# I don't have WWW15 files to test but it will be almost identical to WWW14
}
}
85 changes: 0 additions & 85 deletions nginx.conf.example

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ django-crispy-forms==1.11.0
django-tinymce==3.2.0
django-bleach==0.6.1
django-cleanup==5.1.0
django-sendfile2==0.6.0
django-debug-toolbar==3.2
django-select2==7.6.1
social-auth-app-django==4.0.0
Expand Down
Loading

0 comments on commit ccbb3fa

Please sign in to comment.