Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Add Docker support and update the readme file. #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ ENV/

# SQLite3
db.sqlite3


# Merge backup files
*.orig
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The first instruction is what image we want to base our container on
# We Use an official Python runtime as a parent image
FROM python:3.5.7

# The enviroment variable ensures that the python output is set straight
# to the terminal with out buffering it first
ENV PYTHONUNBUFFERED 1

ENV DRF_DEBUG_MODE False
ENV DRF_ALLOWED_HOSTS *


# Get the Real World example app
COPY . /drf_src

# Set the working directory to /drf
# NOTE: all the directives that follow in the Dockerfile will be executed in
# that directory.
WORKDIR /drf_src
RUN mkdir databases
Run echo '/databases' >> .gitignore

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

VOLUME /drf_src

EXPOSE 8000

ADD start.sh /start.sh
RUN chmod 755 /start.sh

# Run when container starts
CMD /start.sh
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This repo is functionality complete — PR's and issues welcome!

## Installation

### Option 1: Install from source

1. Clone this repository: `git clone [email protected]:gothinkster/productionready-django-api.git`.
2. `cd` into `conduit-django`: `cd productionready-django-api`.
3. Install [pyenv](https://github.com/yyuu/pyenv#installation).
Expand All @@ -22,3 +24,62 @@ If all went well then your command line prompt should now start with `(productio
If your command line prompt does not start with `(productionready)` at this point, try running `pyenv activate productionready` or `cd ../productionready-django-api`.

If pyenv is still not working, visit us in the Thinkster Slack channel so we can help you out.

#### Setting up the Database

```bash
python manage.py makemigrations
python manage.py migrate
```

#### Running the DJango App
```
python manage.py runserver 0.0.0.0:8000
```

#### Adding an admin user
However, there aren’t any users for our Django DRF application.
In order to create admin user, we need to access our container to run the createuser command then enter the promoted credentials:
```bash
python manage.py createsuperuser
```


### Option 2: Use Docker

If you don't have yet a running docker installation, install first docker with

```bash
sudo apt-get install docker.io
```

Fetch the repository from docker
```bash
docker pull realworldio/django-drf
```

#### Running the DJango App
Create a folder to mount the source code of the app
```bash
mkdir ~/django_drf_project
```

Run the DJango DRF app via Docker container
```bash
docker run -d -p 8080:8000 -v ~/django_drf_project:/drf_src --name django_drf_app realworldio/django-drf
```

#### Adding an admin user
However, there aren’t any users for our Django DRF application.
In order to create admin user, we need to access our container to run the createuser command:
```bash
docker exec -it django_drf_app /bin/bash
```

To add an admin user, you need to run the following code in your container then enter the promoted credentials:
```bash
python manage.py createsuperuser
```

Afterwards, exit the Docker container running the `exit` command.

10 changes: 10 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash


sed -i "s/DEBUG = True/DEBUG = $DRF_DEBUG_MODE/g" conduit/settings.py
sed -i "s/os\.path\.join(BASE_DIR, 'db\.sqlite3')/os.path.join(BASE_DIR, 'databases', 'db.sqlite3')/g" conduit/settings.py
sed -i "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = '$DRF_ALLOWED_HOSTS'.split(',')/g" conduit/settings.py

python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:8000