Skip to content

Commit

Permalink
Webteam tooling v3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nottrobin committed Mar 22, 2018
1 parent 5761827 commit 30dd051
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
1 change: 1 addition & 0 deletions .env
@@ -1,3 +1,4 @@
PORT=8004
DEVEL=true
FLASK_DEBUG=true
SECRET_KEY=local_development_fake_key
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
# [generated] Bracketed sections updated by Yeoman generator
# generator-canonical-webteam@3.0.0
# generator-canonical-webteam@3.0.1

# [os] OS & editor files
Desktop.ini
Expand Down
2 changes: 1 addition & 1 deletion .sass-lint.yml
@@ -1,5 +1,5 @@
# File generated by the Webteam's Yeoman generator:
# generator-canonical-webteam@3.0.0
# generator-canonical-webteam@3.0.1
#
# Default config: https://github.com/sasstools/sass-lint/blob/master/lib/config/sass-lint.yml
# Example config: https://github.com/sasstools/sass-lint/blob/master/docs/sass-lint.yml
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -8,7 +8,7 @@
"build-js": "yarn run copy-3rd-party-js && yarn run build-js-transpile",
"copy-3rd-party-js": "cp node_modules/d3/build/d3.min.js static/js/modules && cp node_modules/d3-geo/build/d3-geo.min.js static/js/modules && cp node_modules/topojson-client/dist/topojson-client.min.js static/js/modules && cp node_modules/billboard.js/dist/billboard.min.js static/js/modules && cp node_modules/moment/min/moment.min.js static/js/modules && cp node_modules/clipboard/dist/clipboard.min.js static/js/modules",
"build-js-transpile": "rollup -c",
"serve": "TALISKER_NETWORKS='172.0.0.0/8 192.0.0.0/8' FLASK_DEBUG=true talisker.gunicorn app:app --reload --timeout 9999 --access-logfile - --error-logfile - --bind 0.0.0.0:${PORT}",
"serve": "talisker.gunicorn app:app --reload --timeout 9999 --access-logfile - --error-logfile - --bind 0.0.0.0:${PORT}",
"watch": "watch -p 'static/sass/**/*.scss' -p 'static/js/**/*.js' -c 'yarn run build'",
"watch-scss": "watch -p 'static/sass/**/*.scss' -c 'yarn run build-css'",
"watch-js": "watch -p 'static/js/**/*.js' -c 'yarn run build-js'",
Expand Down
54 changes: 26 additions & 28 deletions run
@@ -1,7 +1,7 @@
#! /usr/bin/env bash

# CAUTION:
# This file was generated by generator-canonical-webteam@3.0.0
# This file was generated by generator-canonical-webteam@3.0.1
# and should usually not be edited directly.
#
# This file was generated by the "canonical-webteam" Yeoman generator
Expand All @@ -14,20 +14,20 @@

set -euo pipefail

