Skip to content
Snippets Groups Projects
Commit 0faf9afa authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

use a single container as web-container subsume celery-container

parent 321a789b
No related branches found
No related tags found
2 merge requests!44use a single container as web-container subsume celery-container,!43K8S deployments of release branche, and other updates
......@@ -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:
......
......@@ -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"
......
......@@ -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"]
......
......@@ -63,6 +63,8 @@ django:
cpu: 2000m
celery:
concurrency: 2
logLevel: info
resources:
requests:
memory: 1Gi
......
......@@ -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:
......
......@@ -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
......
#!/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 "$@"
# 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment