From c848b554fa08fac23cf42ca84ed32eda7065d4a1 Mon Sep 17 00:00:00 2001 From: Michael Chow Date: Sat, 14 Mar 2020 20:36:54 -0400 Subject: [PATCH] dockerize running app --- .env.example | 1 + .gitignore | 1 + Dockerfile | 15 +++++++++++++++ README.md | 14 +++++++++++++- docker-compose.yml | 8 ++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..3646d14f --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +PORT=8000 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..4c49bd78 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..d1c34f62 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.7.7-buster + +WORKDIR /app + +COPY ./requirements.txt /app/requirements.txt + +RUN pip install -r requirements.txt + +COPY . ./ + +RUN chmod u+x setup.sh && PORT=8000 ./setup.sh + +# expanding shell variables in CMD is tricky, see +# https://stackoverflow.com/questions/23071214/use-environment-variables-in-cmd +CMD ["streamlit", "run", "--server.port", "8000", "app.py"] diff --git a/README.md b/README.md index e376cc4d..98339df0 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,19 @@ To test the app locally just run: This will open a browser window with the app running. +### Developing with docker + +Copy `.env.example` to be `.env` and run the container. + +```bash +cp .env.example .env +docker-compose up +``` + +You should be able to view the app via `localhost:8000`. If you want to change the +port, then set `PORT` in the `.env` file. + ## Deployment **Before you push your changes to master make sure that everything works in development mode.** -Changes merged to `master` will be automatically deployed to [pennchime.herokuapp.com](https://pennchime.herokuapp.com/). \ No newline at end of file +Changes merged to `master` will be automatically deployed to [pennchime.herokuapp.com](https://pennchime.herokuapp.com/). diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..f90ac249 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.1' + +services: + app: + build: . + restart: always + ports: + - "${PORT}:8000"