From 3fd73da5bdae3c80e41182da59e6c03ff3a4988f Mon Sep 17 00:00:00 2001 From: Sven Speckmaier Date: Thu, 2 Jun 2016 17:07:07 +0200 Subject: [PATCH] cleaned out ipunkt related example data from all files --- .gitignore | 1 + Dockerfile | 7 + README.md | 10 + composer.json | 13 ++ config.cfg | 28 +++ docker-compose.yml.tpl | 45 ++++ example-environment/scale.yml.tpl | 2 + example-environment/service.yml.tpl | 22 ++ filter_scale_larger_zero.php | 67 ++++++ nginx-conf/laravel.conf.tpl | 74 +++++++ rancherize | 319 ++++++++++++++++++++++++++++ upgrade_lib.sh | 95 +++++++++ usage.sh | 141 ++++++++++++ 13 files changed, 824 insertions(+) create mode 100644 .gitignore create mode 100755 Dockerfile create mode 100644 composer.json create mode 100644 config.cfg create mode 100644 docker-compose.yml.tpl create mode 100644 example-environment/scale.yml.tpl create mode 100644 example-environment/service.yml.tpl create mode 100644 filter_scale_larger_zero.php create mode 100644 nginx-conf/laravel.conf.tpl create mode 100755 rancherize create mode 100644 upgrade_lib.sh create mode 100644 usage.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57872d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..7cf1688 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM busybox +ADD . /var/www/laravel +VOLUME /var/www/laravel +ADD nginx-conf/laravel.conf.tpl /etc/nginx/conf.template.d/ +VOLUME /etc/nginx/conf.template.d +RUN sh -c 'if [ -f "/var/www/laravel/docker-prepare.sh" ] ; then sh /var/www/laravel/docker-prepare.sh ; fi' +CMD /bin/dc diff --git a/README.md b/README.md index a32472c..03683f1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # rancherize Rancherize your development workflow + +## Features +- Start a development webserver for your local development environment +- Build and publish a new docker image +- Deploy your last published version to a rancher stack +- Perform a rolling upgrade in rancher to your last published version + +## TODO +- Setup wizard for easy project setup +- Setup wizard for easy environment setup diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..09da2e0 --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "name": "ipunkt/rancherize", + "description": "Rancherize your development workflow", + "license": "MIT", + "authors": [ + { + "name": "Sven Speckmaier", + "email": "sps@ipunkt.biz" + } + ], + "bin": ["rancherize"], + "require": {} +} diff --git a/config.cfg b/config.cfg new file mode 100644 index 0000000..fcbe66a --- /dev/null +++ b/config.cfg @@ -0,0 +1,28 @@ +# The docker-compose project name +PROJECT_NAME=testproject + + + +# +# Dockerhub Configuration +# +# The docker image will be published to +# DOCKER_REPOSITORY_USER/DOCKER_REPOSITORY_NAME:PROJECT_PREFIX$VERSION +# + +# The docker username to which the image should be published +DOCKER_REPOSITORY_USER=johndoe + +# The docker +DOCKER_REPOSITORY_NAME=test + +# The docker tag prefix. Will be added in front of all docker tags when building +# or commiting +PROJECT_PREFIX=testproject_ + +# +# Rancher Configuration +# + +# The rancher service name to use. Will be suffixed by -VERSION +SERVICE_NAME=AppWebserver diff --git a/docker-compose.yml.tpl b/docker-compose.yml.tpl new file mode 100644 index 0000000..c73d88a --- /dev/null +++ b/docker-compose.yml.tpl @@ -0,0 +1,45 @@ +Webserver: + restart: always + ports: + - 8080:80 + tty: true + image: ipunktbs/laravel-nginx:1.9.7_php7_v5 + links: + - Database:database-master + volumes: + - #CODE_DIRECTORY#:/var/www/laravel + environment: + DATABASE_NAME: db + DATABASE_USER: user + DATABASE_PASSWORD: pw + DB_HOST: database-master + DB_DATABASE: db + DB_USERNAME: user + DB_PASSWORD: pw + SERVER_URL: http.test.local +Database: + restart: always + tty: true + image: ipunktbs/mysql-master:v1 + stdin_open: true + volumes_from: + - Data-DBMaster + labels: + io.rancher.sidekicks: Data-Database + ports: + - 3306:3306/tcp + environment: + MYSQL_ROOT_PASSWORD: cookies + REPLICATION_USER: replicationuser + REPLICATION_PASSWORD: nothing + DATABASE: db + USER: suer + PASSWORD: pw +Data-Database: + tty: true + command: + - cat + image: ubuntu:14.04 + stdin_open: true + volumes: + - /var/lib/mysql diff --git a/example-environment/scale.yml.tpl b/example-environment/scale.yml.tpl new file mode 100644 index 0000000..861be52 --- /dev/null +++ b/example-environment/scale.yml.tpl @@ -0,0 +1,2 @@ +AppWebserver-%VERSION%: + scale: 1 diff --git a/example-environment/service.yml.tpl b/example-environment/service.yml.tpl new file mode 100644 index 0000000..4ce2ed0 --- /dev/null +++ b/example-environment/service.yml.tpl @@ -0,0 +1,22 @@ +AppWebserver-%VERSION%: + restart: always + tty: true + image: ipunktbs/laravel-nginx:1.9.7_php7_v5 + external_links: + - mysql/DB-Master:database-master + labels: + io.rancher.sidekicks: App-%VERSION% + volumes_from: + - App-%VERSION% + environment: + DATABASE_NAME: db + DATABASE_USER: user + DATABASE_PASSWORD: password + DB_HOST: database-master + DB_DATABASE: db + DB_USERNAME: user + DB_PASSWORD: passowrd +App-%VERSION%: + image: user/package:%VERSION% + command: /bin/dc + stdin_open: true diff --git a/filter_scale_larger_zero.php b/filter_scale_larger_zero.php new file mode 100644 index 0000000..91bbbbe --- /dev/null +++ b/filter_scale_larger_zero.php @@ -0,0 +1,67 @@ +#!/usr/bin/php + + $containerData) { + if ( !array_key_exists('scale', $containerData)) + continue; + + $scale = intval($containerData['scale']); + if( $scale < $smallerThan ) + continue; + + $containers[$containerName] = $containerData; + } + + return $containers; +} + +function filterByRegex($input, $regex) { + $filteredContainers = []; + + foreach($input as $containerName => $containerData) { + $match = preg_match('~'.$regex.'~', $containerName); + if( $match === false ) + throw new InvalidArgumentException( "Beim matchen der Regex '$regex' ist ein Fehler aufgetreten." ); + + if( $match == 0 ) + continue; + + $filteredContainers[$containerName] = $containerData; + } + + return $filteredContainers; +} + +$file = 'rancher-compose.yml'; +$regex = $argv[1]; + +$data = parseYaml($file); +$containers = filterScale($data); + +if( ! empty($regex) ) { + + try { + $filteredContainers = filterByRegex($containers, $regex); + } catch(InvalidArgumentException $e) { + echo $e->getMessage(); + exit(1); + } + echo implode("\n", array_keys($filteredContainers) ); + exit(0); + +} + +echo implode("\n", array_keys($containers) ); diff --git a/nginx-conf/laravel.conf.tpl b/nginx-conf/laravel.conf.tpl new file mode 100644 index 0000000..8009935 --- /dev/null +++ b/nginx-conf/laravel.conf.tpl @@ -0,0 +1,74 @@ +server { + listen 80 default_server; + listen 81 default_server http2 proxy_protocol; + listen [::]:80 default_server ipv6only=on; + + root /var/www/laravel/public; + index index.php index.html index.htm; + + server_tokens off; + + error_log /var/log/nginx/error.log debug; + rewrite_log on; + + server_name ; + + ### HTTPS Rewrite + + # + # Der rewrite hier ist etwas komplizierter, damit die Unittests funktionieren + # Grundrewrite: Wenn am Loadbalancer nicht mit https angefagt wird dann leite auf https weiter + # Problem: Unittests haben keinen Loadbalancer zwischen sich und dem Server + # Lösung: Lokale Adressen werden vom rewrite ausgenommen + # Achtung: Zugriffe in der lokalen dev Umgebung zählen als von außen kommend, weil diese von der `öffentlichen` Container- + # Adresse reinkommen. + # + + # Grundstatus: Request kommt von außen + set $test "REMOTE"; + + # Bedingung: Wenn die ipv4 localhost Adresse mitgegeben wurde dann haben wir einen lokalen request + if ($remote_addr = "127.0.0.1") { + set $test "LOCAL"; + } + + # Bedingung: Wenn die ipv6 localhost Adresse mitgegeben wurde dann haben wir einen lokalen request + if ($remote_addr = "::1") { + set $test "LOCAL"; + } + + + # Bedingung: Wenn das Anfordernde Protokol am Loadbalancer nicht https ist + if ($http_x_forwarded_proto != "https") { + set $test "${test}PROTO"; + } + + # Bedingung: Wenn der Request am Loadbalancer nicht mit https ankam UND es sich nicht um einen lokalen request handelt + # leite um auf https. + # Die Abfrage auf den zusammengesetzten String ist ein pseudoe AND. Nginx unterstützt keine und/oder in if Bedingungen + if ($test = REMOTEPROTO) { + rewrite ^/(.*)$ https://$host/$1 permanent; + } + ### HTTPS Rewrite Ende + + if (!-d $request_filename) { + + rewrite ^/(.+)/$ /$1 permanent; + + } + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + + try_files $uri /index.php =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include /etc/nginx/fastcgi_params; + } +} + diff --git a/rancherize b/rancherize new file mode 100755 index 0000000..643816a --- /dev/null +++ b/rancherize @@ -0,0 +1,319 @@ +#!/bin/bash + +function require_root { + + if [ "x$DOCKER_HOST" == "x" ] && [ "$EUID" -ne 0 ] && [ $(groups | grep -v docker 2>&1 > /dev/null) ] + then echo "Please run as root" + exit 1 + fi +} + + +SELF="$0" +if [ -L "$0" ] ; then + SELF=$(readlink -f $0) +fi +pushd `dirname $SELF` > /dev/null +SCRIPTPATH=`pwd` +popd > /dev/null + +. $SCRIPTPATH/upgrade_lib.sh + +function read_link { + if [ "`uname`" == "Linux" ] ; then + DIRECTORY=$(readlink -f $1) + else + DIRECTORY=$(cd "$(dirname "$1")" && pwd -P) + fi + echo $DIRECTORY +} + +PARAMETERS=( ${*:2} ) +SVN_VERSION="r$(svn info | grep Revision | awk '{ print $2 }')" +svn status | egrep -v '\bdeploy' | egrep -v '\bdocker' | awk '{ print $1; }' | egrep 'M|A|D' 2>&1 > /dev/null && SVN_VERSION="$SVN_VERSION"c + +# +# Necessary Configuration: +# +# PROJECT_NAME=donepm - docker-compose project name +# PROJECT_PREFIX=donepm_ - Prefix for docker tags +# SERVICE_NAME=DonePM - rancher service name +# +# +source deploy/config.cfg +source $SCRIPTPATH/usage.sh + +function getWebId { + docker ps | grep Web_ | awk '{ print $1; }' +} + +function getWebTestId { + name=`grep Web deploy/docker-test.yml | sed 's/\://' | tr -dc '[[:print:]]'` + docker ps | grep $name | awk '{ print $1; }' +} + +function commit { + VERSION=ipunktbs/app:$PROJECT_PREFIX$1 + docker build -t $VERSION . && docker push $VERSION + echo $1 > deploy/latest_commit +} + +function deploy { + OLDPWD=$PWD + PROJECT_NAME=$1 + DEPLOY_DIRECTORY=$2 + NEW_VERSION=$3 + + cd $DEPLOY_DIRECTORY + + if ! update_compose $RANCHER_ACCESS_KEY $RANCHER_SECRET_KEY $RANCHER_URL $RANCHER_ENVIRONMENT ; then + echo "Failed to update docker-compose.yml and rancher-compose.yml from server" + exit 4 + fi + + CURRENT_SERVICE=$(find_version $SERVICE_NAME | xargs) + if [ -z "$CURRENT_SERVICE" ] ; then + echo "Failed to find active service for $SERVICE_NAME, unable to upgrade" + exit 3 + fi + NEW_SERVICE=$SERVICE_NAME-$NEW_VERSION + + add_version $SERVICE_NAME $NEW_VERSION + + if [ "$CURRENT_SERVICE" == "$NEW_SERVICE" ] ; then + echo "Attempting to upgrade to the already active revision" + echo "This causes malfunctions in rancher" + echo "Attempt canceled" + + cd $OLDPWD + exit 2 + fi + + echo Upgrading from $CURRENT_SERVICE to $NEW_SERVICE + + MAXIMUM_ATTEMPTS=5 + ATTEMPTS=0 + until rancher-compose -p $PROJECT_NAME upgrade -w $CURRENT_SERVICE $NEW_SERVICE ; do + let ATTEMPTS+=1 + + if [ "$ATTEMPTS" -gt "$MAXIMUM_ATTEMPTS" ] ; then + echo "Upgrade failed more than $MAXIMUM_ATTEMPTS times, aborting" + cd $OLDPWD + exit 1 + fi + + echo "Attempt to upgrade $CURRENT_SERVICE to $NEW_SERVICE failed, trying once more in 1s" + sleep 1s + done + + echo "Successfuly upgraded" + + cd $OLDPWD +} + +function initialize { + OLDPWD=$PWD + PROJECT_NAME=$1 + DEPLOY_DIRECTORY=$2 + NEW_VERSION=$3 + + cd $DEPLOY_DIRECTORY + + rm -f docker-compose.yml + rm -f rancher-compose.yml + + NEW_SERVICE=$SERVICE_NAME-$NEW_VERSION + + add_version $SERVICE_NAME $NEW_VERSION + + rancher-compose -p $PROJECT_NAME up + +} + +case $1 in + start) + require_root + DIRECTORY=$2 + MOUNTPATH_PATH="deploy/.mountpath" + if [ $# -lt 2 ] ; then + if [ ! -f "$MOUNTPATH_PATH" ] ; then + echo "No mountpath specified and none previously remembered" + + usage start + exit 1 + fi + DIRECTORY=$(cat $MOUNTPATH_PATH) + fi + + #DIRECTORY=$(cd "$(dirname "$DIRECTORY")" && pwd -P) + DIRECTORY=$(read_link $DIRECTORY) + ESCAPED_DIRECTORY=$(echo $DIRECTORY | sed -e 's/[\/&]/\\&/g') + cat deploy/docker-compose.yml.tpl | sed -e "s/#CODE_DIRECTORY#/$ESCAPED_DIRECTORY/g" > deploy/docker-compose.yml + docker-compose -f deploy/docker-compose.yml -p $PROJECT_NAME up -d + echo $DIRECTORY > $MOUNTPATH_PATH + ;; + stop) + require_root + docker-compose -f deploy/docker-compose.yml -p $PROJECT_NAME stop + ;; + test-start) + require_root + VERSION=$2 + ENVIRONMENT=$3 + if [ $# -lt 2 ] ; then + VERSION=$SVN_VERSION + echo "Defaulting to version '$VERSION'" + fi + if [ $# -lt 2 ] ; then + ENVIRONMENT=staging + echo "Defaulting to environment '$ENVIRONMENT'" + fi + cat deploy/docker-test.yml.tpl | sed -e "s/%VERSION%/$VERSION/g" | sed -e "s/%ENVIRONMENT%/$ENVIRONMENT/g" > deploy/docker-test.yml + docker-compose -f deploy/docker-test.yml -p $PROJECT_NAME up -d + ;; + test-stop) + require_root + docker-compose -f deploy/docker-test.yml -p $PROJECT_NAME stop + ;; + test-command) + require_root + if [ $# -lt 2 ] ; then + echo "Command missing."; + exit 1 + fi + COMMAND=$2 + + PARAMETERS=( ${*:3} ) + COMMANDLINE="$COMMAND ${PARAMETERS[@]}" + docker exec `getWebTestId` \ + bash -c "cd /var/www/laravel/ ; $COMMANDLINE" + ;; + artisan) + require_root + docker exec -i -t `getWebId` \ + /var/www/laravel/artisan ${PARAMETERS[@]} + ;; + logs) + require_root + docker logs ${PARAMETERS[@]} `getWebId` + ;; + commit) + require_root + VERSION=$2 + ENVIRONMENT=staging + + if [ $# -lt 2 ] ; then + VERSION=$SVN_VERSION + echo "Defaulting to tag '$VERSION'" + fi + commit $VERSION + ;; + deploy) + ENVIRONMENT=$2 + VERSION=$3 + + if [ $# -lt 2 ] ; then + ENVIRONMENT="staging" + fi + + ENVIRONMENT_CONFIG="deploy/$ENVIRONMENT/config.cfg" + if [ ! -f $ENVIRONMENT_CONFIG ] ; then + echo "Error: Configuration file '$ENVIRONMENT_CONFIG' is missing." + exit 1 + fi + + source $ENVIRONMENT_CONFIG + + for VARIABLE in RANCHER_URL RANCHER_ENVIRONMENT RANCHER_ACCESS_KEY RANCHER_SECRET_KEY PROJECT_NAME ; do + eval VALUE=\$$VARIABLE + + if [ -z "$VALUE" ] ; then + echo "Configuration Value for $VARIABLE is missing in $ENVIRONMENT_CONFIG" + MISSING_CONFIG="$MISSING_CONFIG $VARIABLE" + fi + + done + + if [ ! -z "$MISSING_CONFIG" ] ; then + exit 2 + fi + + # PROJECT_NAME muss in der config.cfg gesetzt werden + DEPLOY_DIRECTORY="deploy/$ENVIRONMENT" + + if [ $# -lt 3 ] ; then + VERSION=$(cat deploy/latest_commit) + fi + + deploy $PROJECT_NAME $DEPLOY_DIRECTORY $VERSION + ;; + initialize) + ENVIRONMENT=$2 + VERSION=$3 + + if [ $# -lt 2 ] ; then + ENVIRONMENT="staging" + fi + + ENVIRONMENT_CONFIG="deploy/$ENVIRONMENT/config.cfg" + if [ ! -f $ENVIRONMENT_CONFIG ] ; then + echo "Error: Configuration file '$ENVIRONMENT_CONFIG' is missing." + exit 1 + fi + + source $ENVIRONMENT_CONFIG + + for VARIABLE in RANCHER_URL RANCHER_ENVIRONMENT RANCHER_ACCESS_KEY RANCHER_SECRET_KEY PROJECT_NAME ; do + eval VALUE=\$$VARIABLE + + if [ -z "$VALUE" ] ; then + echo "Configuration Value for $VARIABLE is missing in $ENVIRONMENT_CONFIG" + MISSING_CONFIG="$MISSING_CONFIG $VARIABLE" + fi + + done + + if [ ! -z "$MISSING_CONFIG" ] ; then + exit 2 + fi + + # PROJECT_NAME muss in der config.cfg gesetzt werden + DEPLOY_DIRECTORY="deploy/$ENVIRONMENT" + + if [ $# -lt 3 ] ; then + VERSION=$(cat deploy/latest_commit) + fi + + initialize $PROJECT_NAME $DEPLOY_DIRECTORY $VERSION + ;; + test) + ENVIRONMENT=$2 + VERSION=$3 + + if [ $# -lt 2 ] ; then + ENVIRONMENT="staging" + fi + ;; + revision) + echo Current revision: $SVN_VERSION + exit 0 + ;; + help) + usage $PARAMETERS + exit 0 + ;; +# init) +# Concept: +# Copies files from the docker script directory to the destination directory and fills in project name and some other +# configuration variables +# Note: Ask for project name and fill them in the config file +# Generate secure password for environments +# fill DB_USER and DB_PASSWORD with PROJECTNAME_somestring +# TODO: Switch laravel-nginx database Variable names to DB_HOST, DB_USERNAME, DB_PASSWORD +# exit 0 +# ;; + *) + usage + exit 0 + ;; +esac diff --git a/upgrade_lib.sh b/upgrade_lib.sh new file mode 100644 index 0000000..31920c9 --- /dev/null +++ b/upgrade_lib.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +######################################################################################################################## +# upgrade_lib.sh +# +# Author: Sven Speckmaier +# Datum: 07.01.2016 +# +# Funktionen um herauszufinden welcher Service eines Rancher Stacks aktuell aktiv ist. +# +######################################################################################################################## + +pushd `dirname $0` > /dev/null +SCRIPTPATH=`pwd` +popd > /dev/null + +# +# Läd die docker-compose.yml und rancher-compose.yml für den in den Parametern angegebenen Rancher-Stack in das aktuelle +# Verzeichnis +# +# Parameter: +# 1. Benutzername: in Rancher ACCESS_KEY genannt. Variable RANCHER_ACCESS_KEY in docker-compose +# 2. Passwort: in Rancher SECRET_KEY genannt. Variable RANCHER_SECREKT_KEY in docker-compose +# 3. Url: Die Url zur Rancher API. Variable RACHER_RUL in docker-compose +# 4. ENVIRONMENT: Die Id des Rancher Stacks. Wird in docker-compose standartmäßig aus dem Verzeichnisnamen gelesen +# TODO: Die Id sollte hier aus dem Namen aufgelöst werden, dann kann Id oder Name übergeben werden +# +function update_compose { + USER=$1 + PASSWORD=$2 + URL=$3 + ENVIRONMENT=$4 + + MAXIMUM_ATTEMPTS=5 + ATTEMPTS=0 + until wget --user $USER --password $PASSWORD $URL/environments/$ENVIRONMENT/composeconfig -O compose.zip ; do + let ATTEMPTS+=1 + + if [ "$ATTEMPTS" -gt "$MAXIMUM_ATTEMPTS" ] ; then + echo "Update compose schlug mehr als $MAXIMUM_ATTEMPTS mal fehl: abbruch" + return 1 + fi + + echo "Update compose fehlgeschlagen, warte 1s" + sleep 1s + done + unzip -o compose.zip + return 0 +} + +# +# Such in der rancher-compose.yml Datei alle Services folgende Eigenschaften haben: +# - scale > 0 +# - Servicename matcht Regex $STACKNAME-r[0-9]* +# +# Parameter: +# 1. Stackname: für die Regex +# +function find_version { + + NAME=$1 + + php $SCRIPTPATH/filter_scale_larger_zero.php $NAME'-r[0-9]*' + echo + + return + +} + +# +# Fügt eine neue Version des Services zur docker-compose.yml Datei hinzu. +# Dazu wird eine Template-Datei benötigt in der der Platzhalter VERSION ersetzt wird. +# +# Parameter: +# 1. SERVICE_NAME: Mit SERVICE_NAME-VERSION wird geprüft ob die Version nicht schon hinterlegt ist. +# 2. VERSION: Der Platzhalter %VERSION% in der Template Datei wird hiermit ersetzt +# 3. Template: Die Template-Datei aus der die neue Version erzeugt wird. Wenn nicht angegeben: "service.yml.tpl" +# +function add_version { + + SERVICE_NAME=$1 + SVN_VERSION=$2 + TEMPLATE=service.yml.tpl + if [ "$#" -ge "3" ] ; then + TEMPLATE=$3 + fi + + if ! grep $SERVICE_NAME-$SVN_VERSION docker-compose.yml > /dev/null 2>&1 ; then + sed "s/%VERSION%/$SVN_VERSION/g" $TEMPLATE >> docker-compose.yml + fi + + return + +} + diff --git a/usage.sh b/usage.sh new file mode 100644 index 0000000..5708b53 --- /dev/null +++ b/usage.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +# +# Show Usage info +# Sourced by rancherize +# + +function usage { + if [ "$#" -ge "1" ] ; then + case $1 in + start) + echo "Start development environment" + echo + echo "Usage: $0 start [path/to/source]" + echo + echo "The start command attempts to start the project on your local machine through docker" + echo "The path given to the command will be mounted into the environment as the app to run" + echo "Most commonly the [path] will be '.'" + echo + echo "The path can be omitted after specifying it once. The last path used is remembered and" + echo "will be used" + return 0 + ;; + stop) + echo "Stop development environment" + echo + echo "Usage $0 stop" + echo + echo "The stop command attempts to stop the project on your local machine." + echo + echo "it is currently equal to doing a manual docker-compose stop" + return 0 + ;; + test-start) + echo "Start test environment" + echo + echo "Usage: $0 start [revision] [environment]" + echo + echo "The start-test environment attempts to start a test environment for the given revision and environment." + echo "It works not unlike the start command, except the started containers will be tagged by revision and" + echo "environment and they won't publish any ports." + echo "This ensures that multiple test environments can run on a deployment server at the same time without" + echo "one of them to error while trying to bind on a port." + echo + echo "Use the test-command to run a command inside the running test environment to run tests" + return 0 + ;; + test-command) + echo "Run command in test environment" + echo + echo "Usage: $0 test-command COMMAND" + echo + echo "Runs the given command in the app directory inside the test environment." + echo "The return value of the command will be returned by $0" + return 0 + ;; + test-stop) + echo "Stop test environment" + echo + echo "Usage: $0 test-stop" + echo + echo "Stop the currently running test environment" + return 0 + ;; + artisan) + echo "Run artisan command inside container" + echo + echo "Usage $0 artisan [parameters]" + echo + echo "The artisan command will attempt to run the artisan php script inside the development" + echo "container. Any arguments given here will be passed on to artisan" + return 0 + ;; + logs) + echo "Show stdout & stderr from the development container" + echo + echo "Usage $0 logs [parameters]" + echo + echo "The logs command will run 'docker logs' on the web server container of the development" + echo "environment." + echo "Any parameters given will be passed on to docker logs." + echo + echo "Noteworthy:" + echo " -f: Continue to watch the log as it is written, like tail -f" + return 0 + ;; + commit) + echo "Commit the current source as image to docker" + echo + echo "Usage $0 commit [tag]" + echo + echo "The commit command will build your current source directory as image for docker." + echo "If no tag is given then the current svn revision prefixed by r is used. (ex. r312)" + echo "If svn info shows added, modified or deleted files then the default tag will be suffixed by 'c'" + echo "(ex. r321c)" + return 0 + ;; + deploy) + echo "Deploy given tag to the rancher environment" + echo "" + echo "Usage $0 deploy [environment] [tag]" + echo + echo "The deploy command will attempt to do a rolling upgrade from the current version to the" + echo "image with the specified tag." + echo + echo "[environment]" + echo "If no environment is specified then 'staging' is used." + echo + echo "[tag]" + echo "The tag specifies which version should be online after the rolling upgrade" + echo "more specifically the image with tag $PROJECT_PREFIX""[tag] will be used" + echo "If no tag is specified then the last one built using the commit command is used" + return 0 + ;; + *) + echo "No help for command '$1' found" + echo + ;; + esac + fi + + echo "Usage: $0 [COMMAND] [OPTIONS]" + echo + echo "Commands:" + echo " start - Start docker environment" + echo " stop - Stops docker environment" + echo " artisan - Passes artisan commands through docker exec" + echo " logs - Displays the stdout & stderr of the container" + echo " commit - Build a new data image and commit it to docker. Default Tag $PROJECT_PREFIX"REVISION + echo " deploy - Deploys an image to rancher. Defaults to the last image built by commit" + echo " initialize - First deploy" + echo " revision - Shows the currently detected Version for this directory" + echo " test-start - Starts a new test environment, by default for the current svn revision and environment staging" + echo " test-command - Runs a command in the Web container of the currently running test environemnt" + echo " test-stop - Stops the currently running test environment" + echo " help - Show help for each command listed here" + echo + echo "For more specific help please use the help command" + echo " $0 help [command]" +} +