This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Docker support and update the readme file.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 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 |
---|---|---|
|
@@ -90,3 +90,7 @@ ENV/ | |
|
||
# SQLite3 | ||
db.sqlite3 | ||
|
||
|
||
# Merge backup files | ||
*.orig |
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,24 @@ | ||
# 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 | ||
|
||
# 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 | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
||
VOLUME /drf_src | ||
|
||
EXPOSE 8000 | ||
|
||
CMD python manage.py makemigrations && python manage.py migrate && python manage.py runserver 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 |
---|---|---|
|
@@ -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). | ||
|
@@ -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. | ||
|