From 4578c00dde82d7b3bb2aab3840a15961f6c7a69f Mon Sep 17 00:00:00 2001 From: Bastian Rang Date: Wed, 2 Aug 2017 17:48:44 +0200 Subject: [PATCH 1/3] refs #12 * work in progress on Dockerfile --- Dockerfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..89a34d5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM php:7.1-alpine +RUN apk add --no-cache git curl tar +COPY [".", "/opt/rancherize"] +RUN cd /opt/rancherize \ + && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ + && php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \ + && php composer-setup.php \ + && php -r "unlink('composer-setup.php');" \ + && ./composer.phar install && rm composer.phar +RUN cd /opt/rancherize \ + && curl -SL "https://github.com/rancher/rancher-compose/releases/download/v0.12.5/rancher-compose-linux-amd64-v0.12.5.tar.gz" | tar xz +ENTRYPOINT ["/bin/sh"] \ No newline at end of file From f760cc8cad51f3eeeda36caa3745868af02c2311 Mon Sep 17 00:00:00 2001 From: Bastian Rang Date: Thu, 3 Aug 2017 17:47:36 +0200 Subject: [PATCH 2/3] refs #12 * work in progress on Dockerfile * TODO local user passthru to nginx --- .dockerignore | 3 +++ Dockerfile | 57 ++++++++++++++++++++++++++++++++++++++++++++------- README.md | 24 +++++++++++++++------- composer.json | 5 ++++- 4 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ec05d98 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +Dockerfile +.gitignore +.git \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 89a34d5..2e0d5d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,55 @@ -FROM php:7.1-alpine -RUN apk add --no-cache git curl tar +ARG PHP_VERSION=7.2-rc +FROM php:${PHP_VERSION}-alpine + +ARG PHP_VERSION +ARG DOCKER_COMPOSE_VERSION=1.15.0 +ARG RANCHER_COMPOSE_VERSION=v0.12.5 +ARG RANCHERIZE_HOME=/home/rancherize +ARG DEFAULT_EDITOR=vi + +LABEL maintainer="b.rang@ipunkt.biz" \ + version.php=$PHP_VERSION \ + version.docker-compose=$DOCKER_COMPOSE_VERSION \ + version.rancher-compose=$RANCHER_COMPOSE_VERSION + +# prepare pseudo project directory for npm_modules install +RUN ["mkdir", "$RANCHERIZE_HOME"] +RUN ["chmod", "777", "$RANCHERIZE_HOME"] + +VOLUME $RANCHERIZE_HOME + +# there lies the home +ENV HOME=$RANCHERIZE_HOME + +# default editor +ENV EDITOR=DEFAULT_EDITOR + +# install packages +RUN apk update \ + && apk add --no-cache \ + git \ + docker \ + py-pip + COPY [".", "/opt/rancherize"] -RUN cd /opt/rancherize \ - && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ +WORKDIR /opt/rancherize + +# load rancher-compose +RUN curl -SL "https://github.com/rancher/rancher-compose/releases/download/$RANCHER_COMPOSE_VERSION/rancher-compose-linux-amd64-$RANCHER_COMPOSE_VERSION.tar.gz" \ + | tar xz \ + && mv rancher-compose-$RANCHER_COMPOSE_VERSION/rancher-compose . + +# install composer packages +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ && php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \ && php composer-setup.php \ && php -r "unlink('composer-setup.php');" \ && ./composer.phar install && rm composer.phar -RUN cd /opt/rancherize \ - && curl -SL "https://github.com/rancher/rancher-compose/releases/download/v0.12.5/rancher-compose-linux-amd64-v0.12.5.tar.gz" | tar xz -ENTRYPOINT ["/bin/sh"] \ No newline at end of file + +# install docker-compose +RUN pip install docker-compose==$DOCKER_COMPOSE_VERSION + +# change workdir to project +WORKDIR $RANCHERIZE_HOME/project +ENTRYPOINT ["/opt/rancherize/rancherize"] +#ENTRYPOINT ["/bin/sh"] \ No newline at end of file diff --git a/README.md b/README.md index 6eba12b..ece1163 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,17 @@ of of adding and connecting services. For a concrete example on how the configuration becomes easier through this see the example at the bottom of this page. -# Requirements +# Usage as docker container (preferred) +Rancherize comes bundled as Docker Container `ipunktbs/rancherize`. + +To use it, just make an Shell alias: +``` +alias rancherize='docker run -it -v $HOME/.rancherize:/home/rancherize/.rancherize -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/home/rancherize/project ipunktbs/rancherize' +``` +From now on just use Rancherize without any dependencies for your local environment. + +# Usage in project +## Requirements Rancherize creates configuration to be used with external docker tools. Thus it is necessary to have the following tools installed to use Rancherize: @@ -17,7 +27,7 @@ installed to use Rancherize: - `docker-compose` https://docs.docker.com/compose/install/ - `rancher-compose` https://docs.rancher.com/rancher/v1.2/en/cattle/rancher-compose/#installation -# Installation +## Installation Rancherize is installed using composer composer require 'ipunkt/rancherize:^2.5.0' @@ -205,7 +215,7 @@ in a single place. "DB_HOST":"database", "DB_USER":"example_user", "DB_PASSWORD":"example_password", - "DB_DATABASE":"example_db", + "DB_DATABASE":"example_db" } }, "environments":{ @@ -216,7 +226,7 @@ in a single place. }, "staging":{ "environment":{ - "APP_ENV":"staging", + "APP_ENV":"staging" } } } @@ -232,11 +242,11 @@ in a single place. "database":"DB/MySql" }, "environment":{ - "APP_ENV":"production" + "APP_ENV":"production", "DB_HOST":"database", "DB_USER":"example_user", "DB_PASSWORD":"example_password", - "DB_DATABASE":"example_db", + "DB_DATABASE":"example_db" } }, "staging":{ @@ -248,7 +258,7 @@ in a single place. "DB_HOST":"database", "DB_USER":"example_user", "DB_PASSWORD":"example_password", - "DB_DATABASE":"example_db", + "DB_DATABASE":"example_db" } } } diff --git a/composer.json b/composer.json index 153ac18..b25ee97 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,9 @@ "require-dev": { "phpunit/phpunit": "^5.6", "mockery/mockery": "^0.9.9", - "ipunkt/rancherize-backup-storagebox": "dev-master" + "ipunkt/rancherize-backup-storagebox": "^1.0.3", + "ipunkt/rancherize-ecr": "^1.0.0", + "ipunkt/rancherize-publish-traefik-rancher": "^1.0.2", + "ipunkt/rancherize-blueprint-php-cli": "dev-master" } } From 3a6a88c5abcec3c2858a7352ac179eb11ffd127d Mon Sep 17 00:00:00 2001 From: Bastian Rang Date: Fri, 4 Aug 2017 11:06:34 +0200 Subject: [PATCH 3/3] refs #12 * move rancher-compose to /usr/local/bin * local user passthru to nginx with ENV-vars * no custom project-dir anymore * sample rancherize.sh with `docker run` command --- Dockerfile | 10 +++------- README.md | 13 ++++++++++--- app/Blueprint/Webserver/WebserverBlueprint.php | 4 ++-- scripts/rancherize.sh | 3 +++ 4 files changed, 18 insertions(+), 12 deletions(-) create mode 100755 scripts/rancherize.sh diff --git a/Dockerfile b/Dockerfile index 2e0d5d5..232d692 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM php:${PHP_VERSION}-alpine ARG PHP_VERSION ARG DOCKER_COMPOSE_VERSION=1.15.0 -ARG RANCHER_COMPOSE_VERSION=v0.12.5 +ARG RANCHER_COMPOSE_VERSION=0.12.5 ARG RANCHERIZE_HOME=/home/rancherize ARG DEFAULT_EDITOR=vi @@ -16,8 +16,6 @@ LABEL maintainer="b.rang@ipunkt.biz" \ RUN ["mkdir", "$RANCHERIZE_HOME"] RUN ["chmod", "777", "$RANCHERIZE_HOME"] -VOLUME $RANCHERIZE_HOME - # there lies the home ENV HOME=$RANCHERIZE_HOME @@ -35,9 +33,9 @@ COPY [".", "/opt/rancherize"] WORKDIR /opt/rancherize # load rancher-compose -RUN curl -SL "https://github.com/rancher/rancher-compose/releases/download/$RANCHER_COMPOSE_VERSION/rancher-compose-linux-amd64-$RANCHER_COMPOSE_VERSION.tar.gz" \ +RUN curl -SL "https://github.com/rancher/rancher-compose/releases/download/v$RANCHER_COMPOSE_VERSION/rancher-compose-linux-amd64-v$RANCHER_COMPOSE_VERSION.tar.gz" \ | tar xz \ - && mv rancher-compose-$RANCHER_COMPOSE_VERSION/rancher-compose . + && mv rancher-compose-*/rancher-compose /usr/local/bin/ && cp /usr/local/bin/rancher-compose /usr/local/bin/rancher-compose-$RANCHER_COMPOSE_VERSION # install composer packages RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ @@ -49,7 +47,5 @@ RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ # install docker-compose RUN pip install docker-compose==$DOCKER_COMPOSE_VERSION -# change workdir to project -WORKDIR $RANCHERIZE_HOME/project ENTRYPOINT ["/opt/rancherize/rancherize"] #ENTRYPOINT ["/bin/sh"] \ No newline at end of file diff --git a/README.md b/README.md index ece1163..50607aa 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,19 @@ For a concrete example on how the configuration becomes easier through this see # Usage as docker container (preferred) Rancherize comes bundled as Docker Container `ipunktbs/rancherize`. +## Requirements +Rancherize creates configuration to be used with external docker tools. Thus it is necessary to have the following tools +installed to use Rancherize: -To use it, just make an Shell alias: +- `docker` https://docs.docker.com/engine/installation/ +## Install on linux +No need to separately install it. To use it, just make a shell alias: ``` -alias rancherize='docker run -it -v $HOME/.rancherize:/home/rancherize/.rancherize -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/home/rancherize/project ipunktbs/rancherize' +alias rancherize='docker run -it -v $HOME/.rancherize:/home/rancherize/.rancherize -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):$(pwd) -w $(pwd) -e "USER_ID=$(id -u)" -e "GROUP_ID=$(id -g)" ipunktbs/rancherize' ``` -From now on just use Rancherize without any dependencies for your local environment. +or use the provided script `script/rancherize.sh`. + +From now on use rancherize without other dependencies for your local environment than docker. # Usage in project ## Requirements diff --git a/app/Blueprint/Webserver/WebserverBlueprint.php b/app/Blueprint/Webserver/WebserverBlueprint.php index dffb877..9327592 100644 --- a/app/Blueprint/Webserver/WebserverBlueprint.php +++ b/app/Blueprint/Webserver/WebserverBlueprint.php @@ -326,8 +326,8 @@ protected function makeServerService(Configuration $config, Configuration $defau $serverService->setImage($config->get('docker.image', 'ipunktbs/nginx-debug:debug-1.3.0')); if( $config->get('sync-user-into-container', false) ) { - $serverService->setEnvironmentVariable('USER_ID', getmyuid()); - $serverService->setEnvironmentVariable('GROUP_ID', getmygid()); + $serverService->setEnvironmentVariable('USER_ID',empty($_ENV['USER_ID']) ? getmyuid() : $_ENV['USER_ID'] ); + $serverService->setEnvironmentVariable('GROUP_ID', empty($_ENV['GROUP_ID']) ? getmygid() : $_ENV['GROUP_ID'] ); } if ($config->has('expose-port')) diff --git a/scripts/rancherize.sh b/scripts/rancherize.sh new file mode 100755 index 0000000..87166e2 --- /dev/null +++ b/scripts/rancherize.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker run -it -v $HOME/.rancherize:/home/rancherize/.rancherize -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):$(pwd) -w $(pwd) -e "USER_ID=$(id -u)" -e "GROUP_ID=$(id -g)" ipunktbs/rancherize $* \ No newline at end of file