Skip to content

Commit f3558e5

Browse files
Deployment enh - Docker, Heroku, Gunicorn
1 parent e4a23e1 commit f3558e5

File tree

18 files changed

+241
-152
lines changed

18 files changed

+241
-152
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
DEBUG=True
22
SECRET_KEY=s3cr3t_key
33
DATABASE_URL=sqlite:////tmp/db.sqlite3
4-
PROD_HOST=django-dashboard-black.herokuapp.com

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ venv
2020

2121
# javascript
2222
package-lock.json
23+
24+
staticfiles/*
25+
!staticfiles/.gitkeep

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.6
2+
3+
ENV FLASK_APP run.py
4+
5+
COPY manage.py gunicorn-cfg.py requirements.txt .env ./
6+
COPY app app
7+
COPY authentication authentication
8+
COPY core core
9+
10+
RUN pip install -r requirements.txt
11+
12+
RUN python manage.py makemigrations
13+
RUN python manage.py migrate
14+
15+
EXPOSE 5005
16+
CMD ["gunicorn", "--config", "gunicorn-cfg.py", "core.wsgi"]

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: gunicorn core.wsgi --log-file -
1+
web: gunicorn core.wsgi --log-file=-

Procfile.windows

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
**Open-Source Admin Dashboard** coded in **[Django Framework](https://www.djangoproject.com/)** - Provided by **AppSeed** [Web App Generator](https://appseed.us/app-generator).
44

5-
### Dashboard Features:
5+
### Dashboard Features
66

77
- SQLite, Django native ORM
88
- Modular design
99
- Session-Based authentication (login, register)
1010
- Forms validation
11-
- UI Kit: **Black Dashboard** provided by **Creative-Tim**
11+
- UI Kit: **Black Dashboard** (Free Version) by **Creative-Tim**
12+
13+
### Deployment Scripts
14+
15+
- **Heroku** - Cloud Application Platform
16+
- **Docker** - execute the app using a sandboxed container
17+
- **Gunicorn** / Nginx - a common used configuration for Django Apps
18+
- **Waitress** - Gunicorn equivalent for Windows.
19+
20+
### Web App Links
21+
22+
- [Django Dashboard Black](https://appseed.us/admin-dashboards/django-dashboard-black) - product page
23+
- [Django Dashboard Black](https://django-dashboard-black.herokuapp.com/) - LIVE Demo
1224

1325
<br />
1426

@@ -61,16 +73,117 @@ $ # Access the web app in browser: http://127.0.0.1:8000/
6173

6274
<br />
6375

76+
## Deployment
77+
78+
The app is provided with a basic configuration to be executed in [Heroku](https://heroku.com/), [Docker](https://www.docker.com/), [Gunicorn](https://gunicorn.org/), and [Waitress](https://docs.pylonsproject.org/projects/waitress/en/stable/).
79+
80+
### [Heroku](https://heroku.com/) platform
81+
82+
```bash
83+
$ # Get the code
84+
$ git clone https://github.com/app-generator/django-dashboard-black.git
85+
$ cd django-dashboard-black
86+
$
87+
$ # Heroku Login
88+
$ heroku login
89+
$
90+
$ # Create the app in Heroku platform
91+
$ heroku create # a random name will be generated by Heroku
92+
$
93+
$ # Disable collect static
94+
$ heroku config:set DISABLE_COLLECTSTATIC=1
95+
$
96+
$ # Push the source code and trigger the deploy
97+
$ git push heroku master
98+
$
99+
$ # Execute DBSchema Migration
100+
$ heroku run python manage.py makemigrations
101+
$ heroku run python manage.py migrate
102+
$
103+
$ # Visit the deployed app in browser.
104+
$ heroku open
105+
$
106+
$ # Create a superuser
107+
$ heroku run python manage.py createsuperuser
108+
```
109+
110+
<br />
111+
112+
### [Docker](https://www.docker.com/) execution
113+
---
114+
115+
The application can be easily executed in a docker container. The steps:
116+
117+
> Get the code
118+
119+
```bash
120+
$ git clone https://github.com/app-generator/django-dashboard-black.git
121+
$ cd django-dashboard-black
122+
```
123+
124+
> Start the app in Docker
125+
126+
```bash
127+
$ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up -d
128+
```
129+
130+
Visit `http://localhost:5005` in your browser. The app should be up & running.
131+
132+
<br />
133+
134+
### [Gunicorn](https://gunicorn.org/)
135+
---
136+
137+
Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX.
138+
139+
> Install using pip
140+
141+
```bash
142+
$ pip install gunicorn
143+
```
144+
> Start the app using gunicorn binary
145+
146+
```bash
147+
$ gunicorn --bind=0.0.0.0:8001 core.wsgi:application
148+
Serving on http://localhost:8001
149+
```
150+
151+
Visit `http://localhost:8001` in your browser. The app should be up & running.
152+
153+
154+
<br />
155+
156+
### [Waitress](https://docs.pylonsproject.org/projects/waitress/en/stable/)
157+
---
158+
159+
Waitress (Gunicorn equivalent for Windows) is meant to be a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones that live in the Python standard library.
160+
161+
> Install using pip
162+
163+
```bash
164+
$ pip install waitress
165+
```
166+
> Start the app using [waitress-serve](https://docs.pylonsproject.org/projects/waitress/en/stable/runner.html)
167+
168+
```bash
169+
$ waitress-serve --port=8001 core.wsgi:application
170+
Serving on http://localhost:8001
171+
```
172+
173+
Visit `http://localhost:8001` in your browser. The app should be up & running.
174+
175+
<br />
176+
64177
## Support
65178

66179
- Free support via eMail < [support @ appseed.us](https://appseed.us/support) > and **Github** issues tracker
67180
- 24/7 Live Support via [Discord](https://discord.gg/fZC6hup) for paid plans and commercial products.
68181

69182
<br />
70183

71-
## Credits & Links
184+
## Credits
72185

73-
- [Django Dashboard Black](https://www.youtube.com/watch?v=czv4Ww6rjMU) - yTube presentation
186+
- [Django Dashboard Black](https://www.youtube.com/watch?v=RJkCTn55ywo) - yTube presentation
74187
- [Django Framework](https://www.djangoproject.com/) - Offcial website
75188
- [Django Admin Dashboards](https://appseed.us/admin-dashboards/django) - Open-source and paid admin panels coded in **Django**
76189

authentication/views.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def login_view(request):
1818
form = LoginForm(request.POST or None)
1919

20-
msg = 'Sign in with credentials'
20+
msg = None
2121

2222
if request.method == "POST":
2323

@@ -37,7 +37,8 @@ def login_view(request):
3737

3838
def register_user(request):
3939

40-
msg = 'Add your credentials'
40+
msg = None
41+
success = False
4142

4243
if request.method == "POST":
4344
form = SignUpForm(request.POST)
@@ -46,10 +47,15 @@ def register_user(request):
4647
username = form.cleaned_data.get("username")
4748
raw_password = form.cleaned_data.get("password1")
4849
user = authenticate(username=username, password=raw_password)
49-
return redirect("/login/")
50+
51+
msg = 'User created.'
52+
success = True
53+
54+
#return redirect("/login/")
55+
5056
else:
5157
msg = 'Form is not valid'
5258
else:
5359
form = SignUpForm()
5460

55-
return render(request, "accounts/register.html", {"form": form, "msg" : msg})
61+
return render(request, "accounts/register.html", {"form": form, "msg" : msg, "success" : success })

core/settings-production.py

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)