Skip to content

Commit

Permalink
Entrypoint improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxsmin committed Jun 19, 2018
1 parent b2eb0a4 commit 112b435
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 71 deletions.
7 changes: 3 additions & 4 deletions sysPass-dev-php7/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM debian:stretch
MAINTAINER nuxsmin [email protected]
LABEL from=github version=master php=7.0
LABEL [email protected] from=github version=devel php=7.0

# Usage:
# docker run -d --name=sysPass-dev -p 80:80 -p 443:443 nuxsmin/docker-syspass:devel
Expand All @@ -23,12 +22,12 @@ ENV APACHE_RUN_USER="www-data" \
APACHE_LOG_DIR="/var/log/apache2" \
APACHE_LOCK_DIR="/var/lock/apache2" \
APACHE_PID_FILE="/var/run/apache2.pid" \
SYSPASS_BRANCH="master" \
SYSPASS_BRANCH="devel" \
SYSPASS_UID=9001

WORKDIR /var/www/html

LABEL build=2018020701
LABEL build=18061901

# Mininal HTTP-only Apache config
COPY 000-default.conf /etc/apache2/sites-available/
Expand Down
59 changes: 39 additions & 20 deletions sysPass-dev-php7/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
#!/bin/bash

COLOR_NC='\033[0m'
COLOR_YELLOW='\033[0;33m'
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'

XDEBUG_REMOTE_HOST=${XDEBUG_REMOTE_HOST:-"172.17.0.1"}
XDEBUG_IDE_KEY=${XDEBUG_IDE_KEY:-"ide"}

