Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor meow init scripts #404

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# Stage 0 - Node build
FROM node:8
FROM node:10
WORKDIR /meow
ADD package.json package-lock.json /meow/
RUN npm install
COPY ./webpack.config.js ./webpack.prod.config.js ./jsconfig.json ./
COPY meow/frontend meow/frontend
RUN npm run build-production

# Slightly modified from
# https://www.caktusgroup.com/blog/2017/03/14/production-ready-dockerfile-your-python-django-app/
#FROM python:3.6-alpine
FROM python:3.6
FROM python:3.7
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Copy in your requirements file
WORKDIR /meow

RUN apt-get update && apt-get install -y curl \
Expand All @@ -24,40 +20,10 @@ RUN apt-get update && apt-get install -y curl \
ADD requirements.txt /meow/
RUN pip install -U -r requirements.txt

# ADD requirements.txt /meow/

# Install build deps, then run `pip install`, then remove unneeded build deps all in a single step. Correct the path to your production requirements file, if needed.
# RUN set -ex \
# && apk add --no-cache --virtual .build-deps \
# gcc \
# make \
# tzdata \
# libc-dev \
# musl-dev \
# linux-headers \
# pcre-dev \
# postgresql-dev \
# && cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime \
# && echo "America/Los_Angeles" > /etc/timezone \
# && python3.6 -m venv /venv \
# && /venv/bin/pip install -U pip \
# && LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install --no-cache-dir -r requirements.txt" \
# && runDeps="$( \
# scanelf --needed --nobanner --recursive /venv \
# | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
# | sort -u \
# | xargs -r apk info --installed \
# | sort -u \
# )" \
# && apk add --virtual .python-rundeps $runDeps \
# && apk del .build-deps

# Copy your application code to the container (make sure you create a .dockerignore file if any large files or directories should be excluded)

COPY --from=0 /meow /meow

ADD . /meow/

EXPOSE 5000

ENTRYPOINT ["./entrypoint.sh"]
ENTRYPOINT ["./entrypoint.sh"]
43 changes: 43 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM node:10-slim

# Create and define the node_modules's cache directory.
RUN mkdir /usr/src/cache
WORKDIR /usr/src/cache

# Install the application's dependencies into the node_modules's cache directory.
COPY package.json ./
COPY package-lock.json ./
RUN npm install

WORKDIR /meow
COPY package.json package-lock.json /meow/
COPY ./webpack.config.js ./webpack.prod.config.js ./jsconfig.json /meow/
COPY meow/frontend meow/frontend
RUN cp -r /usr/src/cache/node_modules/. /meow/node_modules/
# RUN npm run build
RUN npm run build-production

RUN apt update && \
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget && \
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz && \
tar xzf Python-3.7.4.tgz && \
cd Python-3.7.4 && \
./configure && \
make && \
make install

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN apt-get update && apt-get install -y curl \
build-essential \
libpq-dev \
git \
zlib1g

ENV LIBRARY_PATH=/lib:/usr/lib
ADD requirements.txt /meow/
RUN python3.7 -m pip install --upgrade pip && python3.7 -m pip install -r requirements.txt
ADD . /meow/

EXPOSE 5000
ENTRYPOINT ["./entrypoint.sh"]
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: gunicorn --pythonpath meow --workers=2 meow.wsgi --log-file -
web: /meow/meow/manage.py runserver 0.0.0.0:5000
worker: export PYTHONPATH=meow && celery -A meow worker -l info --concurrency=1 -f celeryworker.log
clock: export PYTHONPATH=meow && celery -A meow beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler -f celeryclock.log
clock: export PYTHONPATH=meow && celery -A meow beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler -f celeryclock.log
17 changes: 17 additions & 0 deletions dev-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

rsync -arv --progress /usr/src/cache/node_modules/. /meow/node_modules/
cmd="nohup npm run watch";
$cmd &

echo "$DEBUG"
if [ "$DEBUG" = "False" ]; then
# Collect static files
echo "Collect static files"
python3.7 meow/manage.py collectstatic --noinput
fi
echo "Apply database migrations"
python3.7 meow/manage.py migrate

exec "$@"
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ version: "3"

services:
web:
build: .
build:
context: .
dockerfile: Dockerfile.dev
image: meow
command: honcho start -f Procfile.dev
entrypoint: ./entrypoint.sh
entrypoint: ./dev-entrypoint.sh
ports:
- "5000:5000"
env_file: .env
Expand All @@ -17,7 +19,7 @@ services:
environment:
PYTHONUNBUFFERED: 1
db:
image: postgres:latest
image: postgres:12
environment:
POSTGRES_PASSWORD: example
redis:
Expand Down
8 changes: 2 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ echo "$DEBUG"
if [ "$DEBUG" = "False" ]; then
# Collect static files
echo "Collect static files"
python meow/manage.py collectstatic --noinput

# Apply database migrations


python3.7 meow/manage.py collectstatic --noinput
fi
echo "Apply database migrations"
python meow/manage.py migrate
python3.7 meow/manage.py migrate

exec "$@"
9 changes: 7 additions & 2 deletions init_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fi


# this inits everything but will only continue if the pervious step was successful
npm i
npm run build
docker-compose build &&
docker-compose run web meow/manage.py migrate &&
echo ">>> The ids and secrets can be found in the #meow_dev channel's pinned messages" &&
Expand All @@ -50,6 +48,13 @@ if [ $? == 0 ]; then
else
echo "Created section \"Test\""
fi

echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', '[email protected]', '12345')" | docker-compose run web meow/manage.py shell
if [ $? != 0 ]; then
echo "!!!!! Failed to create the super user !!!!!"
else
echo "Created the super users"
fi

echo -e "from django_celery_beat.models import PeriodicTask, IntervalSchedule\nschedule=IntervalSchedule.objects.create(every=$PERIODIC_TASK_MINUTES, period=IntervalSchedule.MINUTES)\nPeriodicTask.objects.create(interval=schedule, name='Send Posts', task='sendposts')\n" | docker-compose run web meow/manage.py shell
if [ $? != 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion meow/manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/local/bin/python3
import os
import sys

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"history": "4.7.2",
"husky": "1.3.1",
"moment": "2.23.0",
"node-sass": "4.12.0",
"sass": "^1.49.9",
"prettier": "1.15.3",
"pretty-quick": "1.8.0",
"prop-types": "15.6.2",
Expand Down
125 changes: 77 additions & 48 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,77 @@
amqp==2.2.1
astroid==1.5.3
backports.functools-lru-cache==1.4
beautifulsoup4==4.6.0
billiard==3.5.0.3
celery==4.2.0
certifi==2017.7.27.1
chardet==3.0.4
configparser==3.5.0
dj-database-url==0.5.0
Django==2.2.6
django-allauth==0.38.0
django-celery-beat==1.1.1
django-cors-headers==2.2.0
django-environ==0.4.5
# django-oauth-toolkit==1.2.0
django-rest-auth==0.9.3
# django-slack-oauth==1.4.3
django-webpack-loader==0.6.0
djangorestframework==3.9.1
enum34==1.1.6
facepy==1.0.9
gunicorn==19.7.1
honcho==1.0.1
idna==2.6
isort==4.2.15
kombu==4.2.1
lazy-object-proxy==1.3.1
mccabe==0.6.1
oauthlib==2.0.3
parsedatetime==2.4
psycopg2==2.7.5
Pillow==4.2.1
pylint==1.7.2
pyshorteners==0.6.1
pytz==2017.2
redis==2.10.6
requests==2.20.0
requests-oauthlib==0.8.0
singledispatch==3.4.0.3
six==1.10.0
social-auth-app-django==3.1.0
social-auth-core==3.2.0
tweepy==3.8.0
urllib3==1.24.2
vine==1.1.4
whitenoise==3.3.1
wrapt==1.10.11
amqp==5.1.1
asgiref==3.6.0
astroid==2.13.3
async-timeout==4.0.2
backports.functools-lru-cache==1.6.4
backports.zoneinfo==0.2.1
beautifulsoup4==4.11.1
billiard==3.6.4.0
cached-property==1.5.2
celery==5.2.7
certifi==2022.12.7
cffi==1.15.1
chardet==5.1.0
charset-normalizer==3.0.1
click==8.1.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
configparser==5.3.0
cryptography==39.0.0
defusedxml==0.7.1
dill==0.3.6
dj-database-url==1.2.0
Django==3.2.16
django-allauth==0.52.0
django-celery-beat==2.4.0
django-cors-headers==3.13.0
django-environ==0.9.0
django-rest-auth==0.9.5
django-timezone-field==5.0
django-webpack-loader==0.7.0
djangorestframework==3.14.0
enum34==1.1.10
facepy==1.0.12
gunicorn==20.1.0
honcho==1.1.0
idna==3.4
importlib-metadata==4.13.0
isort==5.11.4
kombu==5.2.4
lazy-object-proxy==1.9.0
mccabe==0.7.0
oauthlib==3.2.2
parsedatetime==2.6
Pillow==9.4.0
platformdirs==2.6.2
prompt-toolkit==3.0.36
psycopg2==2.9.5
pycparser==2.21
PyJWT==2.6.0
pylint==2.15.10
pyshorteners==1.0.1
python-crontab==2.7.1
python-dateutil==2.8.2
python3-openid==3.2.0
pytz==2022.7.1
redis==4.4.2
requests==2.28.2
requests-oauthlib==1.3.1
singledispatch==4.0.0
six==1.16.0
social-auth-app-django==5.0.0
social-auth-core==4.3.0
soupsieve==2.3.2.post1
sqlparse==0.4.3
tomli==2.0.1
tomlkit==0.11.6
tweepy==4.12.1
typed-ast==1.5.4
typing_extensions==4.4.0
tzdata==2022.7
urllib3==1.26.14
vine==5.0.0
wcwidth==0.2.6
whitenoise==6.3.0
wrapt==1.14.1
zipp==3.11.0
2 changes: 0 additions & 2 deletions sudo_init_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fi


# this inits everything but will only continue if the pervious step was successful
npm i
npm run build
sudo docker-compose build &&
sudo docker-compose run web meow/manage.py migrate &&
echo ">>> The ids and secrets can be found in the #meow_dev channel's pinned messages" &&
Expand Down
5 changes: 4 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ module.exports = {
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "sass-loader" // translates CSS into CommonJS
loader: "sass-loader", // translates CSS into CommonJS
options: {
implementation: require("sass")
}
}
]
},
Expand Down