From 7ec9f53e451531374a94c358c270fbf9a65222c2 Mon Sep 17 00:00:00 2001 From: ludyn Date: Fri, 8 Jan 2021 12:18:07 +0100 Subject: [PATCH] init --- .gitignore | 19 +++++++++++++++++++ README.md | 9 +++++++++ app/hello.py | 8 ++++++++ app/requirements.txt | 1 + app/scripts/startup.sh | 14 ++++++++++++++ docker-compose.yaml | 12 ++++++++++++ docker/Dockerfile | 30 ++++++++++++++++++++++++++++++ 7 files changed, 93 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 app/hello.py create mode 100644 app/requirements.txt create mode 100755 app/scripts/startup.sh create mode 100644 docker-compose.yaml create mode 100644 docker/Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0825fa5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# ignore files with below extensions +*.pyc +*.pyo +*.log +*.sqlite3 + +# ignore below files +.coverage +yarn.lock +package-lock.json +.env.secrets +.ash_history +.bash_history + +# ignore below directories +__pycache__/ +node_modules/ +.cache/ +.pytest_cache/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb3d40d --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Description + +Plain flask init project. + +# Instructions + +```bash +$ docker-compose up +``` diff --git a/app/hello.py b/app/hello.py new file mode 100644 index 0000000..5e7e5f1 --- /dev/null +++ b/app/hello.py @@ -0,0 +1,8 @@ +from flask import Flask + + +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World!' \ No newline at end of file diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..2077213 --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1 @@ +Flask \ No newline at end of file diff --git a/app/scripts/startup.sh b/app/scripts/startup.sh new file mode 100755 index 0000000..2ef009e --- /dev/null +++ b/app/scripts/startup.sh @@ -0,0 +1,14 @@ +#!/bin/ash + +echo "Install requirements.txt" +pip install -r /app/requirements.txt --no-cache-dir + +# is $@ empty +if [ -z "$@" ] +then + echo "Run App" + flask run --host=0.0.0.0 --port=$PORT +else + echo "Executeing \$@ command: $@" + exec $@ +fi \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6bd5c63 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +version: "3.8" +services: + app: + build: + context: ./app + dockerfile: ../docker/Dockerfile + image: flask/demo + container_name: flask-demo + hostname: flask-dev-demo + volumes: + - ./app:/app + # command: sleep 3600 \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..866ec1e --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,30 @@ +FROM python:3.7.9-alpine + +ARG PORT=8000 +ENV PORT=$PORT +ARG FLASK_APP=/app/hello.py +ENV FLASK_APP=$FLASK_APP + +ENV HOME=/app +ENV PYTHONUNBUFFERED=True +ENV PYTHONIOENCODING=UTF-8 + +WORKDIR /app +COPY . /app + +# Fixed permissions, create exec:exec and dev:dev +RUN sed -i '/999/d;' /etc/group +RUN addgroup -S -g 999 exec && adduser -u 999 -s /sbin/nologin -SDHG exec exec +RUN adduser -DH dev && adduser exec dev +RUN chown -R exec:dev \ + /app \ + /usr/local/bin/ \ + /usr/local/lib/python3.7/ +RUN chmod -R a-w /etc + +VOLUME /app +EXPOSE ${PORT} + +USER exec:dev + +ENTRYPOINT ["/app/scripts/startup.sh"] \ No newline at end of file