USAGE="How to use ./run v3.0.0
USAGE="How to use ./run v3.0.1
===
$ ./run \\
[-m|--node-module PATH] # A path to a local node module to use instead of the installed dependencies \\
[--no-debug] # Turn off the DEBUG setting \\
[COMMAND] # Optionally provide a command to run
[-e|--env VAR_NAME=value] # Declare an environment variable to use while running commands \\
[-m|--node-module PATH] # A path to a local node module to use instead of the installed dependencies \\
[COMMAND] # Optionally provide a command to run
If no COMMAND is provided, \`serve\` will be run.
Commands
---
- serve [-p|--port PORT] [-w|--watch] [-d|--detach]: Run a development server (optionally running \`watch\` in the background)
- serve [-p|--port PORT] [-d|--detach]: Run a development server
- watch [-s|--watch-site]: Run \`yarn run watch\` (for jekyll sites, watch for changes with \`--watch-site\`)
- build: Run \`yarn run build\`
- test: Run \`yarn run test\`
Expand All @@ -42,7 +42,7 @@ Commands
##

# Define docker images versions
dev_image="canonicalwebteam/dev:v1.4.0"
dev_image="canonicalwebteam/dev:v1.5.2"
if [ -n "${DOCKER_REGISTRY:-}" ]; then
dev_image="${DOCKER_REGISTRY}/${dev_image}"
fi
Expand All @@ -54,7 +54,6 @@ fi

# Defaults environment settings
PORT=8000
RUN_DEBUG=true

# Import environment settings
if [ -f .env ]; then
Expand All @@ -64,6 +63,7 @@ fi
# Other variables
run_serve_docker_opts="${CANONICAL_WEBTEAM_RUN_SERVE_DOCKER_OPTS:-}"
module_volumes=""
env_vars=""

# Decide which md5 command to use
if $(command -v md5sum > /dev/null); then md5_command="md5sum";
Expand Down Expand Up @@ -140,7 +140,11 @@ while [[ -n "${1:-}" ]] && [[ "${1:0:1}" == "-" ]]; do
key="$1"

case $key in
--no-debug) RUN_DEBUG=false ;;
-e|--env)
if [ -z "${2:-}" ]; then invalid "Missing environment variables. Usage: --env XXXX=yyyy"; fi
env_vars="${env_vars} --env ${2}"
shift
;;
-m|--node-module)
if [ -z "${2:-}" ]; then invalid "Missing module name. Usage: --node-module <path-to-module>."; fi
# Ensure directories exist, ready to host module volumes
Expand All @@ -151,7 +155,7 @@ while [[ -n "${1:-}" ]] && [[ "${1:0:1}" == "-" ]]; do
shift
;;
-h|--help) echo "$USAGE"; exit ;;
-v|--version) echo "Generated from generator-canonical-webteam@3.0.0"; exit ;;
-v|--version) echo "Generated from generator-canonical-webteam@3.0.1"; exit ;;
*) invalid "Option '${key}' not recognised." ;;
esac
shift
Expand Down Expand Up @@ -192,7 +196,8 @@ docker_run () {
--volume ${usr_local_volume}:/usr/local/ `# Bind local folder to volume` \
--volume ${cache_volume}:/home/shared/.cache/ `# Bind cache to volume` \
--env COMMIT_ID=${commit_id} `# Pass through the commit ID` \
${env_file} `# Pass environment variables into the container, if file exists` \
${env_file} `# Pass any files of environment variables to the container` \
${env_vars} `# Pass explicit environment variables to the container` \
${http_proxy} `# Include HTTP proxy if needed` \
${tty} `# Attach a pseudo-terminal, if relevant` \
${docker_run_options} `# Extra options` \
Expand Down Expand Up @@ -238,16 +243,8 @@ python_run () {

fi

# Choose debug variable
debug="DEBUG=${RUN_DEBUG}"
if [ -f manage.py ]; then
debug="DJANGO_DEBUG=${RUN_DEBUG}"
elif [ -f app.py ]; then
debug="FLASK_DEBUG=${RUN_DEBUG}"
fi

# Run the command in the python docker image
run_as_user "--env ${debug} ${python_run_options}" $@
run_as_user "${python_run_options}" $@
}

create_etc_volume() {
Expand Down Expand Up @@ -356,7 +353,6 @@ case $run_command in
PORT=${2}
shift
;;
-w|--watch) run_watcher=true ;;
*) invalid "Option '${key}' not recognised." ;;
esac
shift
Expand Down Expand Up @@ -512,26 +508,28 @@ case $run_command in
;;
"exec")
expose_ports=""
env_vars=""
run_as_root=false
while [[ -n "${1:-}" ]] && [[ "${1:0:1}" == "-" ]]; do
key="$1"

case $key in
-r|--root)
run_as_root=true
;;
-p|--expose-port)
if [ -z "${2:-}" ]; then invalid "Missing port number. Usage: --expose-port XXXX"; fi
expose_ports="${expose_ports} --publish ${2}:${2}"
shift
;;
-e|--env)
if [ -z "${2:-}" ]; then invalid "Missing environment variables. Usage: --env XXXX=yyyy"; fi
env_vars="${env_vars} --env ${2}"
shift
;;
*) invalid "Option '${key}' not recognised." ;;
esac
shift
done
run_as_user "${expose_ports} ${env_vars}" $@
if ${run_as_root}; then
docker_run "${expose_ports}" $@
else
run_as_user "${expose_ports}" $@
fi
;;
*) invalid "Command '${run_command}' not recognised." ;;
esac

0 comments on commit 30dd051

Please sign in to comment.