diff --git a/.gitignore b/.gitignore index 2b00f1b..ef3de34 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,7 @@ ENV/ # SQLite3 db.sqlite3 + + +# Merge backup files +*.orig \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b07f84c --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index a90f2e3..457c37a 100644 --- a/README.md +++ b/README.md @@ -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 git@github.com: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. +