diff options
| author | jfriedli | 2019-08-28 08:33:28 -0700 |
|---|---|---|
| committer | jvoisin | 2019-08-28 08:33:28 -0700 |
| commit | 3a3d1227558a2c405456e3ddab451675e7bbd552 (patch) | |
| tree | 4d59c165e4bcfdac629d6271f2905cd8cbb9c344 | |
| parent | 08ce6aed7662ecf5586d6782ef6449c2ec564ed9 (diff) | |
Resolve "Create a docker image"
Diffstat (limited to '')
| -rw-r--r-- | .gitlab-ci.yml | 17 | ||||
| -rw-r--r-- | Dockerfile | 8 | ||||
| -rw-r--r-- | Dockerfile.development | 15 | ||||
| -rw-r--r-- | Dockerfile.production | 24 | ||||
| -rw-r--r-- | README.md | 21 | ||||
| -rw-r--r-- | config/uwsgi.config | 2 | ||||
| -rw-r--r-- | docker-compose.yml | 4 | ||||
| -rw-r--r-- | main.py | 3 | ||||
| -rw-r--r-- | startup-server.sh | 3 |
9 files changed, 85 insertions, 12 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9c2b39e..481d32a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml | |||
| @@ -1,9 +1,14 @@ | |||
| 1 | image: debian:testing | 1 | image: debian:testing |
| 2 | 2 | ||
| 3 | stages: | 3 | stages: |
| 4 | - build | ||
| 4 | - linting | 5 | - linting |
| 5 | - test | 6 | - test |
| 6 | 7 | ||
| 8 | variables: | ||
| 9 | CONTAINER_TEST_IMAGE: registry.0xacab.org/jvoisin/mat2-web:$CI_BUILD_REF_NAME | ||
| 10 | CONTAINER_RELEASE_IMAGE: registry.0xacab.org/jvoisin/mat2-web:latest | ||
| 11 | |||
| 7 | pyflakes: | 12 | pyflakes: |
| 8 | stage: linting | 13 | stage: linting |
| 9 | script: | 14 | script: |
| @@ -28,3 +33,15 @@ tests:debian: | |||
| 28 | - pip3 install -r requirements.txt | 33 | - pip3 install -r requirements.txt |
| 29 | - python3-coverage run --branch --include main.py -m unittest discover -s test | 34 | - python3-coverage run --branch --include main.py -m unittest discover -s test |
| 30 | - python3-coverage report -m | 35 | - python3-coverage report -m |
| 36 | |||
| 37 | build-docker: | ||
| 38 | stage: build | ||
| 39 | image: | ||
| 40 | name: gcr.io/kaniko-project/executor:debug | ||
| 41 | entrypoint: [""] | ||
| 42 | script: | ||
| 43 | - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json | ||
| 44 | - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile.production --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG | ||
| 45 | only: | ||
| 46 | - tags | ||
| 47 | - master \ No newline at end of file | ||
diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 5ca3fd8..0000000 --- a/Dockerfile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | FROM python:3.7 | ||
| 2 | ADD . /mat2-web | ||
| 3 | WORKDIR /mat2-web | ||
| 4 | RUN apt-get update | ||
| 5 | RUN apt install -y python3-gi python3-gi-cairo gir1.2-poppler-0.18 \ | ||
| 6 | gir1.2-gdkpixbuf-2.0 libimage-exiftool-perl libgirepository1.0-dev | ||
| 7 | RUN pip install -r requirements.txt | ||
| 8 | CMD flask run --host=0.0.0.0 \ No newline at end of file | ||
diff --git a/Dockerfile.development b/Dockerfile.development new file mode 100644 index 0000000..b804959 --- /dev/null +++ b/Dockerfile.development | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | FROM python:3.7 | ||
| 2 | ADD . /mat2-web | ||
| 3 | WORKDIR /mat2-web | ||
| 4 | RUN apt-get update \ | ||
| 5 | && apt-get install --no-install-recommends --no-install-suggests --yes \ | ||
| 6 | python3-gi \ | ||
| 7 | python3-gi-cairo \ | ||
| 8 | gir1.2-poppler-0.18 \ | ||
| 9 | gir1.2-gdkpixbuf-2.0 \ | ||
| 10 | libimage-exiftool-perl \ | ||
| 11 | libgirepository1.0-dev \ | ||
| 12 | && pip install -r requirements.txt \ | ||
| 13 | && rm -rf /var/cache/apt/* /var/lib/apt/lists/* | ||
| 14 | CMD flask run --host=0.0.0.0 | ||
| 15 | |||
diff --git a/Dockerfile.production b/Dockerfile.production new file mode 100644 index 0000000..1d5b0a1 --- /dev/null +++ b/Dockerfile.production | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | From debian:buster-slim | ||
| 2 | WORKDIR /var/www/mat2-web | ||
| 3 | COPY . /var/www/mat2-web | ||
| 4 | RUN apt-get update \ | ||
| 5 | && apt-get install --no-install-recommends --no-install-suggests --yes \ | ||
| 6 | systemd \ | ||
| 7 | mat2 \ | ||
| 8 | uwsgi \ | ||
| 9 | uwsgi-plugin-python3 \ | ||
| 10 | nginx-light \ | ||
| 11 | python3-pip \ | ||
| 12 | python3-setuptools \ | ||
| 13 | python3-wheel \ | ||
| 14 | && rm -rf /var/cache/apt/* /var/lib/apt/lists/* \ | ||
| 15 | && pip3 install -r requirements.txt \ | ||
| 16 | && mkdir ./uploads \ | ||
| 17 | && chown -R www-data:www-data . \ | ||
| 18 | && cp ./config/uwsgi.config /etc/uwsgi/apps-enabled/mat2-web.ini \ | ||
| 19 | && rm /etc/nginx/sites-enabled/default \ | ||
| 20 | && mkdir -p /etc/nginx/sites-enabled/ \ | ||
| 21 | && cp ./config/nginx.config /etc/nginx/sites-enabled/mat2.conf \ | ||
| 22 | && chmod +x ./startup-server.sh | ||
| 23 | |||
| 24 | CMD ["./startup-server.sh"] \ No newline at end of file | ||
| @@ -35,7 +35,7 @@ configure, feel free to copy | |||
| 35 | [this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/uwsgi.config) | 35 | [this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/uwsgi.config) |
| 36 | to `/etc/uwsgi/apps-enabled/mat2-web.ini` and | 36 | to `/etc/uwsgi/apps-enabled/mat2-web.ini` and |
| 37 | [this one](https://0xacab.org/jvoisin/mat2-web/tree/master/config/nginx.config) | 37 | [this one](https://0xacab.org/jvoisin/mat2-web/tree/master/config/nginx.config) |
| 38 | to `/etc/nginx/site-enabled/mat2-web`. | 38 | to `/etc/nginx/sites-enabled/mat2-web`. |
| 39 | 39 | ||
| 40 | Nginx is the recommended web engine, but you can also use Apache if you prefer, | 40 | Nginx is the recommended web engine, but you can also use Apache if you prefer, |
| 41 | by copying [this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/apache2.config) | 41 | by copying [this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/apache2.config) |
| @@ -73,6 +73,18 @@ collector cronjob to remove leftover files. Besides, it can create a | |||
| 73 | the uploads folder, to ensure that the uploaded files won't be recoverable | 73 | the uploads folder, to ensure that the uploaded files won't be recoverable |
| 74 | between reboots. | 74 | between reboots. |
| 75 | 75 | ||
| 76 | |||
| 77 | # Deploy using Docker | ||
| 78 | You can find the ready to run docker image here: | ||
| 79 | https://0xacab.org/jvoisin/mat2-web/container_registry | ||
| 80 | |||
| 81 | Example: | ||
| 82 | `docker run -p 80:80 -d -e MAT2_ALLOW_ORIGIN_WHITELIST='https://myhost1.org' registry.0xacab.org/jvoisin/mat2-web:latest` | ||
| 83 | |||
| 84 | Make sure to add | ||
| 85 | `find /var/www/mat2-web/uploads/ -type f -mtime +1 -exec rm {} \;` as cron job | ||
| 86 | run inside the container. | ||
| 87 | |||
| 76 | # Development | 88 | # Development |
| 77 | Install docker and docker-compose and then run `docker-compose up` to setup | 89 | Install docker and docker-compose and then run `docker-compose up` to setup |
| 78 | the docker dev environment. Mat2-web is now accessible on your host machine at `localhost:5000`. | 90 | the docker dev environment. Mat2-web is now accessible on your host machine at `localhost:5000`. |
| @@ -137,6 +149,13 @@ The `file` parameter is the base64 encoded file which will be cleaned. | |||
| 137 | ] | 149 | ] |
| 138 | ``` | 150 | ``` |
| 139 | 151 | ||
| 152 | # Docker | ||
| 153 | There are two Dockerfiles present in this repository. The file called `Dockerfile.development` is used for development | ||
| 154 | and `Dockerfile.production` is used for production deployments. | ||
| 155 | |||
| 156 | You can find the automated docker builds in the registry of this | ||
| 157 | repository: https://0xacab.org/jvoisin/mat2-web/container_registry | ||
| 158 | |||
| 140 | # Custom templates | 159 | # Custom templates |
| 141 | 160 | ||
| 142 | You can override the default templates from `templates/` by putting replacements | 161 | You can override the default templates from `templates/` by putting replacements |
diff --git a/config/uwsgi.config b/config/uwsgi.config index 7108d33..177ddaf 100644 --- a/config/uwsgi.config +++ b/config/uwsgi.config | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | module=main | 2 | module=main |
| 3 | chdir = /var/www/mat2-web/ | 3 | chdir = /var/www/mat2-web/ |
| 4 | callable = app | 4 | callable = app |
| 5 | wsgi-file = main.py | 5 | wsgi-file = /var/www/mat2-web/main.py |
| 6 | master = true | 6 | master = true |
| 7 | workers = 1 | 7 | workers = 1 |
| 8 | 8 | ||
diff --git a/docker-compose.yml b/docker-compose.yml index fda006e..e758801 100644 --- a/docker-compose.yml +++ b/docker-compose.yml | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | version: '2' | 1 | version: '2' |
| 2 | services: | 2 | services: |
| 3 | web: | 3 | web: |
| 4 | build: . | 4 | build: |
| 5 | context: . | ||
| 6 | dockerfile: Dockerfile.development | ||
| 5 | environment: | 7 | environment: |
| 6 | - FLASK_APP=main.py | 8 | - FLASK_APP=main.py |
| 7 | - FLASK_ENV=development | 9 | - FLASK_ENV=development |
| @@ -187,6 +187,7 @@ def create_app(test_config=None): | |||
| 187 | 187 | ||
| 188 | return app | 188 | return app |
| 189 | 189 | ||
| 190 | app = create_app() | ||
| 190 | 191 | ||
| 191 | if __name__ == '__main__': # pragma: no cover | 192 | if __name__ == '__main__': # pragma: no cover |
| 192 | create_app().run() | 193 | app.run() |
diff --git a/startup-server.sh b/startup-server.sh new file mode 100644 index 0000000..d4449f7 --- /dev/null +++ b/startup-server.sh | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | /etc/init.d/nginx restart | ||
| 3 | uwsgi --ini /etc/uwsgi/apps-enabled/mat2-web.ini \ No newline at end of file | ||
