-
Notifications
You must be signed in to change notification settings - Fork 277
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 #72 from lukasredev/master
Add Docker Based Deployment
- Loading branch information
Showing
7 changed files
with
140 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Dockerfile | ||
FROM python:3.12 | ||
|
||
RUN apt-get update && apt-get install nginx --yes | ||
|
||
COPY requirements.txt requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY deploy/prod-requirements.txt prod-requirements.txt | ||
RUN pip install --no-cache-dir -r prod-requirements.txt | ||
|
||
COPY deploy/nginx.conf /etc/nginx/sites-enabled/default | ||
|
||
# Mounts the application code to the image | ||
COPY . app | ||
WORKDIR /app | ||
|
||
EXPOSE 8080 | ||
|
||
# runs the production server | ||
CMD ["/app/deploy/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 |
---|---|---|
|
@@ -115,6 +115,32 @@ You can now visit your site at `http://localhost:8000/`. | |
The dashboard and admin interface are available at `http://localhost:8000/dashboard/` and `http://localhost:8000/admin/`. | ||
Use the superuser created in step three of the commands above. | ||
|
||
|
||
### Database | ||
The default setup of this project uses a SQLite database, which is persisted on the file system. If you want to use another | ||
database you can change the `DATABASES` config option in the `settings.py` file. This file already contains an example | ||
configuration on how to use the [Postgres](https://www.postgresql.org/) database specified in the docker-compose file. | ||
|
||
### Docker | ||
You can also run the project using [Docker](https://www.docker.com/). To build the image and run the container you can run: | ||
```bash | ||
docker build -t django-wedding-website . | ||
docker run -it -p 8080:8080 \ | ||
-e DJANGO_SUPERUSER_PASSWORD=changeme \ | ||
-e DJANGO_SUPERUSER_USERNAME=admin \ | ||
-e [email protected] \ | ||
django-wedding-website | ||
``` | ||
You can now visit your site at `http://localhost:8080` | ||
|
||
#### Docker Compose | ||
To run the project with a Postgres database, you can | ||
- Change the `DATABASES` configuration in `settings.py` to use the Postgres database | ||
- Start the Postgres Database and the project container with `docker-compose up --build` | ||
- You can now visit your site at `http://localhost:8080` | ||
|
||
> Note that if you want to make a production deployment with Docker you need to backup the SQLite or Postgres database! | ||
## Customization | ||
|
||
I recommend forking this project and just manually modifying it by hand to replace everything with what you want. | ||
|
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,15 @@ | ||
#!/bin/bash | ||
|
||
python manage.py collectstatic --noinput | ||
|
||
# i commit my migration files to git so i dont need to run it on server | ||
# ./manage.py makemigrations app_name | ||
python manage.py migrate | ||
|
||
# Create the superuser | ||
|
||
python manage.py createsuperuser --noinput | ||
|
||
/usr/sbin/nginx -g 'daemon off;' & | ||
|
||
gunicorn bigday.wsgi --bind 0.0.0.0:8000 |
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,31 @@ | ||
upstream app_server_djangoapp { | ||
server localhost:8000 fail_timeout=0; | ||
} | ||
|
||
server { | ||
listen 8080; | ||
server_name localhost; | ||
|
||
access_log /var/log/nginx/wedding-access.log; | ||
error_log /var/log/nginx/wedding-error.log info; | ||
|
||
keepalive_timeout 5; | ||
|
||
root /app; | ||
|
||
location /static { | ||
autoindex on; | ||
alias /app/static_root; | ||
} | ||
|
||
location / { | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $http_host; | ||
proxy_redirect off; | ||
|
||
if (!-f $request_filename) { | ||
proxy_pass http://app_server_djangoapp; | ||
break; | ||
} | ||
} | ||
} |
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,30 @@ | ||
version: "3" | ||
services: | ||
# WARNING: If you want to use this docker-compose file in production, you need to backup your database! | ||
postgres: | ||
container_name: postgres-wedding | ||
image: postgres | ||
environment: | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=password | ||
- POSTGRES_DB=wedding | ||
ports: | ||
- 5432:5432 | ||
wedding: | ||
container_name: wedding | ||
build: . | ||
environment: | ||
- DEBUG=False | ||
- SECRET_KEY=changeme | ||
- POSTGRES_SERVER=postgres-wedding | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_DB=wedding | ||
- POSTGRES_PASSWORD=password | ||
- POSTGRES_PORT=5432 | ||
- DJANGO_SUPERUSER_PASSWORD=changeme | ||
- DJANGO_SUPERUSER_USERNAME=admin | ||
- [email protected] | ||
ports: | ||
- 8080:8080 | ||
depends_on: | ||
- 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
django==4.2.* | ||
Fabric==1.10.2 | ||
psycopg2-binary==2.9.3 | ||
django-environ==0.11.2 |