From 3968e14dadebbb8992a8c6049d7933171ecf39d9 Mon Sep 17 00:00:00 2001 From: Kyle Rockman Date: Fri, 15 Sep 2017 12:14:51 -0500 Subject: [PATCH] cleanup startup of localdev to make it more turn-key - also update readme about auth in production --- Dockerfile | 26 ++++++++++++++------- README.md | 6 +++++ docker-compose.yml | 4 ++++ estate/terraform/fixtures/initial_data.json | 1 + scripts/local.sh | 13 ++++++++++- 5 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 estate/terraform/fixtures/initial_data.json diff --git a/Dockerfile b/Dockerfile index e6b79bb..755b33b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 \ @@ -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 diff --git a/README.md b/README.md index 195c14c..094e6fd 100644 --- a/README.md +++ b/README.md @@ -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 ------------- @@ -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. diff --git a/docker-compose.yml b/docker-compose.yml index 24c9634..a3349a8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/estate/terraform/fixtures/initial_data.json b/estate/terraform/fixtures/initial_data.json new file mode 100644 index 0000000..a045ef8 --- /dev/null +++ b/estate/terraform/fixtures/initial_data.json @@ -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": []}}] diff --git a/scripts/local.sh b/scripts/local.sh index 5e727d4..af306f8 100755 --- a/scripts/local.sh +++ b/scripts/local.sh @@ -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