Skip to content

Commit

Permalink
cleanup startup of localdev to make it more turn-key - also update re…
Browse files Browse the repository at this point in the history
…adme about auth in production
  • Loading branch information
Kyle Rockman committed Sep 15, 2017
1 parent aecd982 commit 3968e14
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
26 changes: 18 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ ENV DJANGO_SETTINGS_MODULE=estate.settings \
PATH=/usr/local/service/node_modules/.bin/:$PATH

RUN yum update -y && \
yum install -y ca-certificates gcc libffi-devel libyaml-devel libmemcached-devel zlib-devel postgresql94-devel python27-devel python27-pip unzip docker git && \
mkdir -p /usr/local/service
yum install -y ca-certificates unzip

# Download Docker
ENV DOCKER_VERSION 17.04.0-ce
RUN curl -fsSLO https://get.docker.com/builds/Linux/x86_64/docker-$DOCKER_VERSION.tgz && \
tar -xzf docker-$DOCKER_VERSION.tgz && \
mv docker/docker /bin/ && \
rm -r docker docker-$DOCKER_VERSION.tgz

# Download Terraform
COPY ./TERRAFORM_URL.txt /usr/local/service/TERRAFORM_URL.txt
Expand All @@ -18,13 +24,15 @@ RUN curl -L --silent $(cat /usr/local/service/TERRAFORM_URL.txt) > /terraform.zi
rm /terraform.zip

# Download nodejs
ENV NODE_VERSION 6.10.2
RUN curl -sLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" && \
tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 && \
rm "node-v$NODE_VERSION-linux-x64.tar.xz"
ENV NODE_VERSION 6.11.3
RUN curl -sLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" && \
tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 && \
rm "node-v$NODE_VERSION-linux-x64.tar.gz"

# Install python dependencies
RUN pip install coreapi==2.3.0 \
RUN yum install -y gcc libffi-devel libyaml-devel libmemcached-devel zlib-devel postgresql94-devel python27-devel python27-pip && \
mkdir -p /usr/local/service && \
pip install coreapi==2.3.0 \
boto3==1.4.4 \
dj-database-url==0.4.1 \
Django==1.10.7 \
Expand Down Expand Up @@ -52,7 +60,9 @@ RUN pip install coreapi==2.3.0 \
semantic_version==2.6.0 \
structlog==17.1.0 \
whitenoise==3.3.0 && \
pip install --global-option="--with-libyaml" pyyaml==3.12
pip install --global-option="--with-libyaml" pyyaml==3.12 && \
yum remove --setopt=clean_requirements_on_remove=1 -y gcc libffi-devel libyaml-devel zlib-devel python27-devel


# Install nodejs dependencies
COPY ./package.json /usr/local/service/package.json
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ The requirements to run Estate in production are:
* [SECRET_KEY](https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-SECRET_KEY): Django secret key variable
* The docker socket is needed because Estate runs terraform in context of another docker container that it spins up on demand - the docker socket requires the container to run in privileged mode.

Since this is a django application - database schema changes are controlled through django's migration system

Once the application is up and running and connected to the database you'll need to have it run the migrations before you can use the application the best way to do this is to `docker exec` into a running container and run the command `django-admin migrate` This will run all the migrations and get the database configured properly for the application to run properly. It will also create a default superuser of Username: `root` Password: `admin` NOTE: for real production usecases you should create other users and disable/delete this auto generated superuser, see the Django documentation on the [Auth](https://docs.djangoproject.com/en/1.11/ref/contrib/auth/) modules for more information.

Configuration
-------------

Expand Down Expand Up @@ -125,6 +129,8 @@ Sentry is a first class citizen with Estate and the integration requires configu
* Clone this repo with [Git](https://git-scm.com/): `git clone https://github.com/underarmour/estate.git`
* Build the container images from root of the repo: `docker-compose build dev`
* Run the containers: `docker-compose up dev`
* Open a web browser to `http://localhost:8000/`
* Login with the credentials Username: `root` Password: `admin`

Every change to `Dockerfile` will require `docker-compose build dev` to be run. Changes to the codebase will be detected and Estate will be hot-reloaded.

Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ dev:
- /tmp:/tmp
environment:
- "DEBUG=True"
- "PGHOST=postgres"
- "PGUSER=postgres"
- "PGPASSWORD=estate"
- "PGDATABASE=estate"
- "DATABASE_URL=postgres://postgres:estate@postgres:5432/estate"
links:
- postgres:postgres
Expand Down
1 change: 1 addition & 0 deletions estate/terraform/fixtures/initial_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"model": "auth.user", "pk": 1, "fields": {"password": "pbkdf2_sha256$30000$QwLXaBkulNVt$VgCNam4n/QKxP+ZH2CYdVe1KiTKAjJtn/ofsMzmFh+I=", "last_login": null, "is_superuser": true, "username": "root", "first_name": "", "last_name": "", "email": "", "is_staff": true, "is_active": true, "date_joined": "2017-09-15T16:42:55.217Z", "groups": [], "user_permissions": []}}]
13 changes: 12 additions & 1 deletion scripts/local.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/bin/bash
#webpack --hot --watch &

RETRIES=5

# This will fail the first time onstartup but it takes long enough for the container to come up
# Every other time you restart the container the DB will exist and it'll work properly untill the postgress container goes away
until psql -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do
echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..."
sleep 1
done

echo "Starting Webpack Server"
webpack-dev-server --config webpack/webpack.local.config.js &
echo "Starting Django Server"
django-admin migrate
django-admin loaddata initial_data
exec django-admin runserver 0.0.0.0:8000

0 comments on commit 3968e14

Please sign in to comment.