From d72f11eecac4445d8510dda1fbf0d3140f0fb9c4 Mon Sep 17 00:00:00 2001 From: Sven Speckmaier Date: Thu, 2 Jun 2016 18:17:19 +0200 Subject: [PATCH] Starting implementation of the setup method and revision images in the readme --- README.md | 2 + config.cfg => examples/config.cfg | 0 .../docker-compose.yml.tpl | 0 .../nginx-conf}/laravel.conf.tpl | 0 rancherize | 9 ++- setup.sh | 69 +++++++++++++++++++ Dockerfile => templates/Dockerfile | 0 templates/config.cfg | 27 ++++++++ test/Dockerfile | 7 ++ test/deploy/config.cfg | 27 ++++++++ 10 files changed, 138 insertions(+), 3 deletions(-) rename config.cfg => examples/config.cfg (100%) rename docker-compose.yml.tpl => examples/docker-compose.yml.tpl (100%) rename {nginx-conf => examples/nginx-conf}/laravel.conf.tpl (100%) create mode 100644 setup.sh rename Dockerfile => templates/Dockerfile (100%) create mode 100644 templates/config.cfg create mode 100755 test/Dockerfile create mode 100644 test/deploy/config.cfg diff --git a/README.md b/README.md index 03683f1..0e318b9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # rancherize + +[![Latest Stable Version](https://poser.pugx.org/ipunkt/rancherize/v/stable.svg)](https://packagist.org/packages/ipunkt/rancherize) [![Latest Unstable Version](https://poser.pugx.org/ipunkt/rancherize/v/unstable.svg)](https://packagist.org/packages/ipunkt/rancherize) [![License](https://poser.pugx.org/ipunkt/rancherize/license.svg)](https://packagist.org/packages/ipunkt/rancherize) [![Total Downloads](https://poser.pugx.org/ipunkt/rancherize/downloads.svg)](https://packagist.org/packages/ipunkt/rancherize) Rancherize your development workflow ## Features diff --git a/config.cfg b/examples/config.cfg similarity index 100% rename from config.cfg rename to examples/config.cfg diff --git a/docker-compose.yml.tpl b/examples/docker-compose.yml.tpl similarity index 100% rename from docker-compose.yml.tpl rename to examples/docker-compose.yml.tpl diff --git a/nginx-conf/laravel.conf.tpl b/examples/nginx-conf/laravel.conf.tpl similarity index 100% rename from nginx-conf/laravel.conf.tpl rename to examples/nginx-conf/laravel.conf.tpl diff --git a/rancherize b/rancherize index 94d9df1..d72ce6c 100755 --- a/rancherize +++ b/rancherize @@ -40,7 +40,9 @@ svn status | egrep -v '\bdeploy' | egrep -v '\bdocker' | awk '{ print $1; }' | e # # source deploy/config.cfg + source $SCRIPTPATH/usage.sh +source $SCRIPTPATH/setup.sh function getWebId { docker ps | grep Web_ | awk '{ print $1; }' @@ -301,7 +303,8 @@ case $1 in usage $PARAMETERS exit 0 ;; -# init) + setup) + setup # Concept: # Copies files from the docker script directory to the destination directory and fills in project name and some other # configuration variables @@ -309,8 +312,8 @@ case $1 in # 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 -# ;; + exit 0 + ;; *) usage exit 0 diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..010059d --- /dev/null +++ b/setup.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# +# Setup +# +# Initialize an app for use with rancherize +# + +# +# collect_data +# +# Ask the user for all necesasry information +# +function collect_data { + echo "PROJECT_NAME" + echo + echo "The project name is used by docker-compose to identify Containers." + echo "So if projectA and projectB both have a mysql container named" + echo "MySQL and share the same PROJECT_NAME then docker-compose will try" + echo "to reuse the already created container which leads to problems" + read -e -p "PROJECT_NAME: " PROJECT_NAME + + echo "" + echo "DOCKER_REPOSITORY_USER" + echo "" + echo "The user to which your docker image should be pushed to" + read -e -p "DOCKER_REPOSITORY_USER: " DOCKER_REPOSITORY_USER + + echo "" + echo "DOCKER_REPOSITORY_NAME" + echo "" + echo "The repository name to which your docker image should be pushed to" + read -e -p "DOCKER_REPOSITORY_NAME: " DOCKER_REPOSITORY_NAME + + echo "" + echo "RANCHER_SERVICE_NAME" + echo "" + echo "" + read -e -p "RANCHER_SERVICE_NAME: " RANCHER_SERVICE_NAME +} + +# +# do_copy +# +# Create the files based on the users answers +# +function do_copy { + + if [ ! -d deploy ] ; then + mkdir deploy + fi + + sed \ + -e "s/%DOCKER_REPOSITORY_USER%/$DOCKER_REPOSITORY_USER/g" \ + -e "s/%DOCKER_REPOSITORY_NAME%/$DOCKER_REPOSITORY_NAME/g" \ + -e "s/%PROJECT_NAME%/$PROJECT_NAME/g" \ + $SCRIPTPATH/templates/config.cfg > deploy/config.cfg + + cp $SCRIPTPATH/templates/Dockerfile . +} + +function setup { + + echo "=== Setup wizard ===" + + collect_data + + do_copy +} diff --git a/Dockerfile b/templates/Dockerfile similarity index 100% rename from Dockerfile rename to templates/Dockerfile diff --git a/templates/config.cfg b/templates/config.cfg new file mode 100644 index 0000000..63bbf17 --- /dev/null +++ b/templates/config.cfg @@ -0,0 +1,27 @@ +# The docker-compose project name +PROJECT_NAME=%PROJECT_NAME% + + +# +# 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=%DOCKER_REPOSITORY_USER% + +# The docker +DOCKER_REPOSITORY_NAME=%DOCKER_REPOSITORY_NAME% + +# The docker tag prefix. Will be added in front of all docker tags when building +# or commiting +PROJECT_PREFIX=%DOCKER_TAG_PREFIX% + +# +# Rancher Configuration +# + +# The rancher service name to use. Will be suffixed by -VERSION +SERVICE_NAME=%RANCHER_SERVICE_NAME% diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100755 index 0000000..7cf1688 --- /dev/null +++ b/test/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/test/deploy/config.cfg b/test/deploy/config.cfg new file mode 100644 index 0000000..5e5fb14 --- /dev/null +++ b/test/deploy/config.cfg @@ -0,0 +1,27 @@ +# 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=ipunkt + +# The docker +DOCKER_REPOSITORY_NAME=%DOCKER_REPOSITORY_NAME% + +# The docker tag prefix. Will be added in front of all docker tags when building +# or commiting +PROJECT_PREFIX=%DOCKER_TAG_PREFIX% + +# +# Rancher Configuration +# + +# The rancher service name to use. Will be suffixed by -VERSION +SERVICE_NAME=%RANCHER_SERVICE_NAME%