Skip to content

Commit

Permalink
Simplify docker invoke tasks (#3673)
Browse files Browse the repository at this point in the history
* Add a config file for invoke. Echo commands before running them

* Simplify docker related task + remove the double .env file

* update docs

* Forgot to change one line of the docs

* Update tasks.py

typo

Co-Authored-By: Pomax <pomax@nihongoresources.com>
  • Loading branch information
patjouk and Pomax committed Sep 23, 2019
1 parent c4368d5 commit 0a595d9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 123 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -66,9 +66,9 @@ In addition to the code tests there are also visual regression tests, located in
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop) (macOS and Windows). For Linux users: install [Docker CE](https://docs.docker.com/install/#supported-platforms) and [Docker Compose](https://docs.docker.com/compose/install/). If you don't want to create a Docker account, direct links to download can be found [in this issue](https://github.com/docker/docker.github.io/issues/6910),
- [Check your install](https://docs.docker.com/get-started/#test-docker-version) by running `docker run hello-world`,
- If relevant: delete your node_modules directory (`rm -rf node_modules`). It's not necessary, but it speeds up the install.
- Run `invoke docker-setup` ([install invoke](http://www.pyinvoke.org/installing.html) if you don't have it yet). If you're running on Windows, you need to run `docker-compose --rm pipenv run python network-api/manage.py createsuperuser` when the setup is finished.
- Run `invoke docker-new-env` ([install invoke](http://www.pyinvoke.org/installing.html) if you don't have it yet). If you're running on Windows, you need to run `docker-compose --rm pipenv run python network-api/manage.py createsuperuser` when the setup is finished.

This task is copying your `.env` to the new `.docker.env` that is in charge of managing your environment variables while running Docker. The installation will take a few minutes: you need to download images from the Docker Hub, install JS and Python dependencies, create fake data, migrate your database, etc.
This task is creating a `.env` that is in charge of managing your environment variables while running Docker. The installation will take a few minutes: you need to download images from the Docker Hub, install JS and Python dependencies, create fake data, migrate your database, etc.

When it's done, run `docker-compose up`, wait until the static files to be built, and go to `0.0.0.0:8000`. You should have a local working version of the foundation site with fake data. When you want to stop, do `^C` to shut down your containers.

Expand Down
5 changes: 1 addition & 4 deletions docker-compose.yml
Expand Up @@ -28,10 +28,7 @@ services:
context: .
dockerfile: ./dockerfiles/Dockerfile.python
env_file:
- ".docker.env"
environment:
# Prevents pipenv from loading env files (python dotenv and docker-compose compatibility issue).
- PIPENV_DONT_LOAD_ENV=1
- ".env"
command: pipenv run python network-api/manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"
Expand Down
10 changes: 4 additions & 6 deletions docs/local_development_with_docker.md
Expand Up @@ -11,7 +11,7 @@ This documentation is composed of three main sections:
To interact with the project, you can use [docker](https://docs.docker.com/engine/reference/commandline/cli/) and [docker-compose](https://docs.docker.com/compose/reference/overview/) CLIs or use shortcuts with invoke.

The general workflow is:
- Install the project with `invoke docker-setup`,
- Install the project with `invoke docker-new-env`,
- Run the project with `docker-compose up`,
- Use invoke commands for frequent development tasks (database migrations, dependencies install, run tests, etc),
- After doing a `git pull`, keep your clone up to date by running `invoke docker-catchup`.
Expand All @@ -27,11 +27,10 @@ The general workflow is:
docker-makemigrations Creates new migration(s) for apps
docker-manage Shorthand to manage.py. inv docker.manage "[COMMAND] [ARG]"
docker-migrate Updates database schema
docker-npm Shorthand to npm. inv docker.npm "[COMMAND] [ARG]"
docker-new-db Delete your database and create a new one with fake data
docker-new-env Get a new dev environment and a new database with fake data
docker-npm Shorthand to npm. inv docker.npm "[COMMAND] [ARG]"
docker-pipenv Shorthand to pipenv. inv docker.pipenv "[COMMAND] [ARG]"
docker-setup Prepare your dev environment after a fresh git clone
docker_switching_branch Get a new database with fake data and rebuild images
docker-test-node Run node tests
docker-test-python Run python tests
```
Expand Down Expand Up @@ -173,6 +172,5 @@ We still use all those tools with Docker. The major difference is that `npm` and
### Can I use Docker in parallel with the old way of running the foundation site?

Short answer is yes but:
- you will have two different databases
- you will have two files to manage your environments variables (`.env` and `.env.docker`),
- you will have two different databases.
- those two environment won't share their dependencies: you will have to maintain and update both of them.
46 changes: 23 additions & 23 deletions env.default
Expand Up @@ -14,15 +14,15 @@ ALLOWED_HOSTS=*
ASSET_DOMAIN=network.mofoprod.net
CONTENT_TYPE_NO_SNIFF=True
CORS_WHITELIST=*
CORS_REGEX_WHITELIST=""
DATABASE_URL=""
CORS_REGEX_WHITELIST=
DATABASE_URL=
DEBUG=True
DISABLE_DEBUG_TOOLBAR=True
DJANGO_SECRET_KEY=secret
LOAD_FIXTURE=False
SET_HSTS=False
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=""
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=""
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=
SOCIAL_AUTH_LOGIN_REDIRECT_URL=http://localhost:5000/soc/complete/google-oauth2/
SSL_REDIRECT=False
USE_S3=False
Expand All @@ -32,46 +32,46 @@ XSS_PROTECTION=True

# SQS config

AWS_SQS_ACCESS_KEY_ID=""
AWS_SQS_SECRET_ACCESS_KEY=""
AWS_SQS_REGION=""
PETITION_SQS_QUEUE_URL=""
AWS_SQS_ACCESS_KEY_ID=
AWS_SQS_SECRET_ACCESS_KEY=
AWS_SQS_REGION=
PETITION_SQS_QUEUE_URL=

CRM_AWS_SQS_ACCESS_KEY_ID=""
CRM_AWS_SQS_SECRET_ACCESS_KEY=""
CRM_AWS_SQS_REGION=""
CRM_PETITION_SQS_QUEUE_URL=""
CRM_AWS_SQS_ACCESS_KEY_ID=
CRM_AWS_SQS_SECRET_ACCESS_KEY=
CRM_AWS_SQS_REGION=
CRM_PETITION_SQS_QUEUE_URL=


# CSP config

CSP_DEFAULT_SRC="'none'"
CSP_DEFAULT_SRC='none'
CSP_SCRIPT_SRC='self' 'unsafe-inline' cdn.optimizely.com https://www.google-analytics.com/analytics.js https://*.shpg.org/ http://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js https://airtable.com https://platform.twitter.com https://cdn.syndication.twimg.com
CSP_STYLE_SRC='self' 'unsafe-inline' code.cdn.mozilla.net fonts.googleapis.com https://platform.twitter.com
CSP_IMG_SRC=* data:
CSP_FONT_SRC='self' fonts.gstatic.com fonts.googleapis.com code.cdn.mozilla.net
CSP_CONNECT_SRC=*
CSP_MEDIA_SRC="'self'"
CSP_MEDIA_SRC='self'
CSP_CHILD_SRC='self' https://www.youtube.com https://s3.amazonaws.com
CSP_FORM_ACTION='self' https://www.mozilla.org/en-US/newsletter/
CSP_FRAME_SRC=https://airtable.com https://platform.twitter.com

# TEST ENVIRONMENT VALUES

PETITION_TEST_CAMPAIGN_ID=""
PETITION_TEST_CAMPAIGN_ID=

# REVIEW APPS SLACK BOT

GITHUB_TOKEN=""
SLACK_WEBHOOK_RA=""
GITHUB_TOKEN=
SLACK_WEBHOOK_RA=

# BUYER'S GUIDE Configuration
CORAL_TALK_SERVER_URL=""
PNI_STATS_DB_URL=""
CORAL_TALK_API_TOKEN=""
CORAL_TALK_SERVER_URL=
PNI_STATS_DB_URL=
CORAL_TALK_API_TOKEN=

# Cloudinary configuration
USE_CLOUDINARY=False
CLOUDINARY_CLOUD_NAME=""
CLOUDINARY_API_KEY=""
CLOUDINARY_API_SECRET=""
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
2 changes: 2 additions & 0 deletions invoke.yaml
@@ -0,0 +1,2 @@
run:
echo: true

0 comments on commit 0a595d9

Please sign in to comment.