From eabc7b2224fd37bc93be7a25e6f720aaf994b3a8 Mon Sep 17 00:00:00 2001 From: Christian M Date: Mon, 28 Jan 2019 19:02:59 +0100 Subject: [PATCH 1/8] added Dockerfile --- Dockerfile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..31557e98 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:alpine3.6 +ARG VERSION=v0.6.6 + +ENV PYTHONUNBUFFERED 1 + +RUN apk add --no-cache shadow +RUN useradd --user-group --create-home --home-dir /flask --shell /bin/false flask + +RUN apk add --no-cache linux-headers make gcc musl-dev libxml2-dev libxslt-dev libffi-dev postgresql-dev git + +RUN pip install --upgrade pip && pip install --no-cache-dir -e git+https://github.com/briancappello/flask-unchained.git@${VERSION}#egg=flask-unchained + +WORKDIR /flask/src + +USER flask + +CMD ["flask","run"] \ No newline at end of file From 422a4b0ca3665a4bb9f165c50b38bbd2ae88530d Mon Sep 17 00:00:00 2001 From: Christian M Date: Mon, 28 Jan 2019 19:48:41 +0100 Subject: [PATCH 2/8] added host and port to run command in dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 31557e98..854a5f88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ WORKDIR /flask/src USER flask -CMD ["flask","run"] \ No newline at end of file +CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"] \ No newline at end of file From 508fea57672352b04362d1d0fc3823105eef2ebd Mon Sep 17 00:00:00 2001 From: Christian M Date: Mon, 28 Jan 2019 20:32:46 +0100 Subject: [PATCH 3/8] added expose 5000 to dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 854a5f88..4ac866f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,5 @@ WORKDIR /flask/src USER flask -CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"] \ No newline at end of file +CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"] +EXPOSE 5000 \ No newline at end of file From 1a6b8138bffb149f862daa093959b2d43ac08c08 Mon Sep 17 00:00:00 2001 From: Christian M Date: Tue, 29 Jan 2019 10:25:09 +0100 Subject: [PATCH 4/8] documented docker and docker-compose --- docs/tutorial/docker.rst | 89 ++++++++++++++++++++++++++++++++++++++++ docs/tutorial/index.rst | 1 + 2 files changed, 90 insertions(+) create mode 100644 docs/tutorial/docker.rst diff --git a/docs/tutorial/docker.rst b/docs/tutorial/docker.rst new file mode 100644 index 00000000..fb5f9db9 --- /dev/null +++ b/docs/tutorial/docker.rst @@ -0,0 +1,89 @@ +Docker Container +-------------------- + +Running a flask app in a docker container is a comfortable way to avoid dependency installation. + +Build Container +^^^^^^^^^^^^^^^ + +Change into flask-unchained source folder. Then run docker build command: + +.. code:: bash + + docker build -t briancappello/flask-unchained . + +The container will be built and tagged with the name briancappello/flask-unchained. + +Run Container +^^^^^^^^^^^^^ + +Change into your project folder created with 'flask new project PROJECT'. +Then run a container mounting your project's folder: + +.. code:: bash + + docker run -d --name PROJECT -p 5000:5000 -v "$(pwd)":/flask/src briancappello/flask-unchained + +Your app runs now on localhost:5000. + +Build Custom Container +^^^^^^^^^^^^^^^^^^^^^^ + +If you want dockerize your project you can create a Dockerfile in your project's folder. + +.. code:: docker + + # Dockerfile + + FROM briancappello/flask-unchained + COPY . . + RUN pip install -r requirements-dev.txt && pip install -r requirements.txt + +Then you can build and run your custom container as described above. + +.. code:: bash + + docker build -t PROJECT . + docker run -d --name PROJECT -p 5000:5000 -v "$(pwd)":/flask/src PROJECT + +Docker Compose +^^^^^^^^^^^^^^ + +Docker Compose is a tool to configure containers, mountpoints and ports. +A simple compose file for an flask-unchained project is following: + +.. code:: yaml + + # docker-compose.yml + + version: '3' + services: + postgres: + image: postgres:9.6.5 + + redis: + image: redis:3.2-alpine + command: redis-server + expose: + - 6379 + + app: + build: + context: . + dockerfile: Dockerfile + links: + - postgres + - redis + environment: + - FLASK_DATABASE_HOST=postgres + - FLASK_REDIS_HOST=redis + command: flask run --host 0.0.0.0 --port 5000 + ports: + - 5000:5000 + volumes: + - .:/flask/src + +This file in project's folder and a simple command 'docker-compose up' starts +the app. +In this example next to the app container, one for postgres database and one for redis are started too. +They are available through their hostnames postgres and redis within the app container. \ No newline at end of file diff --git a/docs/tutorial/index.rst b/docs/tutorial/index.rst index 51abe48c..0e4d68f4 100644 --- a/docs/tutorial/index.rst +++ b/docs/tutorial/index.rst @@ -13,6 +13,7 @@ Tutorial session security building_the_portfolio + docker This tutorial will walk you through creating a basic portfolio application for monitoring your investments. Users will be able to register, log in, create portfolios and manage the stocks in them. You will be able to package and install the application on other computers. From 2931b28344aa334678268fdc54d12a99281be096 Mon Sep 17 00:00:00 2001 From: Christian M Date: Thu, 31 Jan 2019 10:05:11 +0100 Subject: [PATCH 5/8] upgraded version v0.7.0 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ac866f8..23826d35 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM python:alpine3.6 -ARG VERSION=v0.6.6 +ARG VERSION=v0.7.0 ENV PYTHONUNBUFFERED 1 @@ -15,4 +15,4 @@ WORKDIR /flask/src USER flask CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"] -EXPOSE 5000 \ No newline at end of file +EXPOSE 5000 From 1e0d74ac157d5b0ead4df86164c961e88adb3935 Mon Sep 17 00:00:00 2001 From: Christian M Date: Fri, 1 Feb 2019 04:18:02 +0100 Subject: [PATCH 6/8] upgraded docker container versions --- Dockerfile | 2 +- docs/tutorial/docker.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 23826d35..6a802cb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:alpine3.6 +FROM python:3.7-alpine3.8 ARG VERSION=v0.7.0 ENV PYTHONUNBUFFERED 1 diff --git a/docs/tutorial/docker.rst b/docs/tutorial/docker.rst index fb5f9db9..aecaa70b 100644 --- a/docs/tutorial/docker.rst +++ b/docs/tutorial/docker.rst @@ -59,10 +59,10 @@ A simple compose file for an flask-unchained project is following: version: '3' services: postgres: - image: postgres:9.6.5 + image: postgres:11.1-alpine redis: - image: redis:3.2-alpine + image: redis:5.0-alpine command: redis-server expose: - 6379 From c6c98baaab09a0e4140f35c0bd34f8ed24685271 Mon Sep 17 00:00:00 2001 From: Christian M Date: Tue, 5 Feb 2019 09:00:46 +0100 Subject: [PATCH 7/8] added Dockerfile for stretch as base --- Dockerfile => docker/alpine.Dockerfile | 0 docker/stretch.Dockerfile | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) rename Dockerfile => docker/alpine.Dockerfile (100%) create mode 100644 docker/stretch.Dockerfile diff --git a/Dockerfile b/docker/alpine.Dockerfile similarity index 100% rename from Dockerfile rename to docker/alpine.Dockerfile diff --git a/docker/stretch.Dockerfile b/docker/stretch.Dockerfile new file mode 100644 index 00000000..db9e4d43 --- /dev/null +++ b/docker/stretch.Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.7-stretch +ARG VERSION=v0.7.0 + +ENV PYTHONUNBUFFERED 1 + +RUN useradd --user-group --create-home --home-dir /flask --shell /bin/false flask + +RUN apt-get update && apt-get install -y build-essential libxml2-dev libxslt-dev libffi-dev libpq-dev git + +RUN pip install --upgrade pip && pip install --no-cache-dir -e git+https://github.com/briancappello/flask-unchained.git@${VERSION}#egg=flask-unchained + +WORKDIR /flask/src + +USER flask + +CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"] +EXPOSE 5000 From f4d469a446570c2ab4eba3a63d69836f3f1e6f87 Mon Sep 17 00:00:00 2001 From: Christian M Date: Thu, 7 Feb 2019 10:47:00 +0100 Subject: [PATCH 8/8] change python to version 3.6 in dockerfiles as celery is not 3.7 compatible --- docker/alpine.Dockerfile | 2 +- docker/stretch.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/alpine.Dockerfile b/docker/alpine.Dockerfile index 6a802cb8..9b0fe8d1 100644 --- a/docker/alpine.Dockerfile +++ b/docker/alpine.Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine3.8 +FROM python:3.6-alpine3.8 ARG VERSION=v0.7.0 ENV PYTHONUNBUFFERED 1 diff --git a/docker/stretch.Dockerfile b/docker/stretch.Dockerfile index db9e4d43..43a15b13 100644 --- a/docker/stretch.Dockerfile +++ b/docker/stretch.Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-stretch +FROM python:3.6-stretch ARG VERSION=v0.7.0 ENV PYTHONUNBUFFERED 1