First commit
This commit is contained in:
commit
17e952bdbd
11
Caddyfile
Normal file
11
Caddyfile
Normal file
@ -0,0 +1,11 @@
|
||||
http://api.localhost
|
||||
|
||||
root * /usr/src/app/
|
||||
|
||||
@notStatic {
|
||||
not path /static/* /media/*
|
||||
}
|
||||
|
||||
reverse_proxy @notStatic django:8000
|
||||
|
||||
file_server
|
21
Dockerfiles/django/Dockerfile
Normal file
21
Dockerfiles/django/Dockerfile
Normal file
@ -0,0 +1,21 @@
|
||||
FROM debian:stable-slim
|
||||
|
||||
ENV PYTHONUNBUFFERED: 1
|
||||
|
||||
# set work directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# install software
|
||||
RUN apt update
|
||||
RUN apt install -y build-essential cron python3-pip gettext
|
||||
|
||||
# install dependencies
|
||||
RUN pip3 install --upgrade pip
|
||||
COPY ./requirements.txt .
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
# launcher
|
||||
COPY django-launcher.dev.sh /django-launcher.dev.sh
|
||||
COPY django-launcher.pro.sh /django-launcher.pro.sh
|
||||
RUN chmod +x /django-launcher.dev.sh
|
||||
RUN chmod +x /django-launcher.pro.sh
|
19
Dockerfiles/gulp/Dockerfile
Normal file
19
Dockerfiles/gulp/Dockerfile
Normal file
@ -0,0 +1,19 @@
|
||||
FROM debian:unstable-slim
|
||||
|
||||
# set work directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# install software
|
||||
RUN apt update
|
||||
RUN apt -y upgrade
|
||||
# dependencies
|
||||
RUN apt install -y build-essential nodejs npm
|
||||
|
||||
# gulp
|
||||
RUN npm install -g gulp-cli
|
||||
|
||||
# Add package.json
|
||||
COPY package.json package.json
|
||||
|
||||
# dependencies gulp
|
||||
RUN npm i
|
80
README.md
Normal file
80
README.md
Normal file
@ -0,0 +1,80 @@
|
||||
# Install
|
||||
|
||||
## Django
|
||||
|
||||
https://programadorwebvalencia.com/django-chat-usando-websockets-con-salas-y-async/
|
||||
|
||||
## Gulp
|
||||
|
||||
```shell
|
||||
npm i
|
||||
```
|
||||
|
||||
Run.
|
||||
|
||||
```shell
|
||||
gulp dev
|
||||
```
|
||||
|
||||
# Config
|
||||
|
||||
## Change path templates
|
||||
|
||||
|
||||
In `settings.py`.
|
||||
|
||||
``` python
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
```
|
||||
|
||||
Update `DIRS`.
|
||||
|
||||
``` python
|
||||
'DIRS': [str(BASE_DIR) + '/app/templates/'],
|
||||
```
|
||||
|
||||
# Run development
|
||||
|
||||
``` sh
|
||||
docker-compose -f docker-compose.dev.yaml up
|
||||
```
|
||||
|
||||
Now open:
|
||||
|
||||
`http://api.localhost`
|
||||
|
||||
### Other domains
|
||||
|
||||
- Caddy: `http://api.localhost`.
|
||||
- Gulp: `http://localhost:3000`.
|
||||
- Django: `http://localhost:8000`.
|
||||
- Mailhog: `http://localhost:8025`.
|
||||
- Postgres: `localhost:5432`.
|
||||
|
||||
### Bash Django
|
||||
|
||||
``` shell
|
||||
docker exec -it api_django_1 bash
|
||||
```
|
||||
|
||||
# Run production
|
||||
|
||||
``` sh
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
Open `https://domain.com`.
|
11
asgi.py
Normal file
11
asgi.py
Normal file
@ -0,0 +1,11 @@
|
||||
import os
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||
import django
|
||||
|
||||
django.setup()
|
||||
|
||||
from channels.routing import ProtocolTypeRouter
|
||||
|
||||
|
||||
application = ProtocolTypeRouter({})
|
14
django-launcher.dev.sh
Normal file
14
django-launcher.dev.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Collect static files
|
||||
echo "Collect static files"
|
||||
python3 manage.py collectstatic --noinput
|
||||
|
||||
# Apply database migrations
|
||||
echo "Apply database migrations"
|
||||
python3 manage.py makemigrations
|
||||
python3 manage.py migrate
|
||||
|
||||
# Start server
|
||||
echo "Starting server"
|
||||
uvicorn --host 0.0.0.0 --port 8000 --reload chapps.asgi:application
|
14
django-launcher.pro.sh
Normal file
14
django-launcher.pro.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Collect static files
|
||||
echo "Collect static files"
|
||||
python3 manage.py collectstatic --noinput
|
||||
|
||||
# Apply database migrations
|
||||
echo "Apply database migrations"
|
||||
python3 manage.py makemigrations
|
||||
python3 manage.py migrate
|
||||
|
||||
# Start server
|
||||
echo "Starting server"
|
||||
uvicorn --host 0.0.0.0 --port 8000 chapps.asgi:application
|
66
docker-compose.dev.yaml
Normal file
66
docker-compose.dev.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
|
||||
db:
|
||||
image: postgres
|
||||
restart: always
|
||||
volumes:
|
||||
- ./../postgres_data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_DB: api
|
||||
POSTGRES_PASSWORD: postgres
|
||||
expose:
|
||||
- 5432
|
||||
|
||||
django:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Dockerfiles/django/Dockerfile
|
||||
restart: always
|
||||
entrypoint: /django-launcher.dev.sh
|
||||
volumes:
|
||||
- .:/usr/src/app/
|
||||
environment:
|
||||
DEBUG: "True"
|
||||
ALLOWED_HOSTS: ""
|
||||
SECRET_KEY: ""
|
||||
DB_HOST: db
|
||||
DB_NAME: ""
|
||||
DB_USER: "postgres"
|
||||
DB_PASSWORD: "postgres"
|
||||
DB_PORT: "5432"
|
||||
DOMAIN: "api.localhost"
|
||||
DOMAIN_URL: "http://api.localhost"
|
||||
STATIC_URL: "/static/"
|
||||
MEDIA_URL: "/media/"
|
||||
EMAIL_HOST: "mailhog"
|
||||
EMAIL_USE_TLS: "False"
|
||||
EMAIL_PORT: "1025"
|
||||
EMAIL_USER: ""
|
||||
EMAIL_PASSWORD: ""
|
||||
expose:
|
||||
- 8000
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
caddy:
|
||||
image: caddy:alpine
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
volumes:
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile
|
||||
- ./../caddy_data:/data
|
||||
- .:/usr/src/app/
|
||||
depends_on:
|
||||
- django
|
||||
|
||||
mailhog:
|
||||
image: mailhog/mailhog:latest
|
||||
restart: always
|
||||
expose:
|
||||
- 1025:1025
|
||||
ports:
|
||||
- 8025:8025
|
66
docker-compose.pro.yaml
Normal file
66
docker-compose.pro.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
|
||||
db:
|
||||
image: postgres
|
||||
restart: always
|
||||
volumes:
|
||||
- ./../postgres_data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_DB: guitarlions
|
||||
POSTGRES_PASSWORD: postgres
|
||||
expose:
|
||||
- 5432
|
||||
|
||||
django:
|
||||
build: .
|
||||
restart: always
|
||||
entrypoint: /django-launcher.pro.sh
|
||||
volumes:
|
||||
- .:/usr/src/app/
|
||||
environment:
|
||||
DEBUG: "False"
|
||||
ALLOWED_HOSTS: ""
|
||||
SECRET_KEY: "secret"
|
||||
DB_HOST: db
|
||||
DB_NAME: "guitarlions"
|
||||
DB_USER: "postgres"
|
||||
DB_PASSWORD: "postgres"
|
||||
DB_PORT: "5432"
|
||||
DOMAIN: ""
|
||||
DOMAIN_URL: "https://"
|
||||
STATIC_URL: "/static/"
|
||||
MEDIA_URL: "/media/"
|
||||
EMAIL_USE_TLS: True
|
||||
EMAIL_HOST: ""
|
||||
EMAIL_USE_TLS: "True"
|
||||
EMAIL_PORT: "2525"
|
||||
EMAIL_USER: ""
|
||||
EMAIL_PASSWORD: ""
|
||||
expose:
|
||||
- 8000
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
caddy:
|
||||
image: caddy:alpine
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
volumes:
|
||||
- .:/usr/src/app/
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile
|
||||
- ./../caddy_data:/data
|
||||
depends_on:
|
||||
- django
|
||||
|
||||
gulp:
|
||||
build: Dockerfiles/gulp
|
||||
restart: always
|
||||
command: gulp
|
||||
volumes:
|
||||
- .:/app/
|
||||
depends_on:
|
||||
- caddy
|
97
gulpfile.js
Normal file
97
gulpfile.js
Normal file
@ -0,0 +1,97 @@
|
||||
//===
|
||||
// IMPORTS
|
||||
//===
|
||||
const { src, dest, parallel, series, watch } = require('gulp');
|
||||
const browserSync = require('browser-sync').create();
|
||||
const clean = require('gulp-clean');
|
||||
const sass = require('gulp-sass');
|
||||
const sourcemaps = require('gulp-sourcemaps');
|
||||
const ts = require('gulp-typescript');
|
||||
const iconfont = require('gulp-iconfont');
|
||||
|
||||
//===
|
||||
// VARIABLES
|
||||
//===
|
||||
const runTimestamp = Math.round(Date.now() / 1000);
|
||||
const SRC_PATH = 'assets';
|
||||
const DEST_PATH = 'static';
|
||||
|
||||
//===
|
||||
// TASKS
|
||||
//===
|
||||
function cleanDist() {
|
||||
return src('static/*')
|
||||
.pipe(clean());
|
||||
}
|
||||
|
||||
// Static server with reload
|
||||
function initBrowserSync(cb) {
|
||||
browserSync.init({
|
||||
notify: false,
|
||||
open: false,
|
||||
proxy: 'http://localhost'
|
||||
});
|
||||
return cb;
|
||||
}
|
||||
|
||||
// Compile SASS + sourcemaps
|
||||
function sassCompile() {
|
||||
return src([SRC_PATH + "/sass/desktop.sass", SRC_PATH + "/sass/mobile.sass"])
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
|
||||
.pipe(sourcemaps.write('.'))
|
||||
.pipe(dest(DEST_PATH + '/css/'))
|
||||
.pipe(browserSync.stream()) ;
|
||||
}
|
||||
|
||||
// Compile Typescript to JavaScript
|
||||
function typescript() {
|
||||
return src(SRC_PATH +'/ts/*.ts')
|
||||
.pipe(ts({
|
||||
noImplicitAny: true,
|
||||
outFile: 'main.js'
|
||||
}))
|
||||
.pipe(dest('static/js'))
|
||||
.pipe(browserSync.stream()) ;
|
||||
}
|
||||
|
||||
// Copy images
|
||||
function images() {
|
||||
return src(SRC_PATH +'/img/**/*')
|
||||
.pipe(dest(DEST_PATH + '/img/'))
|
||||
.pipe(browserSync.stream()) ;
|
||||
}
|
||||
|
||||
// Build Font icons. *.svg to font-icons.woff2
|
||||
function buildFontIcons() {
|
||||
return src(SRC_PATH + '/fonts/icons/*.svg')
|
||||
.pipe(iconfont({
|
||||
fontName: 'font-icons',
|
||||
prependUnicode: true,
|
||||
formats: ['woff2'],
|
||||
timestamp: runTimestamp
|
||||
}))
|
||||
.pipe(dest(DEST_PATH + '/fonts/'))
|
||||
.pipe(browserSync.stream()) ;
|
||||
}
|
||||
|
||||
//===
|
||||
// Tasks
|
||||
//===
|
||||
|
||||
// Default: 'gulp'
|
||||
const build = series(
|
||||
cleanDist,
|
||||
parallel(sassCompile, typescript, images, buildFontIcons)
|
||||
);
|
||||
exports.default = build;
|
||||
|
||||
// Dev: 'gulp dev'
|
||||
exports.dev = function () {
|
||||
build();
|
||||
watch([SRC_PATH + '/sass/*.sass', SRC_PATH + '/sass/**/*.sass'], sassCompile);
|
||||
watch([SRC_PATH + '/ts/*.ts', SRC_PATH + '/ts/**/*.ts'], typescript);
|
||||
watch([SRC_PATH + '/img/*', SRC_PATH + '/img/**/*'], images);
|
||||
watch([SRC_PATH + '/fonts/icons/*.svg'], buildFontIcons);
|
||||
initBrowserSync();
|
||||
}
|
29
package.json
Normal file
29
package.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "web",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "gulpfile.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/sapps-studio/....git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/sapps-studio/.../issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/sapps-studio/...#readme",
|
||||
"dependencies": {
|
||||
"browser-sync": "^2.26.14",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-iconfont": "^11.0.0",
|
||||
"gulp-sass": "^4.1.0",
|
||||
"gulp-sourcemaps": "^3.0.0",
|
||||
"gulp-typescript": "*"
|
||||
}
|
||||
}
|
10
requirements.txt
Normal file
10
requirements.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Django
|
||||
django
|
||||
# Servidor para Django
|
||||
uvicorn
|
||||
# Conector para PostgreSQL
|
||||
psycopg2-binary
|
||||
# Channels
|
||||
channels==2.4.0
|
||||
# Conector de Redis para Channels
|
||||
channels_redis
|
Loading…
Reference in New Issue
Block a user