Merge branch 'docker' into 7.x-1.x

This commit is contained in:
Michael Stenta 2019-04-23 17:48:06 -04:00
commit 38196e698e
12 changed files with 124 additions and 171 deletions

6
.gitignore vendored
View File

@ -1,6 +0,0 @@
.data
.idea
libraries
modules/contrib
modules/dev
themes/bootstrap

View File

@ -12,7 +12,6 @@ includes[] = drupal-org-core.make
; -----------------------------------------------------------------------------
projects[farm][type] = profile
;projects[farm][version] = 1.1
projects[farm][download][type] = git
projects[farm][download][url] = http://git.drupal.org/project/farm.git
projects[farm][download][branch] = 7.x-1.x

View File

@ -1,25 +0,0 @@
version: '2'
services:
db:
image: mariadb:latest
volumes:
- './.data/db:/var/lib/mysql'
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: farmos
MYSQL_DATABASE: farmos
MYSQL_USER: farmos
MYSQL_PASSWORD: farmos
www:
depends_on:
- db
# image: farmos/farmos:7.x-1.1
image: farmos/farmos:7.x-1.x
volumes:
- './.data/www:/var/www/html'
ports:
- '80:80'
environment:
FARMOS_DEV: 'true'

View File

@ -1,120 +0,0 @@
#!/bin/bash
set -e
# Function for archiving the sites folder.
archive_sites () {
# If the sites folder exists, preserve it by temporarily archiving it.
if [ -e /var/www/html/sites ]; then
echo >&2 "Existing sites folder detected. Archiving temporarily..."
tar -czf /var/www/html/sites.tar.gz /var/www/html/sites
fi
}
# Function for restoring the sites folder.
restore_sites () {
# Restore the sites folder.
if [ -e /var/www/html/sites.tar.gz ]; then
echo >&2 "Restoring sites directory..."
rm -r /var/www/html/sites \
&& tar -xzf /var/www/html/sites.tar.gz -C /var/www/html/ --strip-components=3 \
&& rm /var/www/html/sites.tar.gz
fi
# Change ownership of the sites folder.
chown -R www-data:www-data /var/www/html/sites
}
# Function for deleting the farmOS codebase.
delete_farmos () {
# Remove the existing farmOS codebase, if it exists.
# Exclude sites.tar.gz.
if [ -e /var/www/html/index.php ]; then
echo >&2 "Removing existing farmOS codebase..."
find /var/www/html ! -name 'sites.tar.gz' -mindepth 1 -delete
fi
}
# Function for downloading and unpacking a farmOS release.
build_farmos_release () {
# Download and unpack farmOS release.
echo >&2 "Downloading farmOS $FARMOS_VERSION..."
curl -SL "http://ftp.drupal.org/files/projects/farm-${FARMOS_VERSION}-core.tar.gz" -o /usr/src/farm-${FARMOS_VERSION}-core.tar.gz
echo >&2 "Unpacking farmOS $FARMOS_VERSION..."
tar -xvzf /usr/src/farm-${FARMOS_VERSION}-core.tar.gz -C /var/www/html/ --strip-components=1
}
# Function for building a dev branch of farmOS.
build_farmos_dev () {
# Clone the farmOS installation profile, if it doesn't already exist.
if ! [ -e /var/farmOS/build-farm.make ]; then
git clone --branch $FARMOS_DEV_BRANCH https://git.drupal.org/project/farm.git /var/farmOS
# Update it if it does exist.
else
git -C /var/farmOS pull origin $FARMOS_DEV_BRANCH
fi
# Build farmOS with Drush. Use the --working-copy flag to keep .git folders.
drush make --working-copy --no-gitinfofile /var/farmOS/build-farm.make /tmp/farmOS \
&& cp -r /tmp/farmOS/. /var/www/html \
&& rm -r /tmp/farmOS
}
# Function for building farmOS.
build_farmos () {
# If a development environment is desired, build from dev branch. Otherwise,
# build from official packaged release.
if $FARMOS_DEV; then
build_farmos_dev
else
build_farmos_release
fi
}
# Function for determining whether a rebuild is required.
rebuild_required () {
# If farm.info doesn't exist, a rebuild is required.
if ! [ -e /var/www/html/profiles/farm/farm.info ]; then
echo >&2 "farmOS not detected. Building..."
return 0
fi
# Get the current version of farmOS from the installation profile info file.
CURRENT_VERSION="$(grep 'version' profiles/farm/farm.info | sed 's/version = .\(.*\)./\1/')"
# If this is not a development build, and the current version does not match
# the desired version, then rebuild.
if ! $FARMOS_DEV && [ "$CURRENT_VERSION" != "$FARMOS_VERSION" ]; then
echo >&2 "farmOS $CURRENT_VERSION was detected. Replacing with $FARMOS_VERSION..."
return 0
fi
echo >&2 "An existing farmOS codebase was detected."
echo >&2 "To force a rebuild, delete profiles/farm/farm.info and restart the container."
return 1
}
# Rebuild farmOS, if necessary.
if rebuild_required; then
# Archive the sites folder and delete the farmOS codebase.
archive_sites
delete_farmos
# Build farmOS.
build_farmos
# Restore the sites folder.
restore_sites
fi
# Execute the arguments passed into this script.
echo "Attempting: $@"
exec "$@"

View File

