Skip to content

Commit 45f562b

Browse files
committed
Initial commit
0 parents  commit 45f562b

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

README.md

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Python Flask Docker image
2+
3+
[![Build Status](https://travis-ci.org/devilbox/docker-python-flask.svg?branch=master)](https://travis-ci.org/devilbox/docker-python-flask)
4+
[![Tag](https://img.shields.io/github/tag/devilbox/docker-python-flask.svg)](https://github.com/devilbox/docker-python-flask/releases)
5+
[![Gitter](https://badges.gitter.im/devilbox/Lobby.svg)](https://gitter.im/devilbox/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6+
[![Discourse](https://img.shields.io/discourse/https/devilbox.discourse.group/status.svg?colorB=%234CB697)](https://devilbox.discourse.group)
7+
[![type](https://img.shields.io/badge/type-Docker-blue.svg)](https://hub.docker.com/r/devilbox/python-flask)
8+
[![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT)
9+
10+
This project provides a Python Flask Docker image for development purposes.
11+
12+
13+
## Docker image tags
14+
15+
* **Image name:** `devilbox/python-flask`
16+
17+
### Rolling tags
18+
19+
| Image tag | Python version |
20+
|-----------|----------------|
21+
| `3.8-dev` | Latest 3.8.x |
22+
| `3.7-dev` | Latest 3.7.x |
23+
| `3.6-dev` | Latest 3.6.x |
24+
| `3.5-dev` | Latest 3.5.x |
25+
| `2.7-dev` | Latest 2.7.x |
26+
27+
28+
### Release tags
29+
30+
Release tags are fixed and bound to git tags.
31+
32+
| Image Tag | Python version |
33+
|---------------------|----------------|
34+
| `3.8-dev-<git-tag>` | Latest 3.8.x |
35+
| `3.7-dev-<git-tag>` | Latest 3.7.x |
36+
| `3.6-dev-<git-tag>` | Latest 3.6.x |
37+
| `3.5-dev-<git-tag>` | Latest 3.5.x |
38+
| `2.7-dev-<git-tag>` | Latest 2.7.x |
39+
40+
41+
## Example
42+
43+
For easy usage, there is a Docker Compose example project included.
44+
```bash
45+
cp .env.example .env
46+
docker-compose up
47+
```
48+
```bash
49+
curl localhost:3000
50+
```
51+
52+
53+
## Environment Variables
54+
55+
| Variable | Required | Description |
56+
|-----------------|----------|-------------|
57+
| `FLASK_PROJECT` | Yes | The directory name in `/shared/httpd/` to serve [1] |
58+
| `FLASK_APP` | | The main entrypoint file name (default is `main.py`) |
59+
| `FLASK_PORT` | | Docker internal port to serve the application (default is `3000`) |
60+
| `NEW_UID` | | User id of the host system to ensure syncronized permissions between host and container |
61+
| `NEW_GID` | | Group id of the host system to ensure syncronized permissions between host and container |
62+
63+
* [1] See [Project directory structure](#project-directory-structure) for usage
64+
65+
66+
## Project directory structure
67+
68+
The following shows how to organize your project on the host operating system.
69+
70+
### Basic structure
71+
72+
The following is the least required directory structure:
73+
```bash
74+
<project-dir>/
75+
└── app # Must be named 'app'
76+
   └── main.py # Entrypoint name can be changed via env var [1]
77+
```
78+
79+
* [1] Use the `FLASK_APP` environment variable to defined the file for the entrypoint in `<project-dir>/app/`. Example: `FLASK_APP=test.py`.
80+
81+
82+
### Structure with dependencies
83+
84+
The following directory structure allows for auto-installing Python dependencies during startup into a virtual env.
85+
```bash
86+
<project-dir>/
87+
├── app # Must be named 'app'
88+
│   ├── __init__.py
89+
│   └── main.py # Entrypoint name can be changed via env var
90+
└── requirements.txt # Optional: will pip install in virtual env
91+
```
92+
93+
After you've started the container with a `requirements.txt` in place, a new `venv/` directory will be added with you Python virtual env.
94+
```bash
95+
<project-dir>/
96+
├── app
97+
│   ├── __init__.py
98+
│   ├── main.py
99+
│   └── __pycache__
100+
├── requirements.txt
101+
└── venv
102+
├── bin
103+
├── include
104+
└── lib
105+
```
106+
107+
### Mounting your project
108+
109+
When using this image, you need to mount your project directory into `/shared/httpd/` into the container:
110+
```bash
111+
docker run \
112+
--rm \
113+
-v $(pwd)/<project-dir>:/shared/httpd/<project-dir> \
114+
devilbox/python-flask:3.9-dev
115+
```
116+
117+
If your local uid or gid are not 1000, you should set them accordingly via env vars to ensure to syncronize file system permissions across the container and your host system.
118+
```bash
119+
docker run \
120+
--rm \
121+
-v $(pwd)/<project-dir>:/shared/httpd/<project-dir> \
122+
-e NEW_UID=$(id -u) \
123+
-e NEW_GID=$(id -g) \
124+
devilbox/python-flask:3.9-dev
125+
```
126+
127+
128+
## Build locally
129+
```bash
130+
# Build default version (Python 3.8)
131+
make build
132+
133+
# Build specific version
134+
make build PYTHON=3.7
135+
```
136+
137+
138+
## Test locally
139+
```bash
140+
# Test default version (Python 3.8)
141+
make test
142+
143+
# Test specific version
144+
make test PYTHON=3.7
145+
```
146+
147+
148+
## License
149+
150+
**[MIT License](LICENSE)**
151+
152+
Copyright (c) 2019 [cytopia](https://github.com/cytopia)

0 commit comments

Comments
 (0)