Commit 3a3d1227 authored by jfriedli's avatar jfriedli Committed by jvoisin

Resolve "Create a docker image"

parent 08ce6aed
Pipeline #26624 passed with stages
in 3 minutes and 28 seconds
image: debian:testing
stages:
- build
- linting
- test
variables:
CONTAINER_TEST_IMAGE: registry.0xacab.org/jvoisin/mat2-web:$CI_BUILD_REF_NAME
CONTAINER_RELEASE_IMAGE: registry.0xacab.org/jvoisin/mat2-web:latest
pyflakes:
stage: linting
script:
......@@ -28,3 +33,15 @@ tests:debian:
- pip3 install -r requirements.txt
- python3-coverage run --branch --include main.py -m unittest discover -s test
- python3-coverage report -m
build-docker:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile.production --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags
- master
\ No newline at end of file
FROM python:3.7
ADD . /mat2-web
WORKDIR /mat2-web
RUN apt-get update
RUN apt install -y python3-gi python3-gi-cairo gir1.2-poppler-0.18 \
gir1.2-gdkpixbuf-2.0 libimage-exiftool-perl libgirepository1.0-dev
RUN pip install -r requirements.txt
CMD flask run --host=0.0.0.0
\ No newline at end of file
FROM python:3.7
ADD . /mat2-web
WORKDIR /mat2-web
RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests --yes \
python3-gi \
python3-gi-cairo \
gir1.2-poppler-0.18 \
gir1.2-gdkpixbuf-2.0 \
libimage-exiftool-perl \
libgirepository1.0-dev \
&& pip install -r requirements.txt \
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/*
CMD flask run --host=0.0.0.0
From debian:buster-slim
WORKDIR /var/www/mat2-web
COPY . /var/www/mat2-web
RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests --yes \
systemd \
mat2 \
uwsgi \
uwsgi-plugin-python3 \
nginx-light \
python3-pip \
python3-setuptools \
python3-wheel \
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/* \
&& pip3 install -r requirements.txt \
&& mkdir ./uploads \
&& chown -R www-data:www-data . \
&& cp ./config/uwsgi.config /etc/uwsgi/apps-enabled/mat2-web.ini \
&& rm /etc/nginx/sites-enabled/default \
&& mkdir -p /etc/nginx/sites-enabled/ \
&& cp ./config/nginx.config /etc/nginx/sites-enabled/mat2.conf \
&& chmod +x ./startup-server.sh
CMD ["./startup-server.sh"]
\ No newline at end of file
......@@ -35,7 +35,7 @@ configure, feel free to copy
[this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/uwsgi.config)
to `/etc/uwsgi/apps-enabled/mat2-web.ini` and
[this one](https://0xacab.org/jvoisin/mat2-web/tree/master/config/nginx.config)
to `/etc/nginx/site-enabled/mat2-web`.
to `/etc/nginx/sites-enabled/mat2-web`.
Nginx is the recommended web engine, but you can also use Apache if you prefer,
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
the uploads folder, to ensure that the uploaded files won't be recoverable
between reboots.
# Deploy using Docker
You can find the ready to run docker image here:
https://0xacab.org/jvoisin/mat2-web/container_registry
Example:
`docker run -p 80:80 -d -e MAT2_ALLOW_ORIGIN_WHITELIST='https://myhost1.org' registry.0xacab.org/jvoisin/mat2-web:latest`
Make sure to add
`find /var/www/mat2-web/uploads/ -type f -mtime +1 -exec rm {} \;` as cron job
run inside the container.
# Development
Install docker and docker-compose and then run `docker-compose up` to setup
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.
]
```
# Docker
There are two Dockerfiles present in this repository. The file called `Dockerfile.development` is used for development
and `Dockerfile.production` is used for production deployments.
You can find the automated docker builds in the registry of this
repository: https://0xacab.org/jvoisin/mat2-web/container_registry
# Custom templates
You can override the default templates from `templates/` by putting replacements
......
......@@ -2,7 +2,7 @@
module=main
chdir = /var/www/mat2-web/
callable = app
wsgi-file = main.py
wsgi-file = /var/www/mat2-web/main.py
master = true
workers = 1
......
version: '2'
services:
web:
build: .
build:
context: .
dockerfile: Dockerfile.development
environment:
- FLASK_APP=main.py
- FLASK_ENV=development
......
......@@ -187,6 +187,7 @@ def create_app(test_config=None):
return app
app = create_app()
if __name__ == '__main__': # pragma: no cover
create_app().run()
app.run()
#!/bin/bash
/etc/init.d/nginx restart
uwsgi --ini /etc/uwsgi/apps-enabled/mat2-web.ini
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment