Commit 14d880a0 authored by Ricardo Amaro's avatar Ricardo Amaro
Browse files

first commit

parents
*~
*.tmp
*.bak
data/*
web/*
/local/web/nbproject/private/
\ No newline at end of file
FROM ubuntu:bionic
MAINTAINER Ricardo Amaro <mail_at_ricardoamaro.com>
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update; \
dpkg-divert --local --rename --add /sbin/initctl; \
ln -sf /bin/true /sbin/initctl; \
apt-get -y install git curl wget supervisor openssh-server locales \
mysql-client mysql-server apache2 pwgen vim-tiny mc iproute2 python-setuptools \
unison netcat net-tools memcached nano libapache2-mod-php php php-cli php-common \
php-gd php-json php-mbstring php-xdebug php-mysql php-opcache php-curl \
php-readline php-xml php-memcached php-oauth php-bcmath; \
apt-get clean; \
apt-get autoclean; \
apt-get -y autoremove; \
rm -rf /var/lib/apt/lists/*
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd; \
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config; \
locale-gen en_US.UTF-8; \
mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile; \
rm -rf /var/lib/mysql/*; /usr/sbin/mysqld --initialize-insecure; \
sed -i 's/^bind-address/#bind-address/g' /etc/mysql/mysql.conf.d/mysqld.cnf; \
sed -i "s/^bind-address/#bind-address/" /etc/mysql/my.cnf
# Install Composer, drush and drupal console
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& HOME=/ /usr/local/bin/composer global require drush/drush:~8 \
&& ln -s /.composer/vendor/drush/drush/drush /usr/local/bin/drush \
&& curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal \
&& chmod +x /usr/local/bin/drupal \
&& php --version; composer --version; drupal --version; drush --version
# Install supervisor
COPY ./files/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ./files/start.sh /start.sh
COPY ./files/foreground.sh /etc/apache2/foreground.sh
# Apache & Xdebug
RUN rm /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/*
ADD ./files/000-default.conf /etc/apache2/sites-available/000-default.conf
ADD ./files/xdebug.ini /etc/php/7.2/mods-available/xdebug.ini
RUN a2ensite 000-default ; a2enmod rewrite vhost_alias
# Drupal new version, clean cache
ADD https://updates.drupal.org/release-history/drupal/8.x /tmp/latest.xml
# Retrieve drupal & adminer
RUN /bin/bash -t \
&& cd /var/www/html; drush -v dl drupal --default-major=8 --drupal-project-rename="web" \
&& cd /var/www/html; chmod a+w web/sites/default; \
mkdir web/sites/default/files; chown -R www-data:www-data /var/www/html/; \
chmod -R ug+w /var/www/html/ ; \
wget "http://www.adminer.org/latest.php" -O /var/www/html/web/adminer.php
# Set some permissions
RUN mkdir -p /var/run/mysqld; \
chown mysql:mysql /var/run/mysqld; \
chmod 755 /start.sh /etc/apache2/foreground.sh
WORKDIR /var/www/html
EXPOSE 22 80 3306 9000
CMD ["/bin/bash", "/start.sh"]
This diff is collapsed.
drupal9-docker-app
====================
**Table of Contents**
- [drupal9-docker-app](#drupal9-docker-app)
- [What is this?](#what-is-this)
- [Quick 3 step instructions for a Drupal 8 Trial Run:](#quick-3-step-instructions-for-a-drupal-8-trial-run)
- [1 - Install docker:](#1---install-docker)
- [2 - Get the image and run it using port 80:](#2---get-the-image-and-run-it-using-port-80)
- [3 - Visit Drupal 8 in your browser](#3---visit-drupal-8-in-your-browser)
- [Extra - Visualize MySQL tables in your browser](#extra---visualize-mysql-tables-in-your-browser)
- [COMMUNITY CONTRIBUTIONS](#community-contributions)
- [Using `drupal9_local.sh` or `drupal9_local.bat` for local development](#using-drupal9localsh-or-drupal9localbat-for-local-development)
- [Fresh install](#fresh-install)
- [Credentials (will be shown in the output)](#credentials-will-be-shown-in-the-output)
- [Stoping and starting Drupal9-docker-app](#stoping-and-starting-drupal9-docker-app)
- [Example usage for testing:](#example-usage-for-testing)
- [For older Drupal versions check:](#for-older-drupal-versions-check)
- [You can also clone this repo somewhere and build it,](#you-can-also-clone-this-repo-somewhere-and-build-it)
- [Or build it directly from github,](#or-build-it-directly-from-github)
- [More docker awesomeness](#more-docker-awesomeness)
- [Clean up](#clean-up)
- [Known Issues](#known-issues)
- [Contributing](#contributing)
- [Authors](#authors)
- [License](#license)
# What is this?
This repo contains a Docker recipe for making a container
running Drupal9, using Linux, Apache, MySQL, Memcache and SSH.
You can also use it on the Drupal Contribution Sprints for quickly starting
working on your Drupal9 project.
Note that, despite what other Docker solutions do, this will deliver you a fast, one-shot
container with all necessary services, thus avoiding the need of container orchestration
and the need of installing more software.
- To just Trial Drupal 8 please [Install Docker](https://docs.docker.com/installation/).
- To use this repository as development environment, on Linux, MacOSX or Win10 make sure both bash+docker are installed.
Feel free to test and report any issues.
# Quick 3 step instructions for a Drupal 8 Trial Run:
## 1 - Install docker:
https://docs.docker.com/installation/
## 2 - Get the image and run it using port 80:
Open a terminal and run
```
docker run -i -t -p 80:80 ricardoamaro/drupal9
```
That's it!
## 3 - Visit Drupal 8 in your browser
[http://localhost/](http://localhost/)
Credentials (user/pass): admin/admin
## Extra - Visualize MySQL tables in your browser
[http://localhost/adminer.php](http://localhost/adminer.php)
# COMMUNITY CONTRIBUTIONS
If you want **Code and Database persistence** with Drupal9 code
on the `local/web` folder and MySQL on the `local/data` folder:
### Linux/Mac Users
```
git clone https://github.com/ricardoamaro/drupal9-docker-app.git
cd drupal9-docker-app
./drupal9_local.sh
```
### Windows Users
```
git clone https://github.com/ricardoamaro/drupal9-docker-app.git
cd drupal9-docker-app
drupal9_local.bat
```
## Using `drupal9_local.sh` or `drupal9_local.bat` for local development
### Fresh install
For a fresh install or re-install of your existing code
1. Remove the `local/data/` folder
2. Create a `local/web/` folder with your Drupal 8 docroot
eg. `composer create-project drupal-composer/drupal-project:8.x-dev local --no-interaction`
3. Delete the `sites/default/settings.php` file
4. Run `drupal9_local.sh` to linux/mac users or `drupal9_local.bat` to windows users
### Credentials (will be shown in the output)
* Drupal account-name=admin & account-pass=admin
* ROOT SSH/MYSQL PASSWORD will be on $mysql/mysql-root-pw.txt
* DRUPAL MYSQL_PASSWORD will be on $mysql/drupal-db-pw.txt
### Stoping and starting Drupal9-docker-app
To stop and restart the installed existing site
1. Press CTRL+C on the console showing the logs
2. Run `drupal9_local.sh` or `drupal9_local.bat` on the same directory
3. Open the site URL mentioned in the console
### Example usage for testing:
Using docker exec {ID} {COMMAND}, to run your own commands.
```
~$ docker run --name mydrupal9 -i -t -p 80:80 ricardoamaro/drupal9
~$ docker exec mydrupal9 uptime
10:02:59 up 16:41, 0 users, load average: 1.17, 0.92, 0.76
~$ docker exec mydrupal9 drush status | head
Drupal version : 8.5.3
Site URI : http://default
Database driver : mysql
Database hostname : localhost
Database port : 3306
Drupal bootstrap : Successful
```
## For older Drupal versions check:
https://github.com/ricardoamaro/drupal7-docker-app
https://github.com/ricardoamaro/drupal6-docker-app
## You can also clone this repo somewhere and build it,
```
git clone https://github.com/ricardoamaro/drupal9-docker-app.git
cd drupal9-docker-app
sudo docker build -t <yourname>/drupal9 .
```
## Or build it directly from github,
```
sudo docker build -t ricardo/drupal9 https://github.com/ricardoamaro/drupal9-docker-app.git
```
Note1: you cannot have port 80 already used or the container will not start.
In that case you can start by setting: `-p 8080:80`
Note2: To run the container in the background
```
sudo docker run -d -t -p 80:80 <yourname>/drupal9
```
# More docker awesomeness
How to go back to the last docker run?
```
docker ps -al
(get the container ID)
docker start -i -a (container ID)
```
This will create an ID that you can start/stop/commit changes:
```
# sudo docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
538example20 <yourname>/drupal9:latest /bin/bash /start.sh 3 minutes ago Up 6 seconds 80->80
```
Start/Stop
```
sudo docker stop 538example20
sudo docker start 538example20
```
Commit the actual state to the image
```
sudo docker commit 538example20 <yourname>/drupal9
```
Starting again with the commited changes
```
sudo docker run -d -t -p 80:80 <yourname>/drupal9 /start.sh
```
Shipping the container image elsewhere
```
sudo docker push <yourname>/drupal9
```
You can find more images using the [Docker Index][docker_index].
## Clean up
While i am developing i use this to rm all old instances
```
sudo docker ps -a | awk '{print $1}' | grep -v CONTAINER | xargs -n1 -I {} sudo docker rm {}
```
# Known Issues
* Warning: This is still in development and ports shouldn't
be open to the outside world.
# Contributing
Feel free to submit any bugs, requests, or fork and contribute
to this code. :)
1. Fork the repo
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## Authors
Created and maintained by [Ricardo Amaro][author]
http://blog.ricardoamaro.com
## License
GPL v3
[author]: https://github.com/ricardoamaro
[docker_upstart_issue]: https://github.com/dotcloud/docker/issues/223
[docker_index]: https://index.docker.io/
version: '3.3'
services:
drupal:
stdin_open: true
tty: true
image: "ricardoamaro/drupal9"
ports:
- 80:80
volumes:
- ./local/data:/var/lib/mysql
- ./local:/var/www/html
restart: always
# varnish:
# image: wodby/drupal-varnish:4.1-2.1.2
# ports:
# - 80:6081
# depends_on:
# - drupal
# environment:
# VARNISH_SECRET: secret
# VARNISH_BACKEND_HOST: drupal
# VARNISH_BACKEND_PORT: 80
# VARNISH_CONFIG_PRESET: drupal
# VARNISH_PURGE_EXTERNAL_REQUEST_HEADER: X-Real-IP
# labels:
# - 'traefik.backend=varnish'
# - 'traefik.port=6081'
# - "traefik.frontend.rule=Host:varnish.${COMPOSE_PROJECT_NAME}.docker.localhost"
:: Note: LOCAL can be something else for several sites running from the console
:: eg. drupal9_local.bat LOCAL
@echo off
mkdir %1%\web
mkdir %1%\data
:: Create a random LOCAL ports for the container
@SET /a "WEBPORT = %RANDOM% * (50000 - 10000 + 1) / 32768 + 10000"
@SET /a "DBPORT = %RANDOM% * (50000 - 10000 + 1) / 32768 + 10000"
echo **** Starting Drupal using persistence on %1%/ folder ****
echo Using MYSQL PORT: %DBPORT%
echo Using HTTP URL : http://localhost:%WEBPORT%
:: Create a network
:: docker network create --subnet=10.8.8.0/16 drupalnet
:: Run the container
docker run -it --volume=%cd%\%1\data:/var/lib/mysql --volume=%cd%\%1:/var/www/html -p %WEBPORT%:80 -p %DBPORT%:3306 ricardoamaro/drupal9
#!/bin/bash -e
# Note: $LOCAL can be something else for several sites running from the console
# eg. ./drupal9_local.sh test
LOCAL=${1:-"local"}
mkdir -p ${LOCAL}/web ${LOCAL}/data
# Create a random ${LOCAL} ssh port for the container
export WEBPORT="$(((RANDOM % 10000)+ 50000))"
export DBPORT="$(((RANDOM % 10000)+ 51000))"
echo "**** Starting Drupal using persistence on ${LOCAL}/ folder ****"
echo " Using MYSQL PORT: ${DBPORT}"
echo " Using HTTP URL : http://localhost:${WEBPORT}"
# Create a network
#docker network create --subnet=10.8.8.0/16 drupalnet 2>/dev/null || true
# Run the container
docker run -it \
--volume=${PWD}/${LOCAL}/data:/var/lib/mysql \
--volume=${PWD}/${LOCAL}:/var/www/html \
-p ${WEBPORT}:80 \
-p ${DBPORT}:3306 \
ricardoamaro/drupal9
:: Create a random local ports for the container
@SET /a "WEBPORT = %RANDOM% * (50000 - 10000 + 1) / 32768 + 10000"
@SET /a "DBPORT = %RANDOM% * (50000 - 10000 + 1) / 32768 + 10000"
echo **** Starting Drupal Trial Test Run with ephemeral data ****
echo Using MYSQL PORT: %DBPORT%
echo Using HTTP URL : http://localhost:%WEBPORT%
:: Create a network
:: docker network create --subnet=10.8.8.0/16 drupalnet
:: Run the container
docker run -it -p ${WEBPORT}:80 -p ${DBPORT}:3306 ricardoamaro/drupal9
\ No newline at end of file
#!/bin/bash -e
# Create a random local ssh port for the container
export WEBPORT="$(((RANDOM % 10000)+ 50000))"
export DBPORT="$(((RANDOM % 10000)+ 51000))"
echo "**** Starting Drupal Trial Test Run with ephemeral data ****"
echo " Using MYSQL PORT: ${DBPORT}"
echo " Using HTTP URL : http://localhost:${WEBPORT}"
# Create a network
#docker network create --subnet=10.8.8.0/16 drupalnet 2>/dev/null || true
# Run the container
docker run -it \
-p ${WEBPORT}:80 \
-p ${DBPORT}:3306 \
ricardoamaro/drupal9
<VirtualHost *:80>
ServerName drupal9.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/web
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/html>
AllowOverride All
</Directory>
#!/bin/bash
read pid cmd state ppid pgrp session tty_nr tpgid rest < /proc/self/stat
trap "kill -TERM -$pgrp; exit" EXIT TERM KILL SIGKILL SIGTERM SIGQUIT
source /etc/apache2/envvars
apache2 -D FOREGROUND
#!/bin/bash
export BASEHTML="/var/www/html"
export DOCROOT="/var/www/html/web"
export GRPID=$(stat -c "%g" /var/lib/mysql/)
export DRUSH="/.composer/vendor/drush/drush/drush"
export LOCAL_IP=$(hostname -I| awk '{print $1}')
export HOSTIP=$(/sbin/ip route | awk '/default/ { print $3 }')
export DRUPALVER=9
echo "${HOSTIP} dockerhost" >> /etc/hosts
echo "Started Container: $(date)"
# Create a basic mysql install
if [ ! -d /var/lib/mysql/mysql ]; then
echo "**** No MySQL data found. Creating data on /var/lib/mysql/ ****"
mysqld --initialize-insecure
else
echo "**** MySQL data found on /var/lib/mysql/ ****"
fi
# Start supervisord
supervisord -c /etc/supervisor/conf.d/supervisord.conf -l /tmp/supervisord.log
# If there is no index.php, download drupal
if [ ! -f ${DOCROOT}/index.php ]; then
echo "**** No Drupal found. Downloading latest to ${DOCROOT}/ ****"
cd ${BASEHTML};
${DRUSH} -vy dl drupal \
--default-major=${DRUPALVER} --drupal-project-rename="web"
chmod a+w ${DOCROOT}/sites/default;
mkdir ${DOCROOT}/sites/default/files;
wget "http://www.adminer.org/latest.php" -O ${DOCROOT}/adminer.php
chown -R www-data:${GRPID} ${DOCROOT}
chmod -R ug+w ${DOCROOT}
else
echo "**** ${DOCROOT}/index.php found ****"
fi
# Setup Drupal if services.yml or settings.php is missing
if ( ! grep -q 'database.*=>.*drupal' ${DOCROOT}/sites/default/settings.php 2>/dev/null); then
# Generate random passwords
DRUPAL_DB="drupal"
DEBPASS=$(grep password /etc/mysql/debian.cnf |head -n1|awk '{print $3}')
ROOT_PASSWORD=`pwgen -c -n -1 12`
DRUPAL_PASSWORD=`pwgen -c -n -1 12`
echo ${ROOT_PASSWORD} > /var/lib/mysql/mysql/mysql-root-pw.txt
echo ${DRUPAL_PASSWORD} > /var/lib/mysql/mysql/drupal-db-pw.txt
# Wait for mysql
echo -n "Waiting for mysql "
while ! mysqladmin status >/dev/null 2>&1;
do echo -n . ; sleep 1;
done;
echo;
# Create and change MySQL creds
mysqladmin -u root password ${ROOT_PASSWORD} 2>/dev/null
mysql -uroot -p${ROOT_PASSWORD} -e \
"GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '$DEBPASS';" 2>/dev/null
mysql -uroot -p${ROOT_PASSWORD} -e \
"CREATE DATABASE drupal; GRANT ALL PRIVILEGES ON drupal.* TO 'drupal'@'%' IDENTIFIED BY '$DRUPAL_PASSWORD'; FLUSH PRIVILEGES;" 2>/dev/null
cd ${DOCROOT}
cp sites/default/default.settings.php sites/default/settings.php
${DRUSH} site-install standard -y --account-name=admin --account-pass=admin \
--db-url="mysql://drupal:${DRUPAL_PASSWORD}@localhost:3306/drupal" \
--site-name="Drupal9 docker App" | grep -v 'continue?' 2>/dev/null
# TODO: move this to composer.json
${DRUSH} -y dl memcache >/dev/null 2>&1
${DRUSH} -y en memcache | grep -v 'continue?' | grep -v error 2>/dev/null
else
echo "**** ${DOCROOT}/sites/default/settings.php database found ****"
ROOT_PASSWORD=$(cat /var/lib/mysql/mysql/mysql-root-pw.txt)
DRUPAL_PASSWORD=$(cat /var/lib/mysql/mysql/drupal-db-pw.txt)
fi
# Change root password
echo "root:${ROOT_PASSWORD}" | chpasswd
# Clear caches and reset files perms
chown -R www-data:${GRPID} ${DOCROOT}/sites/default/
chmod -R ug+w ${DOCROOT}/sites/default/
chown -R mysql:${GRPID} /var/lib/mysql/
chmod -R ug+w /var/lib/mysql/
find -type d -exec chmod +xr {} \;
(sleep 3; drush --root=${DOCROOT}/ cache-rebuild 2>/dev/null) &
echo
echo "---------------------- USERS CREDENTIALS ($(date +%T)) -------------------------------"
echo
echo " DRUPAL: http://${LOCAL_IP} with user/pass: admin/admin"
echo
echo " MYSQL : http://${LOCAL_IP}/adminer.php drupal/${DRUPAL_PASSWORD} or root/${ROOT_PASSWORD}"
echo " SSH : ssh root@${LOCAL_IP} with user/pass: root/${ROOT_PASSWORD}"
echo
echo " Please report any issues to https://github.com/ricardoamaro/drupal9-docker-app"
echo " USE CTRL+C TO STOP THIS APP"
echo
echo "------------------------------ STARTING SERVICES ---------------------------------------"
tail -f /tmp/supervisord.log
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=15MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[program:sshd]
command=/usr/sbin/sshd -D
autostart=true
autorestart=true
stdout_events_enabled = true
[program:mysqld]
command=/usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/bin/mysqld_safe --socket /var/run/mysqld/mysqld.sock > /dev/null
autostart=true
autorestart=true
[program:httpd]
command=/etc/apache2/foreground.sh
stopsignal=6
[program:memcached]
command=/usr/bin/memcached -p 11211 -u www-data -m 64 -c 1024 -t 4
[xdebug]
;zend_extension=xdebug.so
xdebug.max_nesting_level=256
xdebug.remote_connect_back=0
;xdebug.remote_enable=1
xdebug.remote_port=9000
;xdebug.remote_autostart=1
xdebug.remote_cookie_expire_time=86400
xdebug.remote_log="/var/log/apache2/xdebug.log"
;xdebug.remote_host=172.17.42.1
xdebug.remote_host=dockerhost
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.collect_vars=on
xdebug.collect_params=4
xdebug.dump_globals=on
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
# Deploy Drupal9 on Kubernetes
This deployment will setup a Drupal site using Kubernetes. The drupal9-docker-app is not
natively designed to be ran on Kubernetes however it serves the pourpose for testing and development.
## Usage
1 - Spun up a kubernetes cluster
2 - Start the deployment with
```
kubectl apply -f drupal-deployment.yaml
```
# Disclaimer
This config only serves development and is not the proper way to run Drupal on kubernetes. If you
want a more robust and complex deployment that will scale you can do it with Helm and Bitnami's
containers https://bitnami.com/stack/drupal/helm
apiVersion: v1
kind: Service
metadata:
name: drupal
labels:
app: drupal
spec:
ports:
- port: 80
selector:
app: drupal
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: drupal-pv-claim
labels:
app: drupal
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: drupal
labels:
app: drupal
spec:
selector:
matchLabels:
app: drupal
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: drupal
tier: frontend
spec:
containers:
- image: ricardoamaro/drupal9:latest
name: drupal
ports:
- containerPort: 80
name: drupal
volumeMounts:
- name: drupal-persistent-storage
mountPath: /var/www/html
- name: drupal-persistent-storage
mountPath: /var/lib/mysql
subPath: data
volumes:
- name: drupal-persistent-storage
persistentVolumeClaim:
claimName: drupal-pv-claim
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