Commit fe898544 authored by Victor Nikulshin's avatar Victor Nikulshin

Split container bootstrapping into multiple Bash scripts

parent 6dd432f0
......@@ -3,52 +3,10 @@
FROM savoirfairelinux/lampd
MAINTAINER Ernesto Rodriguez Ortiz <ernesto.rodriguezortiz@savoirfairelinuc.com>
# Create project root directory and copy the structure
RUN mkdir -p /opt/sfl/src/drupal
COPY . /opt/sfl
ENV initpath ./fabfile/docker
# Create user used by Drupalizer tasks
RUN useradd --home-dir /opt/init --create-home drupalizer --shell /bin/bash && passwd -d drupalizer
RUN echo 'drupalizer ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
RUN echo 'cd /opt/sfl/src/drupal' > /opt/init/.profile
COPY ${initpath} /opt/init
RUN /opt/init/bootstrap
# Setup SSH access
RUN echo 'AuthorizedKeysFile /etc/ssh/authorized_keys' >> /etc/ssh/sshd_config && service ssh restart
RUN echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDcJHyU5S4xRP4QyJuBOiS38mrEuwfgOoWoNFQM0gWhJCb2phByO4Xg68f4v0w3FWm2SQQKv3bG5aevTI2ST5n0o/GbcCpdT1udV9uQIxr1+cbXUrecaNPD3WyIxt1Rldtwm7+s0AlwHHk0zKvulyupzPfQGB4Ix0zUfIzt+U45ww==' \
> /etc/ssh/authorized_keys
# Create entrypoint script
RUN echo '#!/bin/bash\n\
\n\
if [[ ! -z "$USER_ID" ]]\n\
then\n\
which usermod 2>&1 >/dev/null && usermod -u $USER_ID drupalizer\n\
service apache2 reload\n\
fi\n\
\n\
if [[ ! -z "$GROUP_ID" ]]\n\
then\n\
which groupmod 2>&1 >/dev/null && groupmod -g $GROUP_ID drupalizer\n\
service apache2 reload\n\
fi\n\
\n\
exec /bin/sh -c "$*"'\
> /opt/init/init.sh && chmod a+x /opt/init/init.sh
# Create Apache configuration
RUN echo 'ServerName localhost\n\
<VirtualHost *:80>\n\
DocumentRoot /opt/sfl/src/drupal\n\
\n\
<Directory /opt/sfl/src/drupal/>\n\
AllowOverride All\n\
Options FollowSymLinks\n\
Require all granted\n\
</Directory>\n\
</VirtualHost>'\
> /etc/apache2/sites-available/000-default.conf
RUN echo 'export APACHE_RUN_USER=drupalizer\nexport APACHE_RUN_GROUP=drupalizer' >> /etc/apache2/envvars
RUN a2enmod rewrite vhost_alias && service apache2 restart
ENTRYPOINT ["/opt/init/init.sh"]
ENTRYPOINT ["/opt/init/init"]
CMD ["/sbin/my_init"]
#!/bin/bash
set -e
INIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/bootstrap.d"
if [[ -d $INIT_DIR && -r $INIT_DIR && -x $INIT_DIR ]]; then
for i in $(LC_ALL=C command ls "$INIT_DIR"); do
i=$INIT_DIR/$i
[[ -f $i && -r $i ]] && . "$i"
done
fi
##
# Create system users
#
# Main user for Drupalizer tasks
useradd --home-dir /opt/init drupalizer --shell /bin/bash
passwd -d drupalizer
chown drupalizer:drupalizer /opt/init
##
# Create required filesystem structure
#
# Shared filesystem mount point
mkdir -p /opt/sfl/
# Apache document root
mkdir -p /opt/sfl/src/drupal
# Ensure the correct owner
chown -R drupalizer:drupalizer /opt/sfl
##
# Configure SUDO rights
#
# Full access for `drupalizer` user without password
echo 'drupalizer ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
##
# Configure SSH access
#
# Use the same authorized_keys file for all users
echo 'AuthorizedKeysFile /etc/ssh/authorized_keys' >> /etc/ssh/sshd_config
# Add the default known key to allow access for all users
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDcJHyU5S4xRP4QyJuBOiS38mrEuwfgOoWoNFQM0gWhJCb2phByO4Xg68f4v0w3FWm2SQQKv3bG5aevTI2ST5n0o/GbcCpdT1udV9uQIxr1+cbXUrecaNPD3WyIxt1Rldtwm7+s0AlwHHk0zKvulyupzPfQGB4Ix0zUfIzt+U45ww==' > /etc/ssh/authorized_keys
service ssh restart
##
# Configure Apache webserver
#
# Configure default VirtualHost for Drupal
cat > /etc/apache2/sites-available/000-default.conf <<EOF
ServerName localhost
<VirtualHost *:80>
DocumentRoot /opt/sfl/src/drupal
<Directory /opt/sfl/src/drupal/>
AllowOverride All
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
EOF
# Make Apache run as the main `drupalizer` user
cat >> /etc/apache2/envvars << EOF
export APACHE_RUN_USER=drupalizer
export APACHE_RUN_GROUP=drupalizer
EOF
# Enable modules required by Drupal
a2enmod rewrite vhost_alias
service apache2 restart
##
# Configure .profile login script
#
# Change CWD instantly after login into Apache document root for convenience
echo 'cd /opt/sfl/src/drupal' > /opt/init/.profile
#!/bin/bash
if [[ ! -z "$USER_ID" ]]
then
which usermod 2>&1 >/dev/null && usermod -u $USER_ID drupalizer
service apache2 reload
fi
if [[ ! -z "$GROUP_ID" ]]
then
which groupmod 2>&1 >/dev/null && groupmod -g $GROUP_ID drupalizer
service apache2 reload
fi
exec /bin/sh -c "$*"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment