Merge pull request #476 from sivanbecker/sbecker/docker

docker and update readme
This commit is contained in:
Ashwin Kumar 2023-02-16 10:03:30 +05:30 committed by GitHub
commit 026fd0aeb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 96 deletions

View file

@ -93,7 +93,17 @@ pip install -r requirements.txt
* Then refer to `env.md` for environment variables and keep those in the `.env` file in the current folder as your project is in.
### Next steps
### Docker / docker-compose
in order to use docker, please run the next commands after cloning repo:
```
docker build -t djcrm:1 -f docker/Dockerfile .
docker-compose -f docker/docker-compose.yml up
```
**Note**: you must have docker/docker-compose installed on your host.
### next steps
```
python manage.py migrate

View file

View file

@ -1,53 +1,35 @@
version: '3'
services:
djcrm8000:
network_mode: host
build:
context: ..
dockerfile: docker/dockerfile
args:
UWSGI_HTTP: 8000
env_file:
- ./db.env
volumes:
- /root/djcrm/media:/root/djcrm/media
- /root/djcrm/static/CACHE:/root/djcrm/static/CACHE
crm-app:
image: djcrm:1
container_name: crm-app
environment:
- DBNAME=crm
- DBUSER=crm
- DBPASSWORD=crm
- DBHOST=crm-db
- DBPORT=5432
djcrm8001:
network_mode: host
build:
context: ..
dockerfile: docker/dockerfile
args:
UWSGI_HTTP: 8001
env_file:
- ./db.env
volumes:
- /root/djcrm/media:/root/djcrm/media
- /root/djcrm/static/CACHE:/root/djcrm/static/CACHE
depends_on:
- crm-db
ports:
- 8000:8000
networks:
- nw
djcrm8002:
network_mode: host
build:
context: ..
dockerfile: docker/dockerfile
args:
UWSGI_HTTP: 8002
env_file:
- ./db.env
crm-db:
image: postgres:latest
container_name: crm-db
environment:
- POSTGRES_DB=crm
- POSTGRES_USER=crm
- POSTGRES_PASSWORD=crm
ports:
- 5432:5432
volumes:
- /root/djcrm/media:/root/djcrm/media
- /root/djcrm/static/CACHE:/root/djcrm/static/CACHE
- /var/run/postgresql/:/var/run/postgresql
networks:
- nw
djcrm8003:
network_mode: host
build:
context: ..
dockerfile: docker/dockerfile
args:
UWSGI_HTTP: 8003
env_file:
- ./db.env
volumes:
- /root/djcrm/media:/root/djcrm/media
- /root/djcrm/static/CACHE:/root/djcrm/static/CACHE
networks:
nw: {}

View file

@ -1,35 +1,28 @@
FROM ubuntu:18.04
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
WORKDIR /app
# Intall dependencies
COPY requirements.txt /app
ARG APPDIR=/root/djcrm
RUN apt-get update -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y libpcre3 mime-support postgresql-client libgnutls28-dev libcurl4-gnutls-dev libexpat-dev libpython3.6 ruby-full wkhtmltopdf build-essential libpcre3-dev libpq-dev python3-pip gcc python3-dev
RUN pip3 install setuptools
RUN apt update
RUN apt install -y git ruby-dev ruby-ffi postgresql-client redis-server wkhtmltopdf
RUN apt clean
RUN gem install sass
RUN gem install compass
# install nvm/npm
# RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
RUN apt install nodejs npm -y
RUN npm -g install less
RUN apt install -y python3-pip
RUN python3 -m pip install --no-cache-dir -r requirements.txt
RUN python3 -m pip install --no-cache-dir redis
RUN mkdir ${APPDIR}
WORKDIR ${APPDIR}
ADD . ${APPDIR}
RUN mkdir ${APPDIR}/media
RUN mkdir ${APPDIR}/static/CACHE
RUN pip3 install --no-cache-dir -r ${APPDIR}/requirements.txt
RUN python3 manage.py collectstatic --noinput
RUN python3 manage.py compress --force
RUN python3 manage.py migrate
# remove build pkgs
# RUN apt-get remove --purge -y build-essential libpcre3-dev libpq-dev python3-pip gcc python3-dev
COPY . /app
COPY docker/entrypoint.sh /app
COPY docker/wait-for-postgres.sh /app
# uwsgi configuration
ARG UWSGI_HTTP
ENV UWSGI_WSGI_FILE=crm/wsgi.py
ENV UWSGI_HTTP=:${UWSGI_HTTP} UWSGI_MASTER=1 UWSGI_HTTP_AUTO_CHUNKED=1 UWSGI_HTTP_KEEPALIVE=1 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy
# django env vars
# ENV DJANGO_ENVIRONMENT=live
EXPOSE ${UWSGI_HTTP}
CMD ["uwsgi", "--show-config"]
RUN chmod +x entrypoint.sh
RUN chmod +x wait-for-postgres.sh
ENTRYPOINT ["./entrypoint.sh"]

7
docker/entrypoint.sh Normal file
View file

@ -0,0 +1,7 @@
#!/bin/bash
# Execute startup scripts
./wait-for-postgres.sh "$DBHOST"
python3 manage.py collectstatic --noinput
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:8000

View file

@ -1,9 +0,0 @@
[uwsgi]
chdir = /djcrm
module = crm.wsgi
master = true
socket = /djcrm/djcrm.sock
chmod-socket = 666
vacuum = true
plugins = python3

View file

@ -5,11 +5,10 @@ set -e
host="$1"
shift
cmd="$@"
cmd=( "$@" )
echo "Testing Postgres connection with psql ..."
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "postgres" -c '\q'; do
#~ >&2 echo "Postgres is unavailable - sleeping"
until PGPASSWORD="$DBPASSWORD" psql -h "$host" -U "$DBUSER" -c "\q"; do
>&2 echo -n .
sleep 1
done

View file

@ -1,7 +0,0 @@
#!/bin/bash
# Execute startup scripts
./wait-for-postgres.sh $DB_HOST
python manage.py collectstatic --noinput
python manage.py migrate
python manage.py runserver 0.0.0.0:8000