diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e39f5818661168b75f0ea88fae56ff8b5a8c578..fa511b6cb4a4b83a1940071e187977c3288831f1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ test-style: -e POSTGRES_DB=$POSTGRES_DB -e POSTGRES_USER=$POSTGRES_USER -v $(pwd)/persistent:/code/persistent - "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:$CI_COMMIT_SHA" + "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:$CI_COMMIT_SHA" test - mv persistent/coverage.xml coverage.xml - mv persistent/htmlcov htmlcov @@ -83,14 +83,14 @@ pages: script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY # pull the latest build on this branch - - docker pull "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:latest" || true + - docker pull "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:latest" || true # build the image while passing commit SHA and tagging the image with it - cd ippisite - docker build --target docs-container --build-arg CI_COMMIT_REF_SLUG --build-arg CI_COMMIT_SHA - --cache-from "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:latest" + --cache-from "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:latest" --tag ippidb_docs . - mkdir build/ @@ -113,41 +113,23 @@ pages: - ls -lah - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY # pull the latest build on master - - docker pull "$CI_REGISTRY_IMAGE/master/web-container:latest" || true - - docker pull "$CI_REGISTRY_IMAGE/master/celery-container:latest" || true + - docker pull "$CI_REGISTRY_IMAGE/master/app-container:latest" || true # pull the latest build on this branch - - docker pull "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:latest" || true - - docker pull "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/celery-container:latest" || true + - docker pull "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:latest" || true # build the image while passing commit SHA and tagging the image with it - docker build - --target web-container + --target app-container --build-arg CI_COMMIT_REF_SLUG --build-arg CI_COMMIT_SHA - --cache-from "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:latest" - --cache-from "$CI_REGISTRY_IMAGE/master/web-container:latest" - --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:$CI_COMMIT_SHA" - --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:latest" + --cache-from "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:latest" + --cache-from "$CI_REGISTRY_IMAGE/master/app-container:latest" + --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:$CI_COMMIT_SHA" + --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:latest" . # push image as latest for the current branch - - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:latest" + - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:latest" # push image tagged with its sha - - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:$CI_COMMIT_SHA" - # build the image while passing commit SHA and tagging the image with it - - docker build - --target celery-container - --build-arg CI_COMMIT_REF_SLUG - --build-arg CI_COMMIT_SHA - --cache-from "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/celery-container:latest" - --cache-from "$CI_REGISTRY_IMAGE/master/celery-container:latest" - --cache-from "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/web-container:latest" - --cache-from "$CI_REGISTRY_IMAGE/master/web-container:latest" - --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/celery-container:$CI_COMMIT_SHA" - --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/celery-container:latest" - . - # push image as latest for the current branch - - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/celery-container:latest" - # push image tagged with its sha - - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/celery-container:$CI_COMMIT_SHA" + - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG/app-container:$CI_COMMIT_SHA" build-ippisite: diff --git a/chart/templates/deployment-celery-worker.yaml b/chart/templates/deployment-celery-worker.yaml index 6c297120841346bcf5c66a541d41bc4ff779c1d5..a42959cf1d0b0e19fc160fa5fbbc00cd6cc4d090 100644 --- a/chart/templates/deployment-celery-worker.yaml +++ b/chart/templates/deployment-celery-worker.yaml @@ -30,10 +30,20 @@ spec: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: celery - image: {{ printf "%s/%s/%s:%s" .Values.CI_REGISTRY_IMAGE .Release.Name "celery-container" .Values.image.tag }} + image: {{ printf "%s/%s/%s:%s" .Values.CI_REGISTRY_IMAGE .Release.Name "app-container" .Values.image.tag }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} # command: ["/docker-celery-entrypoint.sh", "hold_on"] + command: + - /usr/local/bin/celery + args: + - "-A" + - "ippisite" + - "worker" + - "-l" + - {{ .Values.celery.logLevel | quote }} + - "--concurrency" + - {{ .Values.celery.concurrency | quote }} env: - name: DJANGO_DEBUG value: "false" diff --git a/chart/templates/deployment-django.yaml b/chart/templates/deployment-django.yaml index 6e1e5c5b0d65b9b78e5428124bfc003452407a2c..b3ee9ed6126593780ea3cb6861c3bcff53f33741 100644 --- a/chart/templates/deployment-django.yaml +++ b/chart/templates/deployment-django.yaml @@ -39,7 +39,7 @@ spec: do echo waiting for database; sleep 2; done;' ] containers: - name: django - image: {{ printf "%s/%s/%s:%s" .Values.CI_REGISTRY_IMAGE .Release.Name "web-container" .Values.image.tag }} + image: {{ printf "%s/%s/%s:%s" .Values.CI_REGISTRY_IMAGE .Release.Name "app-container" .Values.image.tag }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} # command: ["/docker-entrypoint.sh", "gunicorn", "--bind", ":8000", "ippisite.wsgi:application", "--threads", "4"] diff --git a/chart/values.yaml b/chart/values.yaml index 9329d1eea19e4886851ebec9224b219339cc158d..b097313b07c781b2b83fb5abdb56695b67a83117 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -63,6 +63,8 @@ django: cpu: 2000m celery: + concurrency: 2 + logLevel: info resources: requests: memory: 1Gi diff --git a/docker-compose.yaml b/docker-compose.yaml index 81018d96da94c89831f959f9edf5be1fdf0fc597..47f7a43c9a9448f5e513b84c473e8daf92b2952b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,7 +15,7 @@ services: django: build: context: ./ippisite - target: web-container + target: app-container env_file: - ./ippisite/ippisite/settings.example.ini command: gunicorn --reload --reload-engine inotify ippisite.wsgi -b 0.0.0.0:8000 --log-level debug --threads 4 @@ -35,9 +35,10 @@ services: celery: build: context: ./ippisite - target: celery-container + target: app-container env_file: - ./ippisite/ippisite/settings.example.ini + command: celery -A ippisite worker -l info --concurrency 2 environment: - DJANGO_DEBUG=False volumes: diff --git a/ippisite/Dockerfile b/ippisite/Dockerfile index f241bb4408c994c85fcf1d82cba852f8790972cf..5a7e04d33759da8115b2b03d9410a600e116f447 100644 --- a/ippisite/Dockerfile +++ b/ippisite/Dockerfile @@ -31,18 +31,14 @@ COPY ./*-entrypoint.sh / RUN chmod a+x /*-entrypoint.sh + ############################################################################### -# Base image plus the sources +# django web app and celery containery ############################################################################### -FROM base-container-without-sources AS base-container +FROM base-container-without-sources AS app-container COPY . /code/ -############################################################################### -# django web app -############################################################################### -FROM base-container AS web-container - ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["gunicorn", "--bind", ":8000", "ippisite.wsgi:application", "--threads", "4" ] @@ -55,17 +51,6 @@ RUN USE_SQLITE_AS_DB=True python manage.py collectstatic --noinput \ USER kiwi -############################################################################### -# celery worker -############################################################################### -FROM base-container AS celery-container - -ENTRYPOINT ["/docker-celery-entrypoint.sh"] - -CMD ["celery", "-A", "ippisite", "worker", "-l", "info", "--concurrency", "2"] - -USER kiwi - ############################################################################### # build the docs diff --git a/ippisite/docker-celery-entrypoint.sh b/ippisite/docker-celery-entrypoint.sh deleted file mode 100644 index 9c1d382c5bd2eaa55682c2745b07846026b50fcd..0000000000000000000000000000000000000000 --- a/ippisite/docker-celery-entrypoint.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -function msg_info { - echo -e "\033[1;32m$1\033[0m" -} - -function msg_warning { - echo -e "\033[1;33m$1\033[0m" -} - -function msg_error { - echo -e "\033[1;31m$1\033[0m" -} - -cd /code - -if [ "$1" == "hold_on" ]; then - msg_info "holding on util you delete /tmp/hold_on" - touch /tmp/hold_on - while [ -e "/tmp/hold_on" ]; do - sleep 1 ; - echo "holding on" ; - done -fi - -exec "$@" diff --git a/ippisite/notes.md b/ippisite/notes.md index 1a3880520bd9c0e455f71884d047bd7da92fdf1f..4f8848bd20f425d08d4a16c8509148210a4b16fe 100755 --- a/ippisite/notes.md +++ b/ippisite/notes.md @@ -1,7 +1,7 @@ # How to build and run the app ```shell -docker build . -t test_ippidb --target web-container && docker run -it -e ALLOWED_HOSTS=localhost -e SECRET_KEY=a -e "STATIC_URL=/static" -e "POSTGRES_NAME=postgres" -e "POSTGRES_USER=postgres" -e "POSTGRES_PASSWORD=postgres" -e "POSTGRES_HOST=db" -e "USE_SQLITE_AS_DB=True" -v $(pwd):/code -p 8095:8000 test_ippidb +docker build . -t test_ippidb --target app-container && docker run -it -e ALLOWED_HOSTS=localhost -e SECRET_KEY=a -e "STATIC_URL=/static" -e "POSTGRES_NAME=postgres" -e "POSTGRES_USER=postgres" -e "POSTGRES_PASSWORD=postgres" -e "POSTGRES_HOST=db" -e "USE_SQLITE_AS_DB=True" -v $(pwd):/code -p 8095:8000 test_ippidb ``` # How to import the data