Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Add Drupal #18

Merged
merged 3 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
service-credentials.txt
Untitled
build.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It covers these baseline features and scenarios:


# One time Container Service and Bluemix services setup
See the Container Service Kubernetes and Bluemix services (MySQL and Redis) [configuration instructions](docs/INITIAL-SETUP.md).
See the Container Service Kubernetes and Bluemix services (MySQL, Redis, Memcached) [configuration instructions](docs/INITIAL-SETUP.md).

# Building and deploying the first set of containers
See the Docker container build and Kubernetes deployment [instructions](docs/DEPLOY-CONTAINERS.md).
Expand Down
10 changes: 5 additions & 5 deletions scripts/build-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ bx cr login

# Build the NGINX image (configure Fast CGI)
cd docker/nginx
docker build -t registry.ng.bluemix.net/krook/nginx:latest .
docker build --tag registry.ng.bluemix.net/krook/nginx:latest --no-cache .
docker push registry.ng.bluemix.net/krook/nginx:latest

# Move back to ROOT_DIR
cd $ROOT_DIR

# Build the PHP-FPM image (base image, inject code, run composer)
cd docker/php-fpm
docker build -t registry.ng.bluemix.net/krook/php-fpm:latest .
docker build --tag registry.ng.bluemix.net/krook/php-fpm:latest --no-cache .
docker push registry.ng.bluemix.net/krook/php-fpm:latest

# Move back to ROOT_DIR
cd $ROOT_DIR

# Build the PHP-FPM image (base image, inject code, run composer)
cd docker/php-cli
docker build -t registry.ng.bluemix.net/krook/php-cli:latest .
docker push registry.ng.bluemix.net/krook/php-cli:latest
# cd docker/php-cli
# docker build --tag registry.ng.bluemix.net/krook/php-cli:latest .
# docker push registry.ng.bluemix.net/krook/php-cli:latest

# Move back to ROOT_DIR
cd $ROOT_DIR
15 changes: 7 additions & 8 deletions scripts/docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
FROM nginx

# Set timezone
# Set consistent timezone
ENV CONTAINER_TIMEZONE="UTC"

RUN rm -f /etc/localtime \
&& ln -s /usr/share/zoneinfo/${CONTAINER_TIMEZONE} /etc/localtime

RUN rm /etc/nginx/conf.d/default.conf

COPY fastcgi.conf /etc/nginx/conf.d/

COPY index.html /var/www/html/

# Debug
RUN file="$(ls -al /var/www/html)" && echo $file

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
# Configure the read/write volume for a non-root user
COPY index.html /root/html/
COPY start.sh /root/start.sh
RUN chmod 755 /root/start.sh

ENTRYPOINT ["/root/start.sh"]
2 changes: 1 addition & 1 deletion scripts/docker/nginx/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>This is a static page served with NGINX.</h1>

<h2>Hit the <a href="phpinfo.php">PHP-FPM page</a>.</h2>
<h2>Hit the <a href="index.php">PHP-FPM page</a>.</h2>

<h2>Hit the <a href="create.php">create page</a>.</h2>

Expand Down
8 changes: 8 additions & 0 deletions scripts/docker/nginx/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

# Couldn't add this file at build time because the volume wasn't mounted
cp /root/html/index.html /var/www/html/

# Now that volume is usable, start up NGINX on port 80
nginx -g "daemon off;";
9 changes: 5 additions & 4 deletions scripts/docker/php-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM php:5.6-cli
FROM php:7.1-cli

# Set timezone, worker name, and index (TODO: where to set this?)
ENV CONTAINER_TIMEZONE="UTC" \
WORKER_NAME="send-emails" \
# Worker name and index (TODO: where to set this?)
ENV WORKER_NAME="send-emails" \
WORKER_INDEX="1"

# Set consistent timezone
ENV CONTAINER_TIMEZONE="UTC"
RUN rm -f /etc/localtime \
&& ln -s /usr/share/zoneinfo/${CONTAINER_TIMEZONE} /etc/localtime

Expand Down
106 changes: 59 additions & 47 deletions scripts/docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,67 @@
FROM php:5.6-fpm
FROM php:7.1-fpm

# Set timezone
# Set consistent timezone
ENV CONTAINER_TIMEZONE="UTC"

RUN rm -f /etc/localtime \
&& ln -s /usr/share/zoneinfo/${CONTAINER_TIMEZONE} /etc/localtime

# Install dependencies
RUN apt-get update && \
apt-get install curl nano git zlib1g-dev libicu-dev libmemcached-dev -y && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Fetch extensions from PECL
RUN mkdir -p /usr/src/php/ext/ \
&& curl -L https://pecl.php.net/get/memcached-2.2.0.tgz >> /usr/src/php/ext/memcached.tgz \
&& curl -L https://pecl.php.net/get/redis-3.1.3.tgz >> /usr/src/php/ext/redis.tgz \
&& tar xvzf /usr/src/php/ext/memcached.tgz -C /usr/src/php/ext/ \
&& tar xvzf /usr/src/php/ext/redis.tgz -C /usr/src/php/ext/ \
&& ln -s /usr/src/php/ext/memcached-2.2.0 /usr/src/php/ext/memcached \
&& ln -s /usr/src/php/ext/redis-3.1.3 /usr/src/php/ext/redis

# Build PHP with the extension source
RUN docker-php-ext-configure memcached \
&& docker-php-ext-install memcached \
&& docker-php-ext-configure redis --with-zlib-dir=/usr \
&& docker-php-ext-install redis \
&& docker-php-ext-enable opcache \
&& docker-php-ext-install mysqli pdo pdo_mysql mbstring bcmath pcntl intl

# Tidy up
RUN apt-get clean autoclean \
&& apt-get autoremove -y \
&& rm -rf /var/lib/{apt,dpkg,cache,log}/

# Add configuration file
COPY php-fpm.conf /usr/local/etc/php/conf.d/
RUN echo "memcached.use_sasl = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-memcached.ini

# Bundle app source
COPY app/ /var/www/html

# Install app dependencies
RUN cd /var/www/html && composer install --no-interaction

# Debug app file
RUN file="$(ls -al /var/www/html)" && echo $file

# Configure the read/write volume for a non-root user
RUN groupadd --gid 1010 temp_user
RUN useradd --uid 1010 --gid 1010 -m --shell /bin/bash temp_user
ENV TEMP_USER=temp_user
# Install prerequisite OS packages
RUN apt-get update && apt-get install -y curl git rsync

# install the PHP extensions we need
RUN set -ex \
&& buildDeps=' \
libjpeg62-turbo-dev \
libpng12-dev \
libpq-dev \
zlib1g-dev \
libicu-dev \
libmemcached-dev \
' \
&& apt-get install -y --no-install-recommends $buildDeps \
&& pecl install -o -f redis \
&& docker-php-ext-enable redis \
&& ls -la /usr/local/etc/php/conf.d/ \
&& docker-php-ext-configure gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
&& docker-php-ext-install -j "$(nproc)" gd mbstring opcache pdo pdo_mysql zip

RUN cd /tmp \
&& git clone -b php7 https://github.com/php-memcached-dev/php-memcached \
&& cd php-memcached \
&& phpize \
&& ./configure \
&& make \
&& cp /tmp/php-memcached/modules/memcached.so /usr/local/lib/php/extensions/no-debug-non-zts-20160303/memcached.so \
&& docker-php-ext-enable memcached \
&& ls -la /usr/local/etc/php/conf.d/

# See https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=60'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

# Download and verify Drupal
# https://www.drupal.org/node/3060/release
WORKDIR /var/www
ENV DRUPAL_VERSION 8.3.7
ENV DRUPAL_MD5 e7b1f382d6bd2b18d4b4aca01d335bc0
RUN curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz \
&& echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c - \
&& tar -xzf drupal.tar.gz \
&& rm drupal.tar.gz \
&& rm -fr html \
&& mv drupal* html \
&& cp -R /var/www/html/sites /tmp/sites \
&& cp -R /var/www/html/modules /tmp/modules \
&& cp -R /var/www/html/themes /tmp/themes

COPY start.sh /root/start.sh
RUN chmod 755 /root/start.sh

Expand Down
2 changes: 1 addition & 1 deletion scripts/docker/php-fpm/app/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
$memcached->set('Cat', 'Tarball!');

date_default_timezone_set('UTC');
file_put_contents('/content/uploads/data/file.txt', 'Wrote some text about Tarball the cat on ' . date('l jS \of F Y h:i:s A'));
file_put_contents('/var/www/html/sites/file.txt', 'Wrote some text about Tarball the cat on ' . date('l jS \of F Y h:i:s A'));
2 changes: 1 addition & 1 deletion scripts/docker/php-fpm/app/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

$memcached->flush();

unlink('/content/uploads/data/file.txt');
unlink('/var/www/html/sites/file.txt');
2 changes: 1 addition & 1 deletion scripts/docker/php-fpm/app/read.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
}
}

