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 new file mode 100644 index 0000000..232d692 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +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=0.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"] + +# 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"] +WORKDIR /opt/rancherize + +# load rancher-compose +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 /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');" \ + && 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 + +# install docker-compose +RUN pip install docker-compose==$DOCKER_COMPOSE_VERSION + +ENTRYPOINT ["/opt/rancherize/rancherize"] +#ENTRYPOINT ["/bin/sh"] \ No newline at end of file diff --git a/README.md b/README.md index 6eba12b..50607aa 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,24 @@ 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`. +## Requirements +Rancherize creates configuration to be used with external docker tools. Thus it is necessary to have the following tools +installed to use Rancherize: + +- `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):$(pwd) -w $(pwd) -e "USER_ID=$(id -u)" -e "GROUP_ID=$(id -g)" ipunktbs/rancherize' +``` +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 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 +34,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 +222,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 +233,7 @@ in a single place. }, "staging":{ "environment":{ - "APP_ENV":"staging", + "APP_ENV":"staging" } } } @@ -232,11 +249,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 +265,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/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/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" } } 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