-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from realpython/docker
added docker
- Loading branch information
Showing
15 changed files
with
308 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
sudo rm /usr/local/bin/docker-compose | ||
curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose | ||
chmod +x docker-compose | ||
sudo mv docker-compose /usr/local/bin |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM python:3.6.5 | ||
|
||
# install environment dependencies | ||
RUN apt-get update -yqq \ | ||
&& apt-get install -yqq --no-install-recommends \ | ||
netcat \ | ||
&& apt-get -q clean | ||
|
||
# set working directory | ||
RUN mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
|
||
# add requirements | ||
COPY ./requirements.txt /usr/src/app/requirements.txt | ||
|
||
# install requirements | ||
RUN pip install -r requirements.txt | ||
|
||
# add entrypoint.sh | ||
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh | ||
|
||
# add app | ||
COPY . /usr/src/app | ||
|
||
# run server | ||
CMD ["./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Flask Skeleton | ||
|
||
## Quick Start | ||
|
||
Install Cookiecutter globally: | ||
|
||
```sh | ||
$ pip install cookiecutter | ||
``` | ||
|
||
Generate the boilerplate: | ||
|
||
```sh | ||
$ cookiecutter https://github.com/realpython/cookiecutter-flask-skeleton.git | ||
``` | ||
|
||
Review the set up guides to configure the app: | ||
|
||
1. [setup-with-docker.md](setup-with-docker.md) | ||
1. [setup-without-docker](setup-without-docker.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
version: '3.5' | ||
|
||
services: | ||
|
||
web: | ||
image: web | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile | ||
volumes: | ||
- '.:/usr/src/app' | ||
ports: | ||
- 5002:5000 | ||
environment: | ||
- APP_NAME={{cookiecutter.app_name}} | ||
- FLASK_DEBUG=1 | ||
- PYTHONUNBUFFERED=0 | ||
- APP_SETTINGS=project.server.config.DevelopmentConfig | ||
- DATABASE_URL=postgres://postgres:postgres@web-db:5432/users_dev | ||
- DATABASE_TEST_URL=postgres://postgres:postgres@web-db:5432/users_test | ||
- SECRET_KEY=change_me_in_prod | ||
depends_on: | ||
- web-db | ||
|
||
web-db: | ||
container_name: web-db | ||
build: | ||
context: ./project/server/db | ||
dockerfile: Dockerfile | ||
ports: | ||
- 5435:5432 | ||
environment: | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Docker Setup | ||
|
||
Use this guide if you want to use Docker in your project. | ||
|
||
> Built with Docker v18.03.0-ce. | ||
## Quick Start | ||
|
||
### Basics | ||
|
||
Install Cookiecutter globally: | ||
|
||
```sh | ||
$ pip install cookiecutter | ||
``` | ||
|
||
Generate the boilerplate: | ||
|
||
```sh | ||
$ cookiecutter https://github.com/realpython/cookiecutter-flask-skeleton.git | ||
``` | ||
|
||
Update the environment variables in *docker-compose.yml*, and then build the images and spin up the containers: | ||
|
||
```sh | ||
$ docker-compose up -d --build | ||
``` | ||
|
||
Create the database: | ||
|
||
```sh | ||
$ docker-compose run web python manage.py create_db | ||
$ docker-compose run web python manage.py db init | ||
$ docker-compose run web python manage.py db migrate | ||
$ docker-compose run web python manage.py create_admin | ||
$ docker-compose run web python manage.py create_data | ||
``` | ||
|
||
Access the application at the address [http://localhost:5002/](http://localhost:5002/) | ||
|
||
### Testing | ||
|
||
Test without coverage: | ||
|
||
```sh | ||
$ docker-compose run web python manage.py test | ||
``` | ||
|
||
Test with coverage: | ||
|
||
```sh | ||
$ docker-compose run web python manage.py cov | ||
``` | ||
|
||
Lint: | ||
|
||
```sh | ||
$ docker-compose run web flake8 project | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
echo "Waiting for postgres..." | ||
|
||
while ! nc -z web-db 5432; do | ||
sleep 0.1 | ||
done | ||
|
||
echo "PostgreSQL started" | ||
|
||
python manage.py run -h 0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM postgres | ||
|
||
# run create.sql on init | ||
ADD create.sql /docker-entrypoint-initdb.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE DATABASE users_prod; | ||
CREATE DATABASE users_stage; | ||
CREATE DATABASE users_dev; | ||
CREATE DATABASE users_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Docker Setup | ||
|
||
Use this guide if you want to use Docker in your project. | ||
|
||
> Built with Docker v18.03.0-ce. | ||
## Getting Started | ||
|
||
Update the environment variables in *docker-compose.yml*, and then build the images and spin up the containers: | ||
|
||
```sh | ||
$ docker-compose up -d --build | ||
``` | ||
|
||
Create the database: | ||
|
||
```sh | ||
$ docker-compose run web python manage.py create_db | ||
$ docker-compose run web python manage.py db init | ||
$ docker-compose run web python manage.py db migrate | ||
$ docker-compose run web python manage.py create_admin | ||
$ docker-compose run web python manage.py create_data | ||
``` | ||
|
||
Access the application at the address [http://localhost:5002/](http://localhost:5002/) | ||
|
||
### Testing | ||
|
||
Test without coverage: | ||
|
||
```sh | ||
$ docker-compose run web python manage.py test | ||
``` | ||
|
||
Test with coverage: | ||
|
||
```sh | ||
$ docker-compose run web python manage.py cov | ||
``` | ||
|
||
Lint: | ||
|
||
```sh | ||
$ docker-compose run web flake8 project | ||
``` |
Oops, something went wrong.