echo file_get_contents('/content/uploads/data/file.txt') . '<br />';
echo file_get_contents('/var/www/html/sites/file.txt') . '<br />';
6 changes: 0 additions & 6 deletions scripts/docker/php-fpm/php-fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,3 @@ daemonize = no
;;;;;;;;;;;;;;;;;;;;

; See /etc/php-fpm.d/*.conf

;;;;;;;;;;;;;;;;;;;;
; Extensions ;
;;;;;;;;;;;;;;;;;;;;

memcached.use_sasl = 1
53 changes: 48 additions & 5 deletions scripts/docker/php-fpm/start.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,73 @@
#!/bin/bash
set -e

# Configure the read/write volume for a non-root user
groupadd --gid 1010 temp_user
useradd --uid 1010 --gid 1010 -m --shell /bin/bash temp_user
TEMP_USER=temp_user

# This is the mount point for the shared volume.
# By default the mount point is owned by the root user.
MOUNT_PATH="/content/uploads"
MOUNT_PATH="/var/www/html"
TEMP_USER=${TEMP_USER:-"temp_user"}

# Debug
echo "MOUNT_PATH is ${MOUNT_PATH}"
echo "TEMP_USER is ${TEMP_USER}"

echo "DRUPAL_VERSION is ${DRUPAL_VERSION}"
echo "DRUPAL_MD5 is ${DRUPAL_MD5}"

# This function creates a subdirectory that is owned by
# the non-root user under the shared volume mount path.
create_data_dir() {
#Add the non-root user to primary group of root user.
# Add the non-root user to primary group of root user.
usermod -aG root $TEMP_USER

# Provide read-write-execute permission to the group for the shared volume mount path.
chmod 777 $MOUNT_PATH

# Create a directory under the shared path owned by non-root user www.
su -c "[ ! -d /home/mlzboy/b2c2/shared/db ] && mkdir -p ${MOUNT_PATH}/data" -l $TEMP_USER
chmod -R 777 ${MOUNT_PATH}/data
cd $MOUNT_PATH
pwd

echo "ls -al before"
ls -al ${MOUNT_PATH}

#echo "Installing Drupal"
#cp -R /tmp/drupal*/* ${MOUNT_PATH}

#echo "Deleting old files"
#rm -rf /tmp/drupal*

# Change permissions on the folders for the non-root user.
echo "Changing directory permissions"
chmod -R 777 ${MOUNT_PATH}/sites
chmod -R 777 ${MOUNT_PATH}/modules
chmod -R 777 ${MOUNT_PATH}/themes

echo "Changing directory owners"
echo $TEMP_USER
echo ${MOUNT_PATH}/sites
chown -R $TEMP_USER ${MOUNT_PATH}/sites
chown -R $TEMP_USER ${MOUNT_PATH}/modules
chown -R $TEMP_USER ${MOUNT_PATH}/themes

echo "Copy back Drupal files to the mount point"
cp -R /tmp/sites ${MOUNT_PATH}/sites
cp -R /tmp/modules ${MOUNT_PATH}/modules
cp -R /tmp/themes ${MOUNT_PATH}/themes

echo "ls -al after"
ls -al ${MOUNT_PATH}

# For security, remove the non-root user from root user group.
echo "Removing user from group"
deluser $TEMP_USER root

# Change the shared volume mount path back to its original read-write-execute permission.
echo "Resetting parent directory permissions"
chmod 755 $MOUNT_PATH

echo "Created Data directory..."
}

Expand Down
22 changes: 18 additions & 4 deletions scripts/kubernetes/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ spec:
name: http
volumeMounts:
-
mountPath: /content/uploads
name: user-files-local-storage
mountPath: /var/www/html/sites
name: sites-local-storage
-
mountPath: /var/www/html/themes
name: themes-local-storage
-
mountPath: /var/www/html/modules
name: modules-local-storage
imagePullSecrets:
-
name: image-pull
volumes:
-
name: user-files-local-storage
name: sites-local-storage
persistentVolumeClaim:
claimName: sites-lv-claim
-
name: themes-local-storage
persistentVolumeClaim:
claimName: themes-lv-claim
-
name: modules-local-storage
persistentVolumeClaim:
claimName: user-files-lv-claim
claimName: modules-lv-claim
26 changes: 24 additions & 2 deletions scripts/kubernetes/persistent-volumes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: user-files-lv-claim
name: sites-lv-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: themes-lv-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: modules-lv-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
Loading