Consolidate Composer install logic into a build-farmOS.sh script.

This commit is contained in:
Michael Stenta 2020-08-12 11:17:39 -04:00
parent cea64ad078
commit aabadf26ad
3 changed files with 63 additions and 40 deletions

View File

@ -71,22 +71,15 @@ RUN apt-get update \
# Set the COMPOSER_MEMORY_LIMIT environment variable to unlimited.
ENV COMPOSER_MEMORY_LIMIT=-1
# Build the farmOS codebase in /var/farmoS.
# Generate an empty project from farmos/project, clone the composer-project
# from a specific repo+revision, replace the farmOS repo+revision within
# composer.json, and run composer install with --no-dev. Finally, change the
# ownership of the sites directory and copy the farmOS codebase into
# /opt/drupal.
RUN mkdir /var/farmOS && cd /var/farmOS \
&& git clone ${PROJECT_REPO} project && mv project/.git ./.git && rm -rf project && git checkout ${PROJECT_VERSION} && git reset --hard \
&& sed -i 's|"repositories": \[|"repositories": \[ {"type": "git", "url": "'"${FARMOS_REPO}"'"},|g' composer.json \
&& if ! [ "${FARMOS_VERSION}" = "2.x" ]; then \
sed -i 's|"farmos/farmos": "2.x-dev"|"farmos/farmos": "dev-'"${FARMOS_VERSION}"'"|g' composer.json; \
fi \
&& export COMPOSER_HOME="$(mktemp -d)" \
&& composer install --no-dev \
&& rm -rf "$COMPOSER_HOME" \
&& chown -R www-data:www-data web/sites \
# Add the build-farmOS.sh script.
COPY build-farmOS.sh /usr/local/bin/
RUN chmod a+x /usr/local/bin/build-farmOS.sh
# Build the farmOS codebase in /var/farmoS with the --no-dev flag.
# Change the ownership of the sites directory and copy the farmOS codebase into /opt/drupal.
RUN mkdir /var/farmOS \
&& /usr/local/bin/build-farmOS.sh --no-dev \
&& chown -R www-data:www-data /var/farmOS/web/sites \
&& rm -r /opt/drupal && cp -rp /var/farmOS /opt/drupal
# Set the entrypoint.

41
docker/build-farmOS.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
set -e
###
# This script will build the farmOS codebase in /var/farmOS.
###
# If /var/farmOS is not empty, bail.
if [ "$(ls -A /var/farmOS/)" ]; then
exit 1
fi
# Make /var/farmOS the working directory.
cd /var/farmOS
# Generate an empty Composer project project and checkout a specific version.
git clone ${PROJECT_REPO} project
mv project/.git ./.git
rm -rf project
git checkout ${PROJECT_VERSION}
git reset --hard
# Replace the farmOS repository and version in composer.json.
# If the farmOS version is not "2.x", then prepend it with "dev-".
sed -i 's|"repositories": \[|"repositories": \[ {"type": "git", "url": "'"${FARMOS_REPO}"'"},|g' composer.json
if ! [ "${FARMOS_VERSION}" = "2.x" ]; then
sed -i 's|"farmos/farmos": "2.x-dev"|"farmos/farmos": "dev-'"${FARMOS_VERSION}"'"|g' composer.json
fi
# Create a temporary Composer cache directory.
export COMPOSER_HOME="$(mktemp -d)"
# Run composer install with optional arguments passed into this script.
if [ $# -eq 0 ]; then
composer install
else
composer install "$*"
fi
# Remove the Composer cache directory.
rm -rf "$COMPOSER_HOME"

View File

@ -18,32 +18,21 @@ ARG WWW_DATA_ID=1000
RUN usermod -u ${WWW_DATA_ID} www-data && groupmod -g ${WWW_DATA_ID} www-data
# Build the farmOS codebase in /var/farmOS.
# Generate an empty project from farmos/project, clone the composer-project
# from a specific repo+revision, replace the farmOS repo+revision within
# composer.json, and run composer install. Finally, change the ownership of the
# entier farmOS codebase and copy it into /opt/drupal.
RUN rm -r /var/farmOS && mkdir /var/farmOS && cd /var/farmOS \
&& git clone ${PROJECT_REPO} project && mv project/.git ./.git && rm -rf project && git checkout ${PROJECT_VERSION} && git reset --hard \
&& sed -i 's|"repositories": \[|"repositories": \[ {"type": "git", "url": "'"${FARMOS_REPO}"'"},|g' composer.json \
&& if ! [ "${FARMOS_VERSION}" = "2.x" ]; then \
sed -i 's|"farmos/farmos": "2.x-dev"|"farmos/farmos": "dev-'"${FARMOS_VERSION}"'"|g' composer.json; \
fi \
&& export COMPOSER_HOME="$(mktemp -d)" \
&& composer install \
&& rm -rf "$COMPOSER_HOME" \
&& chown -R www-data:www-data . \
&& rm -r /opt/drupal && cp -rp /var/farmOS /opt/drupal
RUN /usr/local/bin/build-farmOS.sh
# Configure PHPUnit.
RUN cp -p web/core/phpunit.xml.dist phpunit.xml \
&& sed -i 's|bootstrap="tests/bootstrap.php"|bootstrap="web/core/tests/bootstrap.php"|g' phpunit.xml \
&& sed -i 's|name="SIMPLETEST_BASE_URL" value=""|name="SIMPLETEST_BASE_URL" value="http://localhost"|g' phpunit.xml \
&& sed -i 's|name="SIMPLETEST_DB" value=""|name="SIMPLETEST_DB" value="pgsql://farm:farm@db/farm"|g' phpunit.xml \
&& sed -i 's|name="BROWSERTEST_OUTPUT_DIRECTORY" value=""|name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/sites/simpletest/browser_output"|g' phpunit.xml \
&& sed -i 's|\./|\./web/core/|g' phpunit.xml \
&& sed -i 's|\.\./web/core/|\./web/|g' phpunit.xml \
&& mkdir -p /var/farmOS/web/sites/simpletest/browser_output \
&& chown -R www-data:www-data /var/farmOS/web/sites/simpletest
RUN cp -p /var/farmOS/web/core/phpunit.xml.dist /var/farmOS/phpunit.xml \
&& sed -i 's|bootstrap="tests/bootstrap.php"|bootstrap="web/core/tests/bootstrap.php"|g' /var/farmOS/phpunit.xml \
&& sed -i 's|name="SIMPLETEST_BASE_URL" value=""|name="SIMPLETEST_BASE_URL" value="http://localhost"|g' /var/farmOS/phpunit.xml \
&& sed -i 's|name="SIMPLETEST_DB" value=""|name="SIMPLETEST_DB" value="pgsql://farm:farm@db/farm"|g' /var/farmOS/phpunit.xml \
&& sed -i 's|name="BROWSERTEST_OUTPUT_DIRECTORY" value=""|name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/sites/simpletest/browser_output"|g' /var/farmOS/phpunit.xml \
&& sed -i 's|\./|\./web/core/|g' /var/farmOS/phpunit.xml \
&& sed -i 's|\.\./web/core/|\./web/|g' /var/farmOS/phpunit.xml \
&& mkdir -p /var/farmOS/web/sites/simpletest/browser_output
# Change the ownership of the entire farmOS codebase and copy it into /opt/drupal.
RUN chown -R www-data:www-data /var/farmOS \
&& rm -r /opt/drupal && cp -rp /var/farmOS /opt/drupal
# Install and configure XDebug.
RUN yes | pecl install xdebug \