Skip to content

Commit

Permalink
Merge pull request #86 from uselotus/diego/docker-deployment
Browse files Browse the repository at this point in the history
docker deployment on Heroku
  • Loading branch information
diego-escobedo authored Sep 14, 2022
2 parents 89b1f3f + 8a70685 commit 25d550a
Show file tree
Hide file tree
Showing 126 changed files with 169 additions and 143 deletions.
48 changes: 48 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
#django
*.pyc
*.pyo
*.mo
*.db
*.css.map
*.egg-info
*.sql.gz
.cache
.project
.idea
.pydevproject
.idea/workspace.xml
.DS_Store
.git/
.sass-cache
.vagrant/
__pycache__
dist
docs
env
logs
src/{{ project_name }}/settings/local.py
src/node_modules
web/media
web/static/CACHE
stats
Dockerfile*
static/
frontend/
staticfiles/

#react
node_modules
build
.git
.gitignore
LICENSE
VERSION
README.md
Changelog.md
Makefile
docker-compose.yml
docs
Dockerfile
static

#general
README.md
node_modules
pgdata
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/django-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ on:
pull_request:
branches: ["main"]


defaults:
run:
working-directory: lotus

permissions:
contents: read

Expand Down
9 changes: 4 additions & 5 deletions lotus/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
# ---------------------------------------
FROM --platform=linux/amd64 python:3.9-bullseye AS build
ENV PYTHONUNBUFFERED 1
ENV POSTGRES_USER lotus
ENV POSTGRES_NAME lotus
ENV POSTGRES_PASSWORD lotus
#make lotus user
WORKDIR /code
WORKDIR /lotus
# pip install optimization
COPY Pipfile Pipfile.lock ./
RUN pip install -U --no-cache-dir --disable-pip-version-check pipenv
RUN pipenv install --system --deploy --ignore-pipfile
# copy python files,
COPY . .
COPY ./lotus/ ./lotus/
COPY ./metering_billing/ ./metering_billing/
COPY ./manage.py ./
# ---------------------------------------
# Development
# ---------------------------------------
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
release: chmod u+x release.sh && ./release.sh
web: gunicorn lotus.wsgi
web: gunicorn lotus.wsgi:application -w 4 --threads 4 --preload
worker: celery -A lotus worker -l info
beat: celery -A lotus beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
6 changes: 6 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"addons":[
{
"plan":"heroku-postgresql"
},
{
"plan":"heroku-redis"
}
],
"buildpacks": [
Expand All @@ -32,6 +35,9 @@
},
"STRIPE_SECRET_KEY":{
"value": "1234"
},
"ON_HEROKU":{
"value": "True"
}
},
"scripts":{
Expand Down
39 changes: 28 additions & 11 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,48 @@ services:
db:
image: postgres:14-alpine
restart: on-failure
env_file:
- ./env/.env.dev
ports:
- 5432:5432
volumes:
- ./pgdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: lotus
POSTGRES_PASSWORD: lotus
POSTGRES_DB: lotus

backend:
env_file:
- ./env/.env.dev
build:
context: ./lotus
context: .
dockerfile: Dockerfile
target: development
target: build
ports:
- 8000:8000
volumes:
- ./lotus:/code
command: python3 manage.py runserver 0.0.0.0:8000
- ./lotus:/lotus/lotus
- ./metering_billing:/lotus/metering_billing
command: >
sh -c "python3 manage.py wait_for_db && \
python3 manage.py migrate && \
python3 manage.py initadmin && \
python3 manage.py setup_tasks && \
python3 manage.py runserver 0.0.0.0:8000"
depends_on:
- db

frontend:
restart: always
build:
context: ./frontend
dockerfile: Dockerfile
context: .
dockerfile: frontend.Dockerfile
target: development
ports:
- 3000:3000
command: yarn run dev --host 0.0.0.0 --port 3000
volumes:
- ./frontend:/frontend:delegated
- ./src:/frontend/src:delegated
- ./public:/frontend/public:delegated
- /frontend/node_modules/
stdin_open: true
depends_on:
Expand All @@ -49,7 +58,10 @@ services:
celery:
env_file:
- ./env/.env.dev
build: ./lotus
build:
context: .
dockerfile: Dockerfile
target: build
command: celery -A lotus worker -l info
depends_on:
- redis
Expand All @@ -59,10 +71,15 @@ services:
env_file:
- ./env/.env.dev
restart: on-failure
build: ./lotus
build:
context: .
dockerfile: Dockerfile
target: build
command: celery -A lotus beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
depends_on:
- celery
- backend
- redis

volumes:
pgdata:
21 changes: 13 additions & 8 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ services:
db:
image: postgres:14-alpine
restart: on-failure
env_file:
- ./env/.env
expose:
- 5432
volumes:
- ./pgdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: lotus
POSTGRES_PASSWORD: lotus
POSTGRES_DB: lotus

backend:
env_file:
- ./env/.env
build:
context: ./lotus
context: .
dockerfile: Dockerfile
target: build
expose:
- 8000
volumes:
- django_static_volume:/code/staticfiles
- django_static_volume:/lotus/staticfiles
command: >
sh -c "python3 manage.py wait_for_db && \
python3 manage.py migrate && \
Expand All @@ -33,9 +35,10 @@ services:
frontend:
restart: always
build:
context: ./frontend
dockerfile: Dockerfile
context: .
dockerfile: frontend.Dockerfile
target: production
stdin_open: true
ports:
- 80:80
volumes:
Expand All @@ -53,7 +56,7 @@ services:
env_file:
- ./env/.env
build:
context: ./lotus
context: .
dockerfile: Dockerfile
target: build
command: celery -A lotus worker -l info
Expand All @@ -66,12 +69,14 @@ services:
- ./env/.env
restart: on-failure
build:
context: ./lotus
context: .
dockerfile: Dockerfile
target: build
command: celery -A lotus beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
depends_on:
- celery
- backend
- redis

volumes:
pgdata:
Expand Down
11 changes: 6 additions & 5 deletions frontend/Dockerfile → frontend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# Development stage
# ---------------------------------------
FROM --platform=linux/amd64 node:18.7.0-alpine AS development
ENV DOCKER_BUILDKIT 0
ENV COMPOSE_DOCKER_CLI_BUILD 0
WORKDIR /frontend
COPY package*.json yarn.lock tsconfig.json ./
COPY package*.json yarn.lock tsconfig.json \
vite.config.ts tsconfig.node.json postcss.config.cjs\
tailwind.config.cjs ./
RUN yarn config set network-timeout 300000 && \
yarn install --frozen-lockfile
# Bundle app source
COPY . ./
COPY public/ ./public/
COPY src/ ./src/
# ---------------------------------------
# Build stage
# ---------------------------------------
Expand All @@ -21,7 +22,7 @@ RUN yarn run build
FROM nginx:1.23-alpine AS production
#copy static files to nginx
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build frontend/src/dist /usr/share/nginx/html
COPY --from=build /frontend/src/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

ENTRYPOINT ["nginx", "-g", "daemon off;"]
13 changes: 0 additions & 13 deletions frontend/.dockerignore

This file was deleted.

File renamed without changes.
30 changes: 0 additions & 30 deletions lotus/.dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion lotus/lotus/__init__.py → lotus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import absolute_import, unicode_literals

from .celery import celery as celery_app
from lotus.lotus_celery import celery as celery_app

__all__ = ("celery_app",)
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 6 additions & 11 deletions lotus/lotus/settings.py → lotus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@
# set casting, default value
DEBUG=(bool, False),
PROFILER_ENABLED=(bool, False),
DOCKERIZED=(bool, False),
ON_HEROKU=(bool, False),
POSTGRES_NAME=(str, "lotus"),
POSTGRES_USER=(str, "lotus"),
POSTGRES_PASSWORD=(str, "lotus"),
)

DOCKERIZED = env("DOCKERIZED")
ON_HEROKU = env("ON_HEROKU")
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
local_env_file = BASE_DIR / "env/.env"
if local_env_file.is_file():
environ.Env.read_env(local_env_file)
DOCKERIZED = True
else:
DOCKERIZED = False
global_env_file = BASE_DIR / ".." / "env/.env"
if global_env_file.is_file():
environ.Env.read_env(global_env_file)


try:
sentry_sdk.init(
Expand Down Expand Up @@ -253,11 +250,9 @@
INTERNAL_IPS += [ip[: ip.rfind(".")] + ".1" for ip in ips]


# VITE_APP_DIR = BASE_DIR / "frontend" / "src"

# DJANGO_VITE_ASSETS_PATH = BASE_DIR / "frontend" / "static" / "dist"
VITE_APP_DIR = BASE_DIR / "src"

STATICFILES_DIRS = [BASE_DIR / "static"]
STATICFILES_DIRS = [BASE_DIR / "static", VITE_APP_DIR / "dist"]

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATIC_URL = "static/"
Expand Down
Loading

0 comments on commit 25d550a

Please sign in to comment.