diff --git a/Dockerfile b/Dockerfile index 91db9a7e..7841bd0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,11 +31,18 @@ COPY ./vaas/requirements /home/app/vaas/requirements RUN pip install -r ./requirements/base.txt +#copy uwsgi config +COPY ./docker/uwsgi.cfg /etc/ + +#copy mime types used by uwsgi +COPY ./docker/mime.types /etc/ + # copy project COPY ./vaas /home/app/vaas # copy entrypoints.sh COPY \ + docker/entrypoint-uwsgi.sh \ docker/entrypoint-uwsgi-dev.sh \ docker/entrypoint-celery-worker.sh \ docker/entrypoint-celery-routes-test.sh \ diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 00000000..bef29a88 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,131 @@ +services: + celery-worker: + entrypoint: [ '/entrypoint-celery-worker.sh' ] + env_file: ./envs/dev.env + volumes: + - ./vaas:/home/app/vaas + - ./plugins:/home/app/plugins + networks: + - vaas + - default + celery-cron-worker: + entrypoint: [ '/entrypoint-celery-cron-worker.sh' ] + env_file: ./envs/dev.env + volumes: + - ./vaas:/home/app/vaas + - ./plugins:/home/app/plugins + networks: + - vaas + - default + celery-routes-test: + entrypoint: [ '/entrypoint-celery-routes-test.sh' ] + env_file: ./envs/dev.env + volumes: + - ./vaas:/home/app/vaas + - ./plugins:/home/app/plugins + networks: + - vaas + - default + uwsgi: + entrypoint: ['/wait-for-it.sh', 'mysql:3306', '-t', '30', '--', '/entrypoint-uwsgi-dev.sh' ] + env_file: ./envs/dev.env + volumes: + - ./vaas:/home/app/vaas + - ./plugins:/home/app/plugins + networks: + - vaas + - default + celery-scheduler: + entrypoint: ['/wait-for-it.sh', 'uwsgi:3030', '-t', '60', '--', '/entrypoint-celery-scheduler.sh' ] + env_file: ./envs/dev.env + volumes: + - ./vaas:/home/app/vaas + - ./plugins:/home/app/plugins + networks: + - vaas + - default + + # Varnishes & nginx + nginx-0: + build: ./docker/nginx + image: vaas-nginx + expose: + - "80" + networks: + vaas: + ipv4_address: 192.168.199.10 + nginx-1: + build: ./docker/nginx + image: vaas-nginx + expose: + - "80" + networks: + vaas: + ipv4_address: 192.168.199.11 + nginx-2: + build: ./docker/nginx + image: vaas-nginx + expose: + - "80" + networks: + vaas: + ipv4_address: 192.168.199.12 + nginx-3: + build: ./docker/nginx + image: vaas-nginx + expose: + - "80" + networks: + vaas: + ipv4_address: 192.168.199.13 + nginx-4: + build: ./docker/nginx + image: vaas-nginx + expose: + - "80" + networks: + vaas: + ipv4_address: 192.168.199.14 + nginx-5: + build: ./docker/nginx + image: vaas-nginx + expose: + - "80" + networks: + vaas: + ipv4_address: 192.168.199.15 + varnish-4.1: + build: ./docker/varnish-4.1 + image: allegro/vaas-varnish-4.1 + expose: + - "6082" + - "6081" + networks: + vaas: + ipv4_address: 192.168.199.4 + varnish-6.0.2: + build: ./docker/varnish-6.0.2 + image: allegro/vaas-varnish-6.0.2 + expose: + - "6082" + - "6081" + networks: + vaas: + ipv4_address: 192.168.199.6 + varnish-7.0: + build: ./docker/varnish-7.0 + image: allegro/vaas-varnish-7.0 + expose: + - "6082" + - "6081" + networks: + vaas: + ipv4_address: 192.168.199.7 +networks: + vaas: + driver: bridge + ipam: + driver: default + config: + - subnet: 192.168.199.0/24 + gateway: 192.168.199.1 diff --git a/docker-compose.override.yml b/docker-compose.override.yml index bef29a88..691ba8c8 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,131 +1,41 @@ services: celery-worker: entrypoint: [ '/entrypoint-celery-worker.sh' ] - env_file: ./envs/dev.env + env_file: ./envs/base.env volumes: - ./vaas:/home/app/vaas - ./plugins:/home/app/plugins networks: - - vaas - default celery-cron-worker: entrypoint: [ '/entrypoint-celery-cron-worker.sh' ] - env_file: ./envs/dev.env + env_file: ./envs/base.env volumes: - ./vaas:/home/app/vaas - ./plugins:/home/app/plugins networks: - - vaas - default celery-routes-test: entrypoint: [ '/entrypoint-celery-routes-test.sh' ] - env_file: ./envs/dev.env + env_file: ./envs/base.env volumes: - ./vaas:/home/app/vaas - ./plugins:/home/app/plugins networks: - - vaas - default uwsgi: - entrypoint: ['/wait-for-it.sh', 'mysql:3306', '-t', '30', '--', '/entrypoint-uwsgi-dev.sh' ] - env_file: ./envs/dev.env + entrypoint: ['/wait-for-it.sh', 'mysql:3306', '-t', '30', '--', '/entrypoint-uwsgi.sh' ] + env_file: ./envs/base.env volumes: - ./vaas:/home/app/vaas - ./plugins:/home/app/plugins networks: - - vaas - default celery-scheduler: entrypoint: ['/wait-for-it.sh', 'uwsgi:3030', '-t', '60', '--', '/entrypoint-celery-scheduler.sh' ] - env_file: ./envs/dev.env + env_file: ./envs/base.env volumes: - ./vaas:/home/app/vaas - ./plugins:/home/app/plugins networks: - - vaas - default - - # Varnishes & nginx - nginx-0: - build: ./docker/nginx - image: vaas-nginx - expose: - - "80" - networks: - vaas: - ipv4_address: 192.168.199.10 - nginx-1: - build: ./docker/nginx - image: vaas-nginx - expose: - - "80" - networks: - vaas: - ipv4_address: 192.168.199.11 - nginx-2: - build: ./docker/nginx - image: vaas-nginx - expose: - - "80" - networks: - vaas: - ipv4_address: 192.168.199.12 - nginx-3: - build: ./docker/nginx - image: vaas-nginx - expose: - - "80" - networks: - vaas: - ipv4_address: 192.168.199.13 - nginx-4: - build: ./docker/nginx - image: vaas-nginx - expose: - - "80" - networks: - vaas: - ipv4_address: 192.168.199.14 - nginx-5: - build: ./docker/nginx - image: vaas-nginx - expose: - - "80" - networks: - vaas: - ipv4_address: 192.168.199.15 - varnish-4.1: - build: ./docker/varnish-4.1 - image: allegro/vaas-varnish-4.1 - expose: - - "6082" - - "6081" - networks: - vaas: - ipv4_address: 192.168.199.4 - varnish-6.0.2: - build: ./docker/varnish-6.0.2 - image: allegro/vaas-varnish-6.0.2 - expose: - - "6082" - - "6081" - networks: - vaas: - ipv4_address: 192.168.199.6 - varnish-7.0: - build: ./docker/varnish-7.0 - image: allegro/vaas-varnish-7.0 - expose: - - "6082" - - "6081" - networks: - vaas: - ipv4_address: 192.168.199.7 -networks: - vaas: - driver: bridge - ipam: - driver: default - config: - - subnet: 192.168.199.0/24 - gateway: 192.168.199.1 diff --git a/docker/entrypoint-celery-cron-worker.sh b/docker/entrypoint-celery-cron-worker.sh index a3c10929..4eb06b9f 100755 --- a/docker/entrypoint-celery-cron-worker.sh +++ b/docker/entrypoint-celery-cron-worker.sh @@ -2,6 +2,6 @@ exec celery --workdir=/home/app/vaas \ -A vaas.settings worker \ - --loglevel=DEBUG \ + --loglevel=$LOG_LEVEL \ --concurrency=1 \ -Q cron_queue diff --git a/docker/entrypoint-celery-routes-test.sh b/docker/entrypoint-celery-routes-test.sh index 3190ca29..f5bb6c29 100755 --- a/docker/entrypoint-celery-routes-test.sh +++ b/docker/entrypoint-celery-routes-test.sh @@ -2,6 +2,6 @@ exec celery --workdir=/home/app/vaas \ -A vaas.settings worker \ - --loglevel=DEBUG \ + --loglevel=$LOG_LEVEL \ --concurrency=1 \ -Q routes_test_queue diff --git a/docker/entrypoint-celery-scheduler.sh b/docker/entrypoint-celery-scheduler.sh index 318c3b34..b81ff2b4 100755 --- a/docker/entrypoint-celery-scheduler.sh +++ b/docker/entrypoint-celery-scheduler.sh @@ -2,5 +2,5 @@ echo "Migrating Scheduler" exec celery --workdir=/home/app/vaas \ --app=vaas.settings beat \ - --loglevel=DEBUG \ + --loglevel=$LOG_LEVEL \ --scheduler=beatx.schedulers.Scheduler \ No newline at end of file diff --git a/docker/entrypoint-celery-worker.sh b/docker/entrypoint-celery-worker.sh index 9ce05bec..4b660370 100755 --- a/docker/entrypoint-celery-worker.sh +++ b/docker/entrypoint-celery-worker.sh @@ -2,6 +2,6 @@ exec celery --workdir=/home/app/vaas \ -A vaas.settings worker \ - --loglevel=DEBUG \ + --loglevel=$LOG_LEVEL \ --concurrency=1 \ -Q worker_queue diff --git a/docker/entrypoint-uwsgi-dev.sh b/docker/entrypoint-uwsgi-dev.sh index a2ceb4af..60806056 100755 --- a/docker/entrypoint-uwsgi-dev.sh +++ b/docker/entrypoint-uwsgi-dev.sh @@ -7,7 +7,7 @@ echo "Migrating" python /home/app/vaas/manage.py migrate --run-syncdb echo "Loading test_data" -python /home/app/vaas/manage.py loaddata ./vaas/resources/data.yaml +python /home/app/vaas/manage.py loaddata ./vaas/resources/dev-data.yaml echo "Install the test requirements to allow [manage.py test] to be called within the container" pip install -r /home/app/vaas/requirements/test.txt diff --git a/docker/entrypoint-uwsgi.sh b/docker/entrypoint-uwsgi.sh new file mode 100755 index 00000000..fdd86c26 --- /dev/null +++ b/docker/entrypoint-uwsgi.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +echo "Collect static files" +python /home/app/vaas/manage.py collectstatic --no-input + +echo "Migrating" +python /home/app/vaas/manage.py migrate --run-syncdb + +echo "Loading base-data" +python /home/app/vaas/manage.py loaddata ./vaas/resources/base-data.yaml + +echo "Install the test requirements to allow [manage.py test] to be called within the container" +pip install -r /home/app/vaas/requirements/base.txt + +echo "Start uwsgi server" +exec uwsgi --ini /etc/uwsgi.cfg --http-socket :3030 \ No newline at end of file diff --git a/docker/mime.types b/docker/mime.types new file mode 100644 index 00000000..452b7bcd --- /dev/null +++ b/docker/mime.types @@ -0,0 +1,86 @@ +text/html html htm shtml; +text/css css; +text/xml xml; +image/gif gif; +image/jpeg jpeg jpg; +application/javascript js; +application/atom+xml atom; +application/rss+xml rss; + +text/mathml mml; +text/plain txt; +text/vnd.sun.j2me.app-descriptor jad; +text/vnd.wap.wml wml; +text/x-component htc; + +image/png png; +image/tiff tif tiff; +image/vnd.wap.wbmp wbmp; +image/x-icon ico; +image/x-jng jng; +image/x-ms-bmp bmp; +image/svg+xml svg svgz; +image/webp webp; + +application/font-woff woff; +application/java-archive jar war ear; +application/json json; +application/mac-binhex40 hqx; +application/msword doc; +application/pdf pdf; +application/postscript ps eps ai; +application/rtf rtf; +application/vnd.apple.mpegurl m3u8; +application/vnd.ms-excel xls; +application/vnd.ms-fontobject eot; +application/vnd.ms-powerpoint ppt; +application/vnd.wap.wmlc wmlc; +application/vnd.google-earth.kml+xml kml; +application/vnd.google-earth.kmz kmz; +application/x-7z-compressed 7z; +application/x-cocoa cco; +application/x-java-archive-diff jardiff; +application/x-java-jnlp-file jnlp; +application/x-makeself run; +application/x-perl pl pm; +application/x-pilot prc pdb; +application/x-rar-compressed rar; +application/x-redhat-package-manager rpm; +application/x-sea sea; +application/x-shockwave-flash swf; +application/x-stuffit sit; +application/x-tcl tcl tk; +application/x-x509-ca-cert der pem crt; +application/x-xpinstall xpi; +application/xhtml+xml xhtml; +application/xspf+xml xspf; +application/zip zip; + +application/octet-stream bin exe dll; +application/octet-stream deb; +application/octet-stream dmg; +application/octet-stream iso img; +application/octet-stream msi msp msm; + +application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; +application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; +application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; + +audio/midi mid midi kar; +audio/mpeg mp3; +audio/ogg ogg; +audio/x-m4a m4a; +audio/x-realaudio ra; + +video/3gpp 3gpp 3gp; +video/mp2t ts; +video/mp4 mp4; +video/mpeg mpeg mpg; +video/quicktime mov; +video/webm webm; +video/x-flv flv; +video/x-m4v m4v; +video/x-mng mng; +video/x-ms-asf asx asf; +video/x-ms-wmv wmv; +video/x-msvideo avi; \ No newline at end of file diff --git a/docker/uwsgi.cfg b/docker/uwsgi.cfg new file mode 100644 index 00000000..f624b69c --- /dev/null +++ b/docker/uwsgi.cfg @@ -0,0 +1,13 @@ +[uwsgi] +master = 1 +die-on-term = 1 +need-app = 1 +processes = 8 +buffer-size = 65535 +async = 25 +ugreen = 1 +pythonpath = /home/app/vaas +module = vaas.external.wsgi +check-static = /home/app/vaas/vaas +mimefile = /etc/mime.types +route-run = last: \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 871c3db8..7eef7884 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,7 +18,7 @@ There are many benefits from using VaaS, including: Try it ------ -You can easily set up a sample VaaS instance with two test Varnish servers and several test backends using [VaaS in Docker Compose](quick-start/development.md). You might also like to check out [VaaS in Docker](quick-start/docker.md). +You can easily set up a sample VaaS instance with two test Varnish servers and several test backends using [VaaS in Docker Compose](quick-start/docker_compose.md). Release notes ------------- diff --git a/docs/quick-start/docker.md b/docs/quick-start/docker.md deleted file mode 100644 index d478b9c3..00000000 --- a/docs/quick-start/docker.md +++ /dev/null @@ -1,48 +0,0 @@ -VaaS in Docker -============== -VaaS in Docker is a preconfigured instance of VaaS varnish configuration tool. It is meant as a demo application that can help you understand how VaaS works. - -How to run VaaS in Docker -------------------------- -By default, the container starts with no data loaded and with an admin user identified by admin password: - - sudo docker run -p 80:80 -d -t allegro/vaas - -You will now be able to log in to your container pointing your browser to the IP address of your docker host. -If you want, you can start the container with selected username and password as follows: - - sudo docker run -p 80:80 -d -t allegro/vaas - -The last argument is optional. If you don't specify an api_key, a random one will be generated. - -Starting VaaS in Docker with API access ---------------------------------------- - -First, create a data.yaml file that will only contain an admin user definition with a preconfigured password "admin" and api key "vagrant_api_key" (do not directly copy and paste the data.yaml file contents below, use cat to generate it): - - cat > /var/tmp/data.yaml < allegro/vaas-nginx -You will need to configure the new Nginx instance in Manager app. \ No newline at end of file +You will need to configure the new Nginx instance in Manager app. + +Production ready VaaS instance with empty configuration and without debug logs +=============== + +To start Vaas you just have to run: +```bash +docker-compose up -d +``` + +Check That Everything Is Working +---------------- +To check that the build is working, run `docker-compose ps`. This should give you output similar to the below. + +```bash +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +vaas-celery-cron-worker-1 vaas-celery-cron-worker "/entrypoint-celery-…" celery-cron-worker 49 minutes ago Up 49 minutes +vaas-celery-routes-test-1 vaas-celery-routes-test "/entrypoint-celery-…" celery-routes-test 49 minutes ago Up 49 minutes +vaas-celery-scheduler-1 vaas-celery-scheduler "/wait-for-it.sh uws…" celery-scheduler 49 minutes ago Up 49 minutes +vaas-celery-worker-1 vaas-celery-worker "/entrypoint-celery-…" celery-worker 49 minutes ago Up 49 minutes +vaas-mysql-1 mysql:5.7 "docker-entrypoint.s…" mysql 6 hours ago Up 49 minutes (healthy) 3306/tcp, 33060/tcp +vaas-redis-1 redis:alpine "docker-entrypoint.s…" redis 6 hours ago Up 49 minutes (healthy) 6379/tcp +vaas-uwsgi-1 vaas-uwsgi "/wait-for-it.sh mys…" uwsgi 49 minutes ago Up 49 minutes 0.0.0.0:3030->3030/tcp, :::3030->3030/tcp +``` + +Log in to VaaS +-------------- +Point your browser to and log in using the following credentials: + + User: admin + Password: admin + diff --git a/envs/base.env b/envs/base.env new file mode 100644 index 00000000..b44c4e15 --- /dev/null +++ b/envs/base.env @@ -0,0 +1,6 @@ +# Application +DEBUG=False +TEMPLATE_DEBUG=False +DJANGO_SETTINGS_MODULE=vaas.settings.docker +PROMETHEUS_ENABLE=True +LOG_LEVEL=INFO diff --git a/envs/dev.env b/envs/dev.env index cb9fc5d4..751b9b87 100644 --- a/envs/dev.env +++ b/envs/dev.env @@ -3,3 +3,4 @@ DEBUG=True TEMPLATE_DEBUG=True DJANGO_SETTINGS_MODULE=vaas.settings.docker PROMETHEUS_ENABLE=True +LOG_LEVEL=DEBUG \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 57821bef..aa58359a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -3,8 +3,7 @@ repo_url: https://github.com/allegro/vaas pages: - 'About': 'index.md' - 'Quick Start': - - 'VaaS in Docker Compose': 'quick-start/development.md' - - 'VaaS in Docker': 'quick-start/docker.md' + - 'VaaS in Docker Compose': 'quick-start/docker_compose.md' - 'VaaS in Production': 'quick-start/production.md' - 'Documentation': - 'VaaS request flow': 'documentation/flow.md' diff --git a/vaas/requirements/base.txt b/vaas/requirements/base.txt index a19fc95b..c4f56708 100644 --- a/vaas/requirements/base.txt +++ b/vaas/requirements/base.txt @@ -1,3 +1,4 @@ +uwsgi django==3.1.14 django-nose==1.4.7 enum34==1.1.10 diff --git a/vaas/vaas/resources/base-data.yaml b/vaas/vaas/resources/base-data.yaml new file mode 100644 index 00000000..c27b59c9 --- /dev/null +++ b/vaas/vaas/resources/base-data.yaml @@ -0,0 +1,19 @@ +- model: auth.user + fields: + password: pbkdf2_sha256$36000$HSNx3yHNXG51$yggojN+90XWiHuGBK7YnrUZMWtMKpck45CsSel0JxUk= + last_login: '2019-11-19T11:24:56.296352+00:00' + is_superuser: true + username: admin + first_name: '' + last_name: '' + email: admin@vaas.example.com + is_staff: true + is_active: true + date_joined: '2019-11-13T07:46:40.829872+00:00' + groups: [] + user_permissions: [] +- model: tastypie.apikey + pk: 1 + fields: + key: vagrant_api_key + user_id: 1 \ No newline at end of file diff --git a/vaas/vaas/resources/data.yaml b/vaas/vaas/resources/dev-data.yaml similarity index 100% rename from vaas/vaas/resources/data.yaml rename to vaas/vaas/resources/dev-data.yaml