diff --git a/README.md b/README.md index dff93950..0e3fea94 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker/cmd.sh b/docker/cmd.sh deleted file mode 100755 index e69de29b..00000000 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ced5abc6..161f28a7 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -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: {} diff --git a/docker/dockerfile b/docker/dockerfile index e6af9d2d..0aa85740 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -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"] \ No newline at end of file +RUN chmod +x entrypoint.sh +RUN chmod +x wait-for-postgres.sh +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 00000000..b3125dfe --- /dev/null +++ b/docker/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/docker/uwsgi b/docker/uwsgi deleted file mode 100644 index e0c6d30d..00000000 --- a/docker/uwsgi +++ /dev/null @@ -1,9 +0,0 @@ -[uwsgi] - -chdir = /djcrm -module = crm.wsgi -master = true -socket = /djcrm/djcrm.sock -chmod-socket = 666 -vacuum = true -plugins = python3 diff --git a/wait-for-postgres.sh b/docker/wait-for-postgres.sh similarity index 58% rename from wait-for-postgres.sh rename to docker/wait-for-postgres.sh index 8d0dae97..49a49799 100644 --- a/wait-for-postgres.sh +++ b/docker/wait-for-postgres.sh @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index b4d72618..00000000 --- a/entrypoint.sh +++ /dev/null @@ -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 \ No newline at end of file