Skip to content

Commit 6227672

Browse files
committed
Added production builds and fixed migration errors
1 parent 6031b20 commit 6227672

File tree

10 files changed

+144
-16
lines changed

10 files changed

+144
-16
lines changed

.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ FLASK_API_VERSION="1.1"
22
FLASK_SERVER_NAME="My API Project"
33
FLASK_SERVER_DESCRIPTION="Dockerized Flask API boilerplate using an LDAP and token-based authentication"
44
FLASK_SECRET_KEY="Some secret key"
5-
FLASK_LEVEL="dev" # dev, test or prod
6-
LOG_LEVEL="DEBUG" # DEBUG, INFO, WARNING or ERROR
75

86
LDAP_ORGANISATION="My Company"
97
LDAP_DOMAIN="mycompany.com"

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ before_install:
1111

1212
script:
1313
- docker-compose build
14+
- docker-compose -f prod.docker-compose.yml build

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Here you can take a look at the database architecture scheme :
3636

3737
> Reminder : there is no `password` field because we use LDAP for authentication.
3838
39+
## Why using LDAP authentication ?
40+
41+
LDAP services are used in a lot of companies and institutions around the world to manage their user accounts and rights in a central place.
42+
43+
With this boilerplate, you will be able to develop corporate-ready services AND avoid yourself the troubles of developing registration / password forgotten / change password / profile update code.
44+
3945
## Getting started (development)
4046

4147
The API is made to run with an LDAP server for managing users. Whether use the provided Docker LDAP server or remove the conf. in [`docker-compose.yml`](./docker-compose.yml) and use your own LDAP server.
@@ -54,7 +60,7 @@ This section will explain to you how to run this project and set-up the LDAP ser
5460
5561
2. Change the database/LDAP passwords and keys in `.env`
5662
57-
You can now run :
63+
Then run :
5864
5965
```bash
6066
docker-compose up ldap phpldapadmin database adminer -d
@@ -93,19 +99,11 @@ docker-compose up --build -d api
9399
94100
:clock9: NPM's initial install may take quite a lot of time
95101

96-
Start the app :
97-
98102
```bash
99103
# Expect several minutes for first launch (npm install)
100104
docker-compose up --build -d app
101105
```
102106

103-
You can now enjoy the app on [`http://localhost:8080`](http://localhost:8080)
107+
Enjoy the app on [`http://localhost:8080`](http://localhost:8080)
104108

105109
> :information_source: If you want to add a NPM package, just stop & re-launch `docker-compose up app`.
106-
107-
## Why using LDAP authentication ?
108-
109-
LDAP services are used in a lot of companies and institutions around the world to manage their user accounts and rights in a central place.
110-
111-
With this boilerplate, you will be able to develop corporate-ready services AND avoid yourself the troubles of developing registration / password forgotten / change password / profile update code.

api/app/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
app.app_context().push()
1717

1818
manager = Manager(app)
19-
migrate = Migrate(app, database.getDatabase())
19+
migrate = Migrate(app, database.getDatabase(), "/migrations")
2020
manager.add_command('db', MigrateCommand)
2121

2222
# Commands

api/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
# These commands are here because they must be run at runtime
23

34
python /app/manager.py db init
45

api/prod.Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.7-alpine
2+
3+
# python-ldap requirements
4+
RUN apk update && apk add openldap-dev libc-dev gcc g++
5+
6+
# psycopg2 requirements
7+
RUN apk add libpq python3-dev musl-dev postgresql-dev
8+
9+
COPY ./requirements.txt .
10+
RUN pip install -r requirements.txt
11+
12+
# Install WSGI server
13+
RUN pip install gunicorn==20.1.0
14+
15+
WORKDIR /app
16+
COPY ./app /app
17+
18+
# Run migrations and WSGI server
19+
COPY ./prod.entrypoint.sh /entrypoint.sh
20+
ENTRYPOINT [ "/entrypoint.sh" ]

api/prod.entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
# These commands are here because they must be run at runtime
3+
4+
python /app/manager.py db init
5+
6+
python /app/manager.py db migrate --message 'initial database migration'
7+
python /app/manager.py db upgrade
8+
9+
gunicorn manager:app -b 0.0.0.0:5000

app/prod.Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM node:13.0.1-alpine
2+
3+
ARG NODE_ENV
4+
5+
COPY ./app /app
6+
7+
WORKDIR '/app'
8+
RUN npm install
9+
RUN npm run build --production
10+
11+
RUN npm install -g serve
12+
13+
EXPOSE 3000
14+
ENTRYPOINT ["serve", "-l", "tcp://0.0.0.0:3000", "-s", "/app/build"]

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ services:
88
ldap:
99
image: osixia/openldap:1.3.0
1010
restart: always
11-
ports:
12-
- 389:389
13-
- 636:636
1411
env_file:
1512
- .env
1613
volumes:
@@ -61,6 +58,9 @@ services:
6158
- 5000:5000
6259
env_file:
6360
- .env
61+
environment:
62+
FLASK_LEVEL: "dev" # dev, test or prod
63+
LOG_LEVEL: "DEBUG" # DEBUG, INFO, WARNING or ERROR
6464
depends_on:
6565
- ldap
6666
- database

prod.docker-compose.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
version: "3.3"
2+
3+
services:
4+
5+
6+
# LDAP-related
7+
8+
ldap:
9+
image: osixia/openldap:1.3.0
10+
restart: always
11+
env_file:
12+
- .env
13+
volumes:
14+
- ldap_data:/var/lib/ldap
15+
- ldap_slapd:/etc/ldap/slapd.d
16+
17+
phpldapadmin:
18+
image: osixia/phpldapadmin:0.9.0
19+
restart: always
20+
ports:
21+
- 8081:443
22+
environment:
23+
PHPLDAPADMIN_LDAP_HOSTS: ldap
24+
depends_on:
25+
- ldap
26+
27+
28+
# Database-related
29+
30+
database:
31+
image: postgres:12.2-alpine
32+
restart: always
33+
env_file:
34+
- .env
35+
volumes:
36+
- database:/var/lib/postgresql/data
37+
38+
39+
# Service-related
40+
41+
api:
42+
build:
43+
context: ./api
44+
dockerfile: prod.Dockerfile
45+
image: flavienb/reactjs-flask-ldap-boilerplate-api:latest
46+
restart: always
47+
volumes:
48+
- api_logs:/logs
49+
- api_migrations:/migrations
50+
env_file:
51+
- .env
52+
environment:
53+
FLASK_LEVEL: "dev" # dev, test or prod
54+
LOG_LEVEL: "DEBUG" # DEBUG, INFO, WARNING or ERROR
55+
depends_on:
56+
- ldap
57+
- database
58+
59+
app:
60+
build:
61+
context: ./app
62+
dockerfile: prod.Dockerfile
63+
image: flavienb/reactjs-flask-ldap-boilerplate-app:latest
64+
restart: always
65+
environment:
66+
NODE_ENV: "production"
67+
CHOKIDAR_USEPOLLING: "false"
68+
69+
# We set-up NGINX to have a unique endpoint for app & api
70+
nginx:
71+
build:
72+
context: ./nginx
73+
dockerfile: prod.Dockerfile
74+
image: flavienb/reactjs-flask-ldap-boilerplate-nginx:latest
75+
restart: always
76+
ports:
77+
- "8080:80"
78+
volumes:
79+
- nginx_logs:/var/log/nginx
80+
81+
volumes:
82+
api_logs:
83+
nginx_logs:
84+
database:
85+
ldap_data:
86+
ldap_slapd:
87+
api_migrations:

0 commit comments

Comments
 (0)