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 <>
# 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\
if [[ ! -z "$USER_ID" ]]\n\
which usermod 2>&1 >/dev/null && usermod -u $USER_ID drupalizer\n\
service apache2 reload\n\
if [[ ! -z "$GROUP_ID" ]]\n\
which groupmod 2>&1 >/dev/null && groupmod -g $GROUP_ID drupalizer\n\
service apache2 reload\n\
exec /bin/sh -c "$*"'\
> /opt/init/ && chmod a+x /opt/init/
# Create Apache configuration
RUN echo 'ServerName localhost\n\
<VirtualHost *:80>\n\
DocumentRoot /opt/sfl/src/drupal\n\
<Directory /opt/sfl/src/drupal/>\n\
AllowOverride All\n\
Options FollowSymLinks\n\
Require all granted\n\
> /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/"]
ENTRYPOINT ["/opt/init/init"]
CMD ["/sbin/my_init"]
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
[[ -f $i && -r $i ]] && . "$i"
# 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
# Make Apache run as the main `drupalizer` user
cat >> /etc/apache2/envvars << EOF
export APACHE_RUN_USER=drupalizer
export APACHE_RUN_GROUP=drupalizer
# 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
if [[ ! -z "$USER_ID" ]]
which usermod 2>&1 >/dev/null && usermod -u $USER_ID drupalizer
service apache2 reload
if [[ ! -z "$GROUP_ID" ]]
which groupmod 2>&1 >/dev/null && groupmod -g $GROUP_ID drupalizer
service apache2 reload
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