Skip to content

Commit

Permalink
Do not use multi-stage build
Browse files Browse the repository at this point in the history
See #2
  • Loading branch information
gnumoksha committed Feb 7, 2019
1 parent 886bc90 commit b453154
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 125 deletions.
31 changes: 20 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
#!/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

docker push ${HUB_USERNAME}/utils:latest
}

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
26 changes: 26 additions & 0 deletions docker/images/ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions docker/images/flux/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
File renamed without changes.
15 changes: 15 additions & 0 deletions docker/images/flux/base/bin/flux-run
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions docker/images/flux/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
100 changes: 0 additions & 100 deletions docker/images/php-apache/Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions docker/images/php-apache/flux-run

This file was deleted.

5 changes: 4 additions & 1 deletion release.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b453154

Please sign in to comment.