summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfriedli2019-08-28 08:33:28 -0700
committerjvoisin2019-08-28 08:33:28 -0700
commit3a3d1227558a2c405456e3ddab451675e7bbd552 (patch)
tree4d59c165e4bcfdac629d6271f2905cd8cbb9c344
parent08ce6aed7662ecf5586d6782ef6449c2ec564ed9 (diff)
Resolve "Create a docker image"
-rw-r--r--.gitlab-ci.yml17
-rw-r--r--Dockerfile8
-rw-r--r--Dockerfile.development15
-rw-r--r--Dockerfile.production24
-rw-r--r--README.md21
-rw-r--r--config/uwsgi.config2
-rw-r--r--docker-compose.yml4
-rw-r--r--main.py3
-rw-r--r--startup-server.sh3
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 @@
1image: debian:testing 1image: debian:testing
2 2
3stages: 3stages:
4 - build
4 - linting 5 - linting
5 - test 6 - test
6 7
8variables:
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
7pyflakes: 12pyflakes:
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
37build-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 @@
1FROM python:3.7
2ADD . /mat2-web
3WORKDIR /mat2-web
4RUN apt-get update
5RUN apt install -y python3-gi python3-gi-cairo gir1.2-poppler-0.18 \
6gir1.2-gdkpixbuf-2.0 libimage-exiftool-perl libgirepository1.0-dev
7RUN pip install -r requirements.txt
8CMD 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 @@
1FROM python:3.7
2ADD . /mat2-web
3WORKDIR /mat2-web
4RUN 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/*
14CMD 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 @@
1From debian:buster-slim
2WORKDIR /var/www/mat2-web
3COPY . /var/www/mat2-web
4RUN 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
24CMD ["./startup-server.sh"] \ No newline at end of file
diff --git a/README.md b/README.md
index fd723c8..2546c5c 100644
--- a/README.md
+++ b/README.md
@@ -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)
36to `/etc/uwsgi/apps-enabled/mat2-web.ini` and 36to `/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)
38to `/etc/nginx/site-enabled/mat2-web`. 38to `/etc/nginx/sites-enabled/mat2-web`.
39 39
40Nginx is the recommended web engine, but you can also use Apache if you prefer, 40Nginx is the recommended web engine, but you can also use Apache if you prefer,
41by copying [this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/apache2.config) 41by 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
73the uploads folder, to ensure that the uploaded files won't be recoverable 73the uploads folder, to ensure that the uploaded files won't be recoverable
74between reboots. 74between reboots.
75 75
76
77# Deploy using Docker
78You can find the ready to run docker image here:
79https://0xacab.org/jvoisin/mat2-web/container_registry
80
81Example:
82`docker run -p 80:80 -d -e MAT2_ALLOW_ORIGIN_WHITELIST='https://myhost1.org' registry.0xacab.org/jvoisin/mat2-web:latest`
83
84Make sure to add
85`find /var/www/mat2-web/uploads/ -type f -mtime +1 -exec rm {} \;` as cron job
86run inside the container.
87
76# Development 88# Development
77Install docker and docker-compose and then run `docker-compose up` to setup 89Install docker and docker-compose and then run `docker-compose up` to setup
78the docker dev environment. Mat2-web is now accessible on your host machine at `localhost:5000`. 90the 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
153There are two Dockerfiles present in this repository. The file called `Dockerfile.development` is used for development
154and `Dockerfile.production` is used for production deployments.
155
156You can find the automated docker builds in the registry of this
157repository: https://0xacab.org/jvoisin/mat2-web/container_registry
158
140# Custom templates 159# Custom templates
141 160
142You can override the default templates from `templates/` by putting replacements 161You 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 @@
2module=main 2module=main
3chdir = /var/www/mat2-web/ 3chdir = /var/www/mat2-web/
4callable = app 4callable = app
5wsgi-file = main.py 5wsgi-file = /var/www/mat2-web/main.py
6master = true 6master = true
7workers = 1 7workers = 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 @@
1version: '2' 1version: '2'
2services: 2services:
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
diff --git a/main.py b/main.py
index 75299de..b059bfe 100644
--- a/main.py
+++ b/main.py
@@ -187,6 +187,7 @@ def create_app(test_config=None):
187 187
188 return app 188 return app
189 189
190app = create_app()
190 191
191if __name__ == '__main__': # pragma: no cover 192if __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
3uwsgi --ini /etc/uwsgi/apps-enabled/mat2-web.ini \ No newline at end of file