diff --git a/build.sh b/build.sh index ec61bda..12fcb85 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,29 @@ #!/usr/bin/env bash -set -ex +set -e HUB_USERNAME=talentify -IMAGE_NAME="${HUB_USERNAME}/php-apache" -BUILD_DIR='./docker/images/php-apache' +IMAGE_NAME="${HUB_USERNAME}/flux" +IMAGES_DIR='./docker/images' + +scream() { + echo + echo + echo "$@" + echo + echo +} build_app() { - docker build --target base --tag ${IMAGE_NAME}:latest ${BUILD_DIR} - docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:base + docker build --tag ${IMAGE_NAME}:base "${IMAGES_DIR}/flux/base" +# docker tag ${IMAGE_NAME}:base-latest ${IMAGE_NAME}:base - docker build --target development --tag ${IMAGE_NAME}:dev ${BUILD_DIR} + docker build --tag ${IMAGE_NAME}:dev "${IMAGES_DIR}/flux/dev" docker build --tag ${HUB_USERNAME}/utils:latest ./docker/images/utils } push_app() { - docker push ${IMAGE_NAME}:latest + docker push ${IMAGE_NAME}:base docker push ${IMAGE_NAME}:dev @@ -23,18 +31,19 @@ push_app() { } build_ci() { - docker build --target ci --tag ${IMAGE_NAME}:ci ${BUILD_DIR} - docker tag ${IMAGE_NAME}:ci ${IMAGE_NAME}:circle + docker build --tag ${HUB_USERNAME}/ci:latest "${IMAGES_DIR}/ci" docker build --tag ${HUB_USERNAME}/ssh-selenium-standalone-chrome:latest ./docker/images/ssh-selenium-standalone-chrome } push_ci() { - docker push ${IMAGE_NAME}:ci - docker push ${IMAGE_NAME}:circle + docker push ${HUB_USERNAME}/ci:latest docker push ${HUB_USERNAME}/ssh-selenium-standalone-chrome:latest } +scream "Building Flux's images" build_app + +scream "Building CI's images" build_ci diff --git a/docker/images/ci/Dockerfile b/docker/images/ci/Dockerfile new file mode 100644 index 0000000..5bf6cfc --- /dev/null +++ b/docker/images/ci/Dockerfile @@ -0,0 +1,26 @@ +FROM talentify/flux:base +LABEL version="1.1.0" +LABEL description="Image for Flux's continuous integration." + +RUN apt-get update \ + && apt-get install --assume-yes gnupg \ + && curl -sL https://deb.nodesource.com/setup_9.x | bash - + +# git is needed for AWS cli in order to do the deployment process +RUN apt-get install ruby-dev rubygems \ + git \ + nodejs \ + python-dev python-pip\ + ssh sshpass \ + zip --assume-yes \ + && gem update --system \ + && gem install sass --no-user-install \ + && npm install -g grunt-cli \ + && pip install awsebcli --upgrade \ + && curl -sOL https://github.com/jwilder/dockerize/releases/download/v0.6.1/dockerize-linux-amd64-v0.6.1.tar.gz \ + && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.6.1.tar.gz \ + && rm dockerize-linux-amd64-v0.6.1.tar.gz + +# Add composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +RUN composer global require hirak/prestissimo diff --git a/docker/images/flux/base/Dockerfile b/docker/images/flux/base/Dockerfile new file mode 100644 index 0000000..8d877b1 --- /dev/null +++ b/docker/images/flux/base/Dockerfile @@ -0,0 +1,55 @@ +FROM talentify/phalcon-framework:3.3-php-7.1-apache-stretch +LABEL version="1.1.0" +LABEL description="Base image for Flux application." + +# Install dependencies +# RabbitMQ/amqp extension needs librabbitmq-dev and libssh-dev apt packages. +# Source: https://github.com/php-amqplib/php-amqplib/issues/521#issuecomment-357807290 +RUN apt-get update && apt-get install -y \ + libcurl3 \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libpng-dev \ + libyaml-dev \ + mysql-client \ + ssl-cert \ + libxml2-dev \ + librabbitmq-dev \ + libssh-dev \ + && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ + && docker-php-ext-install -j$(nproc) gd \ + && docker-php-ext-install mysqli \ + pdo_mysql \ + soap \ + && pecl install redis \ + yaml \ + mailparse \ + amqp \ + && docker-php-ext-enable redis \ + yaml \ + mailparse \ + amqp + +# Configure Apache +RUN a2enmod rewrite ssl +COPY --chown=www-data sites-enable/* /etc/apache2/sites-enabled/ +EXPOSE 443 + +# Add the ability to run commands as other user +ENV FLUX_USER=flux FLUX_GROUP=flux FLUX_USER_ID=1000 FLUX_USER_GID=1000 +ENV APACHE_RUN_USER=flux APACHE_RUN_GROUP=flux +RUN groupadd -r $FLUX_GROUP --gid=$FLUX_USER_GID &&\ + useradd -r -g $FLUX_GROUP -G www-data --uid=$FLUX_USER_ID --create-home --shell=/bin/bash $FLUX_USER +# Install gosu. Source: https://github.com/tianon/gosu/blob/master/INSTALL.md +RUN set -eux; \ + apt-get update; \ + apt-get install -y gosu; \ + rm -rf /var/lib/apt/lists/*; \ + # verify that the binary works + gosu nobody true +COPY bin/* /usr/local/bin/ +ENTRYPOINT ["flux-entrypoint"] +# Somehow CMD is undefined when I set ENTRYPOINT, so I set CMD again (as base image does). +CMD ["apache2-foreground"] + +WORKDIR /var/www/ diff --git a/docker/images/php-apache/flux-entrypoint b/docker/images/flux/base/bin/flux-entrypoint similarity index 100% rename from docker/images/php-apache/flux-entrypoint rename to docker/images/flux/base/bin/flux-entrypoint diff --git a/docker/images/flux/base/bin/flux-run b/docker/images/flux/base/bin/flux-run new file mode 100755 index 0000000..6f2ae1e --- /dev/null +++ b/docker/images/flux/base/bin/flux-run @@ -0,0 +1,15 @@ +#!/bin/bash +# +# Add the ability to run commands as "flux" user. +# +set -e + +# Add user and group if not already exists. +# "flux" user is already created on the base image, the following code will be +# useful if we need to remap the UID 1000 in the future. +#getent group "$FLUX_GROUP" 2>&1 > /dev/null || groupadd -r $FLUX_GROUP --gid=$FLUX_USER_GID +#getent passwd "$FLUX_USER" 2>&1 > /dev/null || useradd -r -g $FLUX_GROUP -G www-data --uid=$FLUX_USER_ID --create-home --shell=/bin/bash $FLUX_USER + +exec gosu $FLUX_USER "$@" + +exit 0 diff --git a/docker/images/php-apache/sites-enable/000-default.conf b/docker/images/flux/base/sites-enable/000-default.conf similarity index 100% rename from docker/images/php-apache/sites-enable/000-default.conf rename to docker/images/flux/base/sites-enable/000-default.conf diff --git a/docker/images/php-apache/sites-enable/ssl.conf b/docker/images/flux/base/sites-enable/ssl.conf similarity index 100% rename from docker/images/php-apache/sites-enable/ssl.conf rename to docker/images/flux/base/sites-enable/ssl.conf diff --git a/docker/images/flux/dev/Dockerfile b/docker/images/flux/dev/Dockerfile new file mode 100644 index 0000000..b7a7dc5 --- /dev/null +++ b/docker/images/flux/dev/Dockerfile @@ -0,0 +1,18 @@ +FROM talentify/flux:base +LABEL version="1.1.0" +LABEL description="Image for development on Flux application." + +# Configure PHP +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" &&\ + pecl config-set php_ini "$PHP_INI_DIR/php.ini" +# Install xdebug and append our configuration within .ini file +# that usually contains only the instruction to load the extension. +COPY xdebug.ini /tmp +RUN pecl install xdebug-2.6.0 \ + && docker-php-ext-enable xdebug \ + && cat /tmp/xdebug.ini | grep -v '^#' >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \ + && rm /tmp/xdebug.ini + +# Add composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +RUN flux-run composer global require hirak/prestissimo diff --git a/docker/images/php-apache/xdebug.ini b/docker/images/flux/dev/xdebug.ini similarity index 100% rename from docker/images/php-apache/xdebug.ini rename to docker/images/flux/dev/xdebug.ini diff --git a/docker/images/php-apache/Dockerfile b/docker/images/php-apache/Dockerfile deleted file mode 100644 index 9cb6d18..0000000 --- a/docker/images/php-apache/Dockerfile +++ /dev/null @@ -1,100 +0,0 @@ -# -# Base image -# -FROM talentify/phalcon-framework:3.3-php-7.1-apache-stretch AS base -LABEL version="1.1.0" -LABEL description="Image for Flux application." - -# Install dependencies -# RabbitMQ/amqp extension needs librabbitmq-dev and libssh-dev apt packages. -# Source: https://github.com/php-amqplib/php-amqplib/issues/521#issuecomment-357807290 -RUN apt-get update && apt-get install -y \ - libcurl3 \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libyaml-dev \ - mysql-client \ - ssl-cert \ - libxml2-dev \ - librabbitmq-dev \ - libssh-dev \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ - && docker-php-ext-install -j$(nproc) gd \ - && docker-php-ext-install mysqli \ - pdo_mysql \ - soap \ - && pecl install redis \ - yaml \ - mailparse \ - amqp \ - && docker-php-ext-enable redis \ - yaml \ - mailparse \ - amqp -# Configure Apache -RUN a2enmod rewrite ssl -COPY --chown=www-data sites-enable/* /etc/apache2/sites-enabled/ -EXPOSE 443 -# -# Add the ability to run commands as other user -ENV FLUX_USER=flux FLUX_GROUP=flux FLUX_USER_ID=1000 FLUX_USER_GID=1000 -ENV APACHE_RUN_USER=flux APACHE_RUN_GROUP=flux -# Install gosu. Source: https://github.com/tianon/gosu/blob/master/INSTALL.md -RUN set -eux; \ - apt-get update; \ - apt-get install -y gosu; \ - rm -rf /var/lib/apt/lists/*; \ - # verify that the binary works - gosu nobody true -COPY flux-entrypoint /usr/local/bin -COPY flux-run /usr/local/bin -ENTRYPOINT ["flux-entrypoint"] -# Somehow CMD is undefined when I set ENTRYPOINT, so I set CMD again (as base image does). -CMD ["apache2-foreground"] -WORKDIR /var/www/ - - -# -# Image for development -# -FROM base AS development -# Configure PHP -RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" &&\ - pecl config-set php_ini "$PHP_INI_DIR/php.ini" -# Install xdebug and append our configuration within .ini file -# that usually contains only the instruction to load the extension. -COPY xdebug.ini /tmp -RUN pecl install xdebug-2.6.0 \ - && docker-php-ext-enable xdebug \ - && cat /tmp/xdebug.ini | grep -v '^#' >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \ - && rm /tmp/xdebug.ini -# Add composer -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -RUN flux-run composer global require hirak/prestissimo - - -# -# Image for Continuous Integration (CI) -# -FROM base AS ci -RUN apt-get update \ - && apt-get install --assume-yes gnupg \ - && curl -sL https://deb.nodesource.com/setup_9.x | bash - -# git is needed for AWS cli in order to do the deployment process -RUN apt-get install ruby-dev rubygems \ - git \ - nodejs \ - python-dev python-pip\ - ssh sshpass \ - zip --assume-yes \ - && gem update --system \ - && gem install sass --no-user-install \ - && npm install -g grunt-cli \ - && pip install awsebcli --upgrade \ - && curl -sOL https://github.com/jwilder/dockerize/releases/download/v0.6.1/dockerize-linux-amd64-v0.6.1.tar.gz \ - && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.6.1.tar.gz \ - && rm dockerize-linux-amd64-v0.6.1.tar.gz -# Add composer -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -RUN composer global require hirak/prestissimo diff --git a/docker/images/php-apache/flux-run b/docker/images/php-apache/flux-run deleted file mode 100755 index a7efc34..0000000 --- a/docker/images/php-apache/flux-run +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# -# Add the ability to run commands as "flux" user. -# -set -e - -# Add user and group if not already exists. -getent group "$FLUX_GROUP" 2>&1 > /dev/null || groupadd -r $FLUX_GROUP --gid=$FLUX_USER_GID -getent passwd "$FLUX_USER" 2>&1 > /dev/null || useradd -r -g $FLUX_GROUP -G www-data --uid=$FLUX_USER_ID --create-home --shell=/bin/bash $FLUX_USER - -exec gosu $FLUX_USER "$@" - -exit 0 diff --git a/release.sh b/release.sh index 3495051..5b65d89 100755 --- a/release.sh +++ b/release.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash -set -ex +set -e . build.sh +scream "Pushing Flux's images" push_app + +scream "Pushing CI's images" push_ci