@ -1,10 +1,8 @@
# Inherit from the Drupal 7 image on Docker Hub.
FROM drupal:7
# Set environment variables.
ENV FARMOS_VERSION 7.x-1.1
ENV FARMOS_DEV_BRANCH 7.x-1.x
ENV FARMOS_DEV false
# Set the farmOS version in an environment variable.
ENV FARMOS_VERSION 7.x-1.x-dev
# Enable Apache rewrite module.
RUN a2enmod rewrite
@ -59,20 +57,14 @@ RUN { \
echo 'realpath_cache_ttl=3600'; \
} > /usr/local/etc/php/conf.d/realpath_cache-recommended.ini
# Install mysql-client (for Drush).
RUN apt-get update && apt-get install -y mysql-client
# Download the packaged release of farmOS from drupal.org.
RUN curl -SL "http://ftp.drupal.org/files/projects/farm-${FARMOS_VERSION}-core.tar.gz" -o /tmp/farm-${FARMOS_VERSION}-core.tar.gz && \
tar -xvzf /tmp/farm-${FARMOS_VERSION}-core.tar.gz -C /var/www/html/ --strip-components=1 && \
chown -R www-data:www-data /var/www/html
# Install Drush 8 with the phar file.
ENV DRUSH_VERSION 8.2.1
RUN curl -fsSL -o /usr/local/bin/drush "https://github.com/drush-ops/drush/releases/download/$DRUSH_VERSION/drush.phar" && \
chmod +x /usr/local/bin/drush && \
drush core-status
# Install git and unzip for use by Drush Make.
RUN apt-get update && apt-get install -y git unzip
# Mount a volume at /var/www/html.
VOLUME /var/www/html
# Copy the sites directory to /tmp/sites, so that it can be restored after a
# volume is mounted, if necessary.
RUN cp -rp /var/www/html/sites /tmp/sites
# Set the entrypoint.
COPY docker-entrypoint.sh /usr/local/bin/

25
docker/README.txt Normal file
View File

@ -0,0 +1,25 @@
# Running farmOS with Docker
This directory contains files necessary to build the farmOS Docker image, along
with example `docker-compose.yml` files that can be used for running farmOS in
Docker containers.
## Development environment
To run a farmOS development environment, copy `docker-compose.development.yml`
into a new directory on your server, rename it to `docker-compose.yml` and run
`docker-compose up`.
If you would like to experiment with installing farmOS on PostgreSQL with
PostGIS, copy the `docker-compose.override.postgis.yml` file to the same
directory and rename it to `docker-compose.override.yml`. This will override
the `db` configuration from `docker-compose.development.yml`.
## Production environment
To run a farmOS production environment, use `docker-compose.production.yml` as
an example for building your own configuration. Note that this example does not
include a database. It is assumed that in production environments the database
will be managed outside of Docker.
For more information, see farmOS.org/hosting/docker.

34
docker/dev/Dockerfile Normal file
View File

@ -0,0 +1,34 @@
# Inherit from the farmOS 7.x-1.x image.
FROM farmos/farmos:7.x-1.x
# Set the farmOS version to the development branch.
ENV FARMOS_VERSION 7.x-1.x
# Install Xdebug.
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
# Install git and unzip for use by Drush Make.
RUN apt-get update && apt-get install -y git unzip
# Install Drush 8 with the phar file.
ENV DRUSH_VERSION 8.2.1
RUN curl -fsSL -o /usr/local/bin/drush "https://github.com/drush-ops/drush/releases/download/${DRUSH_VERSION}/drush.phar" && \
chmod +x /usr/local/bin/drush && \
drush core-status
# Install mariadb-client so Drush can connect to the database.
RUN apt-get update && apt-get install -y mariadb-client
# Build the farmOS repository in /tmp/farmOS.
RUN git clone --branch ${FARMOS_VERSION} https://git.drupal.org/project/farm.git /tmp/farmOS && \
drush make --working-copy --no-gitinfofile /tmp/farmOS/build-farm.make /tmp/www && \
chown -R www-data:www-data /tmp/www
# Set the entrypoint.
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod u+x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]

View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
# If the webroot directory is empty, copy from /tmp/www.
if ! [ "$(ls -A /var/www/html/)" ]; then
cp -rp /tmp/www/. /var/www/html
fi
# Execute the arguments passed into this script.
echo "Attempting: $@"
exec "$@"

View File

@ -0,0 +1,24 @@
version: '2'
services:
db:
image: mariadb:latest
volumes:
- './db:/var/lib/mysql'
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: farm
MYSQL_DATABASE: farm
MYSQL_USER: farm
MYSQL_PASSWORD: farm
www:
depends_on:
- db
image: farmos/farmos:dev
volumes:
- './www:/var/www/html'
ports:
- '80:80'
environment:
XDEBUG_CONFIG: remote_host=172.17.0.1

View File

@ -7,5 +7,5 @@ services:
ports:
- '5432:5432'
environment:
POSTGRES_USER: farmos
POSTGRES_PASSWORD: farmos
POSTGRES_USER: farm
POSTGRES_PASSWORD: farm

View File

@ -0,0 +1,8 @@
version: '2'
services:
www:
image: farmos/farmos:7.x-1.1
volumes:
- './sites:/var/www/html/sites'
ports:
- '80:80'

View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
# If the sites directory is empty, copy from /tmp/sites.
if ! [ "$(ls -A /var/www/html/sites/)" ]; then
cp -rp /tmp/sites/. /var/www/html/sites
fi
# Execute the arguments passed into this script.
echo "Attempting: $@"
exec "$@"