From 6c48be6771d3063089fc5d2b0124d281b1576a06 Mon Sep 17 00:00:00 2001 From: Sivan Becker Date: Wed, 17 Aug 2022 22:29:56 +0300 Subject: [PATCH 1/4] docker and update readme --- README.md | 8 ++ docker/cmd.sh | 0 docker/docker-compose.yml | 76 +++++++------------ docker/dockerfile | 51 ++++++------- docker/entrypoint.sh | 7 ++ docker/uwsgi | 9 --- .../wait-for-postgres.sh | 2 +- entrypoint.sh | 7 -- 8 files changed, 67 insertions(+), 93 deletions(-) delete mode 100755 docker/cmd.sh create mode 100644 docker/entrypoint.sh delete mode 100644 docker/uwsgi rename wait-for-postgres.sh => docker/wait-for-postgres.sh (76%) delete mode 100644 entrypoint.sh diff --git a/README.md b/README.md index f78a1e51..771220e7 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,14 @@ 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. +### 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 ``` 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..cb30dbfc --- /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 76% rename from wait-for-postgres.sh rename to docker/wait-for-postgres.sh index 8d0dae97..041f1654 100644 --- a/wait-for-postgres.sh +++ b/docker/wait-for-postgres.sh @@ -8,7 +8,7 @@ shift cmd="$@" echo "Testing Postgres connection with psql ..." -until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "postgres" -c '\q'; do +until PGPASSWORD=$DBPASSWORD psql -h $DBHOST -U $DBUSER -c '\q'; do #~ >&2 echo "Postgres is unavailable - sleeping" >&2 echo -n . sleep 1 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 From 988407e724a608d03a8fd141e2d773b9c037627a Mon Sep 17 00:00:00 2001 From: Sivan Becker Date: Thu, 18 Aug 2022 09:31:05 +0300 Subject: [PATCH 2/4] CI deepsource fixes --- docker/wait-for-postgres.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker/wait-for-postgres.sh b/docker/wait-for-postgres.sh index 041f1654..588d0568 100644 --- a/docker/wait-for-postgres.sh +++ b/docker/wait-for-postgres.sh @@ -4,12 +4,9 @@ set -e host="$1" -shift -cmd="$@" echo "Testing Postgres connection with psql ..." -until PGPASSWORD=$DBPASSWORD psql -h $DBHOST -U $DBUSER -c '\q'; do - #~ >&2 echo "Postgres is unavailable - sleeping" +until PGPASSWORD="$DBPASSWORD" psql -h "$DBHOST" -U $DBUSER -c "\q"; do >&2 echo -n . sleep 1 done From 481eca697cd8abc7b28740783d4221530918ff51 Mon Sep 17 00:00:00 2001 From: Sivan Becker Date: Thu, 18 Aug 2022 09:41:33 +0300 Subject: [PATCH 3/4] CI fixes --- docker/entrypoint.sh | 2 +- docker/wait-for-postgres.sh | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index cb30dbfc..b3125dfe 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash # Execute startup scripts -./wait-for-postgres.sh $DBHOST +./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/wait-for-postgres.sh b/docker/wait-for-postgres.sh index 588d0568..5b27c405 100644 --- a/docker/wait-for-postgres.sh +++ b/docker/wait-for-postgres.sh @@ -4,9 +4,11 @@ set -e host="$1" +shift +cmd="$@" echo "Testing Postgres connection with psql ..." -until PGPASSWORD="$DBPASSWORD" psql -h "$DBHOST" -U $DBUSER -c "\q"; do +until PGPASSWORD="$DBPASSWORD" psql -h "$host" -U "$DBUSER" -c "\q"; do >&2 echo -n . sleep 1 done From 0c9ed60cd2f7a31fef171770260a5f7aeae32d7d Mon Sep 17 00:00:00 2001 From: Sivan Becker Date: Thu, 18 Aug 2022 10:11:08 +0300 Subject: [PATCH 4/4] CI fixes --- docker/wait-for-postgres.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/wait-for-postgres.sh b/docker/wait-for-postgres.sh index 5b27c405..49a49799 100644 --- a/docker/wait-for-postgres.sh +++ b/docker/wait-for-postgres.sh @@ -5,7 +5,7 @@ set -e host="$1" shift -cmd="$@" +cmd=( "$@" ) echo "Testing Postgres connection with psql ..." until PGPASSWORD="$DBPASSWORD" psql -h "$host" -U "$DBUSER" -c "\q"; do