setup_app () {
[[ ! -d "./sysPass" ]] && mkdir sysPass

if [ ! -e "./sysPass/index.php" ]; then
echo -e "\nUnpacking sysPass ..."
echo -e "${COLOR_YELLOW}setup_app: Unpacking sysPass${COLOR_NC}"

unzip ${SYSPASS_BRANCH}.zip
mv sysPass-${SYSPASS_BRANCH}/* sysPass
rm -rf sysPass-${SYSPASS_BRANCH}

echo -e "${COLOR_YELLOW}setup_app: Setting up permissions${COLOR_NC}"

chown ${APACHE_RUN_USER}:${SYSPASS_UID} -R sysPass/
chmod g+w -R sysPass/
chmod 750 sysPass/config sysPass/backup
Expand All @@ -20,23 +29,26 @@ setup_app () {
setup_composer () {
pushd ./sysPass

if [ -e "composer.lock" ]; then
echo -e "\nComposer already set up."
if [ -e "composer.phar" -a -e "composer.lock" -a -d "vendor" ]; then
echo -e "${COLOR_YELLOW}setup_composer: Composer already set up${COLOR_NC}"
echo -e "${COLOR_YELLOW}setup_composer: Updating${COLOR_NC}"

run_composer update
return 0
fi

echo -e "\nSetting up composer ..."
echo -e "${COLOR_YELLOW}setup_composer: Setting up composer${COLOR_NC}"

if [ ! -e "./sysPass/composer.phar" ]; then
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
if [ ! -e "composer.phar" ]; then
gosu ${SYSPASS_UID} php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
gosu ${SYSPASS_UID} php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
gosu ${SYSPASS_UID} php composer-setup.php
gosu ${SYSPASS_UID} php -r "unlink('composer-setup.php');"
fi

php composer.phar self-update
gosu ${SYSPASS_UID} php composer.phar self-update

[[ $? -eq 0 && -e "composer.json" ]] && php composer.phar install
[[ $? -eq 0 && -e "composer.json" ]] && gosu ${SYSPASS_UID} php composer.phar install

popd
}
Expand All @@ -45,7 +57,7 @@ setup_locales() {
if [ ! -e ".setup" ]; then
LOCALE_GEN="/etc/locale.gen"

echo -e "\nSetting up locales ..."
echo -e "${COLOR_YELLOW}setup_locales: Setting up locales${COLOR_NC}"

echo -e "\n### sysPass locales" >> $LOCALE_GEN
echo "es_ES.UTF-8 UTF-8" >> $LOCALE_GEN
Expand All @@ -54,7 +66,7 @@ setup_locales() {
echo "ca_ES.UTF-8 UTF-8" >> $LOCALE_GEN
echo "fr_FR.UTF-8 UTF-8" >> $LOCALE_GEN
echo "ru_RU.UTF-8 UTF-8" >> $LOCALE_GEN
echo "po_PO.UTF-8 UTF-8" >> $LOCALE_GEN
echo "pl_PL.UTF-8 UTF-8" >> $LOCALE_GEN
echo "nl_NL.UTF-8 UTF-8" >> $LOCALE_GEN

echo 'LANG="en_US.UTF-8"' > /etc/default/locale
Expand All @@ -69,49 +81,56 @@ setup_locales() {
}

setup_apache () {
echo -e "Setting up xdebug variables ...\n"
echo -e "${COLOR_YELLOW}setup_apache: Setting up xdebug variables${COLOR_NC}"
sed -i 's/__XDEBUG_REMOTE_HOST__/'"$XDEBUG_REMOTE_HOST"'/' /etc/php/7.0/apache2/conf.d/20-xdebug.ini
sed -i 's/__XDEBUG_IDE_KEY__/'"$XDEBUG_IDE_KEY"'/' /etc/php/7.0/apache2/conf.d/20-xdebug.ini
}

run_composer () {
if [ -e "./composer.phar" -a -e "./composer.lock" ]; then
echo -e "Running composer ...\n"
echo -e "${COLOR_YELLOW}run_composer: Running composer${COLOR_NC}"

gosu ${SYSPASS_UID} php composer.phar "$@"
else
echo -e "ERROR: Composer not set up"
echo -e "${COLOR_RED}run_composer: Error, composer not set up${COLOR_NC}"
fi
}

echo "Starting with UID : ${SYSPASS_UID}"
echo -e "${COLOR_YELLOW}entrypoint: Starting with UID : ${SYSPASS_UID}${COLOR_NC}"
id ${SYSPASS_UID} > /dev/null 2>&1 || useradd --shell /bin/bash -u ${SYSPASS_UID} -o -c "" -m user
export HOME=/home/user

setup_app
setup_composer

case "$1" in
"apache")
setup_composer
setup_locales
setup_apache

echo -e "Starting Apache ..\n"
SELF_IP_ADDRESS=$(grep $HOSTNAME /etc/hosts | cut -f1)

echo -e "${COLOR_GREEN}######"
echo -e "sysPass environment installed and configured. Please point your browser to http://${SELF_IP_ADDRESS} to start the installation"
echo -e "######${COLOR_NC}"
echo -e "${COLOR_YELLOW}entrypoint: Starting Apache${COLOR_NC}"

# Apache gets grumpy about PID files pre-existing
rm -f ${APACHE_PID_FILE}

exec /usr/sbin/apache2ctl -DFOREGROUND
;;
"update")
setup_composer
run_composer update
;;
"composer")
setup_composer
shift
run_composer "$@"
;;
*)
echo -e "Starting $@ ...\n"
echo -e "${COLOR_YELLOW}entrypoint: Starting $@${COLOR_NC}"
exec gosu ${SYSPASS_UID} "$@"
;;
esac
39 changes: 23 additions & 16 deletions sysPass-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM debian:jessie
MAINTAINER nuxsmin [email protected]
LABEL from=github version=devel php=5.6
LABEL [email protected] from=github version=devel

# Usage:
# docker run -d --name=sysPass-dev -p 80:80 -p 443:443 nuxsmin/docker-syspass:devel
Expand All @@ -16,28 +15,36 @@ RUN apt-get update \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*

ENV APACHE_RUN_USER="www-data" \
APACHE_RUN_GROUP="www-data" \
APACHE_LOG_DIR="/var/log/apache2" \
APACHE_LOCK_DIR="/var/lock/apache2" \
APACHE_PID_FILE="/var/run/apache2.pid" \
SYSPASS_BRANCH="devel" \
SYSPASS_UID=9001

WORKDIR /var/www/html

LABEL version=2.1.7.17042101
# Mininal Apache config using provided .conf files
COPY 000-default.conf default-ssl.conf /etc/apache2/sites-available/

# Mininal HTTP-only Apache config
COPY 000-default.conf /etc/apache2/sites-available/
# Custom entrypoint to run Apache on foreground
COPY entrypoint.sh /usr/local/sbin/

# Xdebug module config
COPY 20-xdebug.ini /etc/php5/apache2/conf.d/20-xdebug.ini
# Enable SSL site and set entrypoint permissions
RUN a2enmod ssl \
&& a2ensite default-ssl \
&& chmod 755 /usr/local/sbin/entrypoint.sh

# Cutom entrypoint to run Apache on foreground
COPY entrypoint.sh /usr/local/sbin/
RUN chmod 755 /usr/local/sbin/entrypoint.sh
LABEL build=18061901

RUN pwd && wget https://github.com/nuxsmin/sysPass/archive/devel.zip \
&& unzip devel.zip \
&& mv sysPass-devel sysPass \
&& chmod 750 sysPass/config sysPass/backup \
&& chown www-data -R sysPass/
# Download and install the latest sysPass stable release from GitHub
RUN wget https://github.com/nuxsmin/sysPass/archive/${SYSPASS_BRANCH}.zip

EXPOSE 80 443

VOLUME ["/var/log/apache2", "/var/www/html/sysPass"]
VOLUME ["/var/www/html/sysPass/config", "/var/www/html/sysPass/backup"]

ENTRYPOINT ["/usr/local/sbin/entrypoint.sh"]

CMD ["apache"]
118 changes: 105 additions & 13 deletions sysPass-dev/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,136 @@
#!/bin/bash

COLOR_NC='\033[0m'
COLOR_YELLOW='\033[0;33m'
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'

XDEBUG_REMOTE_HOST=${XDEBUG_REMOTE_HOST:-"172.17.0.1"}
XDEBUG_IDE_KEY=${XDEBUG_IDE_KEY:-"ide"}

setup_app () {
[[ ! -d "./sysPass" ]] && mkdir sysPass

if [ ! -e "./sysPass/index.php" ]; then
echo -e "${COLOR_YELLOW}setup_app: Unpacking sysPass${COLOR_NC}"

unzip ${SYSPASS_BRANCH}.zip
mv sysPass-${SYSPASS_BRANCH}/* sysPass
rm -rf sysPass-${SYSPASS_BRANCH}

echo -e "${COLOR_YELLOW}setup_app: Setting up permissions${COLOR_NC}"

chown ${APACHE_RUN_USER}:${SYSPASS_UID} -R sysPass/
chmod g+w -R sysPass/
chmod 750 sysPass/config sysPass/backup
fi
}

setup_composer () {
pushd ./sysPass

if [ -e "composer.phar" -a -e "composer.lock" -a -d "vendor" ]; then
echo -e "${COLOR_YELLOW}setup_composer: Composer already set up${COLOR_NC}"
echo -e "${COLOR_YELLOW}setup_composer: Updating${COLOR_NC}"

run_composer update
return 0
fi

echo -e "${COLOR_YELLOW}setup_composer: Setting up composer${COLOR_NC}"

if [ ! -e "composer.phar" ]; then
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
fi

php composer.phar self-update

[[ $? -eq 0 && -e "composer.json" ]] && php composer.phar install

popd
}

setup_locales() {
if [ ! -e ".setup" ]; then
LOCALE_GEN="/etc/locale.gen"

echo -e "\nSetting up locales ..."
echo -e "${COLOR_YELLOW}setup_locales: Setting up locales${COLOR_NC}"

echo -e "\n### sysPass locales" >> $LOCALE_GEN
echo -e "\n### sysPass locales" >> $LOCALE_GEN
echo "es_ES.UTF-8 UTF-8" >> $LOCALE_GEN
echo "en_US.UTF-8 UTF-8" >> $LOCALE_GEN
echo "de_DE.UTF-8 UTF-8" >> $LOCALE_GEN
echo "ca_ES.UTF-8 UTF-8" >> $LOCALE_GEN
echo "fr_FR.UTF-8 UTF-8" >> $LOCALE_GEN
echo "ru_RU.UTF-8 UTF-8" >> $LOCALE_GEN
echo "po_PO.UTF-8 UTF-8" >> $LOCALE_GEN
echo "pl_PL.UTF-8 UTF-8" >> $LOCALE_GEN
echo "nl_NL.UTF-8 UTF-8" >> $LOCALE_GEN

echo 'LANG="en_US.UTF-8"' > /etc/default/locale

dpkg-reconfigure --frontend=noninteractive locales
update-locale LANG=en_US.UTF-8

LANG=en_US.UTF-8

echo "1" > .setup
fi
}

trap "echo 'Stopping Apache2 ...' && /usr/sbin/apachectl stop" HUP INT QUIT KILL TERM
setup_apache () {
echo -e "${COLOR_YELLOW}setup_apache: Setting up xdebug variables${COLOR_NC}"
sed -i 's/__XDEBUG_REMOTE_HOST__/'"$XDEBUG_REMOTE_HOST"'/' /etc/php5/apache2/conf.d/20-xdebug.ini
sed -i 's/__XDEBUG_IDE_KEY__/'"$XDEBUG_IDE_KEY"'/' /etc/php5/apache2/conf.d/20-xdebug.ini
}

run_composer () {
if [ -e "./composer.phar" -a -e "./composer.lock" ]; then
echo -e "${COLOR_YELLOW}run_composer: Running composer${COLOR_NC}"

composer.phar "$@"
else
echo -e "${COLOR_RED}run_composer: Error, composer not set up${COLOR_NC}"
fi
}

echo -e "${COLOR_YELLOW}entrypoint: Starting with UID : ${SYSPASS_UID}${COLOR_NC}"
id ${SYSPASS_UID} > /dev/null 2>&1 || useradd --shell /bin/bash -u ${SYSPASS_UID} -o -c "" -m user
export HOME=/home/user

setup_app

case "$1" in
"apache")
setup_composer
setup_locales
setup_apache

setup_locales
SELF_IP_ADDRESS=$(grep $HOSTNAME /etc/hosts | cut -f1)

echo -e "Setting xdebug variables ...\n"
sed -i 's/__XDEBUG_REMOTE_HOST__/'"$XDEBUG_REMOTE_HOST"'/' /etc/php5/apache2/conf.d/20-xdebug.ini
sed -i 's/__XDEBUG_IDE_KEY__/'"$XDEBUG_IDE_KEY"'/' /etc/php5/apache2/conf.d/20-xdebug.ini
echo -e "${COLOR_GREEN}######"
echo -e "sysPass environment installed and configured. Please point your browser to http://${SELF_IP_ADDRESS} to start the installation"
echo -e "######${COLOR_NC}"
echo -e "${COLOR_YELLOW}entrypoint: Starting Apache${COLOR_NC}"

echo -e "Starting Apache2 ...\n"
/usr/sbin/apache2ctl -D FOREGROUND &
# Apache gets grumpy about PID files pre-existing
rm -f ${APACHE_PID_FILE}

wait $!
exec /usr/sbin/apache2ctl -DFOREGROUND
;;
"update")
setup_composer
run_composer update
;;
"composer")
setup_composer
shift
run_composer "$@"
;;
*)
echo -e "${COLOR_YELLOW}entrypoint: Starting $@${COLOR_NC}"
exec "$@"
;;
esac
Loading

0 comments on commit 112b435

Please sign in to comment.