Skip to content

Commit

Permalink
Development image
Browse files Browse the repository at this point in the history
  • Loading branch information
AlMaVizca committed Nov 20, 2023
1 parent ed742a8 commit 1d905ca
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deliver.yml
Expand Up @@ -48,7 +48,7 @@ jobs:
# farmOS Composer project 3.x branch is always used.
- name: Build and save farmOS dev Docker image
run: |
docker build --build-arg FARMOS_REPO=https://github.com/${FARMOS_REPO} --build-arg FARMOS_VERSION=${FARMOS_VERSION} -t farmos/farmos:3.x-dev docker/dev
docker build --build-arg FARMOS_REPO=https://github.com/${FARMOS_REPO} --build-arg FARMOS_VERSION=${FARMOS_VERSION} -t farmos/farmos:3.x-dev --target farmos-dev docker
docker save farmos/farmos:3.x-dev > /tmp/farmos-dev.tar
- name: Cache farmOS dev Docker image
uses: actions/cache@v3
Expand Down
51 changes: 45 additions & 6 deletions docker/Dockerfile
Expand Up @@ -4,7 +4,6 @@ FROM drupal:10.1 as baseimage
# Define common paths.
ENV FARMOS_PATH=/var/farmOS
ENV DRUPAL_PATH=/opt/drupal
ENV COMPOSER_HOME=${FARMOS_PATH}

# Set the farmOS and composer project repository URLs and versions.
ARG FARMOS_REPO=https://github.com/farmOS/farmOS.git
Expand Down Expand Up @@ -50,8 +49,8 @@ RUN apt-get update && apt-get install -y \
# Add the build-farmOS.sh script.
COPY build-farmOS.sh /usr/local/bin/

WORKDIR ${FARMOS_PATH}
# Setup composer file for non interactive installation.
WORKDIR ${FARMOS_PATH}
RUN build-farmOS.sh

##
Expand All @@ -64,6 +63,16 @@ RUN composer install --no-dev
# Set the version in farm.info.yml.
RUN sed -i "s|version: 3.x|version: ${FARMOS_VERSION}|g" ${FARMOS_PATH}/web/profiles/farm/farm.info.yml

##
# Create layer with farmOS dev sources.
FROM composer-file as farmos-dev-sources

# Install sources.
RUN composer install

# Set the version in farm.info.yml.
RUN sed -i "s|version: 3.x|version: ${FARMOS_VERSION}|g" ${FARMOS_PATH}/web/profiles/farm/farm.info.yml

##
# Add final image dependencies and configurations.
FROM baseimage as farmos-baseimage
Expand All @@ -87,7 +96,8 @@ RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean \
# Clean up ${DRUPAL_PATH}.
&& rm -r ${DRUPAL_PATH}
&& rm -r ${DRUPAL_PATH} \
&& mkdir ${DRUPAL_PATH}

# Set the entrypoint.
COPY --chown=www-data docker-entrypoint.sh /usr/local/bin/
Expand All @@ -97,13 +107,42 @@ WORKDIR ${DRUPAL_PATH}
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]

##
# Development image.
FROM farmos-baseimage as farmos-dev

# Change the user/group IDs of www-data inside the image to match the ID of the
# developer's user on the host machine. This allows Composer to create files
# owned by www-data inside the container, while keeping those files editable by
# the developer outside of the container.
# This defaults to 1000, based on the assumption that the developer is running
# as UID 1000 on the host machine. It can be overridden at image build time with:
# --build-arg WWW_DATA_ID=$(id -u)
ARG WWW_DATA_ID=1000
RUN usermod -u ${WWW_DATA_ID} www-data && groupmod -g ${WWW_DATA_ID} www-data

# Add farmOS sources
COPY --from=composer-file --chown=www-data:www-data ${FARMOS_PATH} ${FARMOS_PATH}

# Install and configure XDebug.
RUN yes | pecl install xdebug \
&& docker-php-ext-enable xdebug

# Add opcache revalidation frequency configuration.
COPY dev/conf.d/ /usr/local/etc/php/conf.d

# Add Configurations for PHP CodeSniffer, PHPStan
COPY --chown=www-data:www-data ./dev/files/ ${FARMOS_PATH}

# Add farmOS dev sources.
COPY --from=farmos-dev-sources --chown=www-data:www-data ${FARMOS_PATH} ${FARMOS_PATH}

# Configure PHPUnit.
RUN ${FARMOS_PATH}/phpunit.sh

##
# Final image.
FROM farmos-baseimage

# Add farmOS sources.
COPY --from=farmos-sources --chown=www-data:www-data ${FARMOS_PATH} ${DRUPAL_PATH}

# Add the build-farmOS.sh script to keep compatibility with dev image.
COPY build-farmOS.sh /usr/local/bin/
3 changes: 1 addition & 2 deletions docker/build-farmOS.sh
Expand Up @@ -46,5 +46,4 @@ for plugin in ${allowedPlugins[@]}; do
composer config --no-plugins allow-plugins.$plugin true
done

mkdir -p ${FARMOS_PATH}/web/sites
mkdir -p ${FARMOS_PATH}/vendor
mkdir -p ${FARMOS_PATH}/web/sites/simpletest/browser_output
75 changes: 0 additions & 75 deletions docker/dev/Dockerfile

This file was deleted.

15 changes: 15 additions & 0 deletions docker/dev/files/phpunit.sh
@@ -0,0 +1,15 @@
#!/usr/bin/env sh

cp -p ${FARMOS_PATH}/web/core/phpunit.xml.dist ${FARMOS_PATH}/phpunit.xml
sed -i 's|bootstrap="tests/bootstrap.php"|bootstrap="web/core/tests/bootstrap.php"|g' ${FARMOS_PATH}/phpunit.xml
sed -i '/failOnWarning="true"/a \ failOnIncomplete="true"' ${FARMOS_PATH}/phpunit.xml
sed -i '/failOnWarning="true"/a \ failOnSkipped="true"' ${FARMOS_PATH}/phpunit.xml
sed -i 's|name="SIMPLETEST_BASE_URL" value=""|name="SIMPLETEST_BASE_URL" value="http://www"|g' ${FARMOS_PATH}/phpunit.xml
sed -i 's|name="SIMPLETEST_DB" value=""|name="SIMPLETEST_DB" value="pgsql://farm:farm@db/farm"|g' ${FARMOS_PATH}/phpunit.xml
sed -i 's|name="BROWSERTEST_OUTPUT_DIRECTORY" value=""|name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/sites/simpletest/browser_output"|g' ${FARMOS_PATH}/phpunit.xml
sed -i 's|name="MINK_DRIVER_ARGS_WEBDRIVER" value='\'''\''|name="MINK_DRIVER_ARGS_WEBDRIVER" value='\''["chrome", { "chromeOptions": { "w3c": false, "args": ["--disable-gpu","--headless", "--no-sandbox"] } }, "http://chrome:4444/wd/hub"]'\''|g' ${FARMOS_PATH}/phpunit.xml
sed -i 's|\./|\./web/core/|g' ${FARMOS_PATH}/phpunit.xml
sed -i 's|\.\./web/core/|\./web/|g' ${FARMOS_PATH}/phpunit.xml
sed -i 's| </php>| <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>'"\n"' </php>|g' ${FARMOS_PATH}/phpunit.xml

rm ${FARMOS_PATH}/phpunit.sh
8 changes: 4 additions & 4 deletions docker/docker-entrypoint.sh
Expand Up @@ -8,15 +8,15 @@ set -e
###

# If the Drupal directory is empty, populate it from pre-built files.
if [ -d /opt/drupal ] && ! [ "$(ls -A /opt/drupal/)" ]; then
if [ -d ${DRUPAL_PATH} ] && ! [ "$(ls -A ${DRUPAL_PATH}/)" ]; then
echo "farmOS codebase not detected. Copying from pre-built files in the Docker image."
cp -rp /var/farmOS/. /opt/drupal
cp -rp ${FARMOS_PATH}/. ${DRUPAL_PATH}
fi

# If the sites directory is empty, populate it from pre-built files.
if [ -d /opt/drupal/web/sites ] && ! [ "$(ls -A /opt/drupal/web/sites/)" ]; then
if [ -d ${DRUPAL_PATH}/web/sites ] && ! [ "$(ls -A ${DRUPAL_PATH}/web/sites/)" ]; then
echo "farmOS sites directory not detected. Copying from pre-built files in the Docker image."
cp -rp /var/farmOS/web/sites/. /opt/drupal/web/sites
cp -rp ${FARMOS_PATH}/web/sites/. ${DRUPAL_PATH}/web/sites
fi

if [ -n "$FARMOS_FS_READY_SENTINEL_FILENAME" ]; then
Expand Down
9 changes: 8 additions & 1 deletion docs/development/environment/docker.md
Expand Up @@ -17,7 +17,9 @@ Available arguments and their default values are described below:
check out.
- Default: `3.x`

The `3.x-dev` image also provides the following:
## Development image

The `3.x-dev` image also provides the following build arguments:

- `WWW_DATA_ID` - The ID to use for the `www-data` user and group inside the
image. Setting this to the ID of the developer's user on the host machine
Expand All @@ -26,3 +28,8 @@ The `3.x-dev` image also provides the following:
container. If your user ID is not `1000`, build the image with:
`--build-arg WWW_DATA_ID=$(id -u)`
- Default: `1000`

To build the development image, you will have to define the target farmos-dev,
for example:

`docker build --build-arg WWW_DATA_ID=$(id -u) -t farmos/farmos:3.x-dev --target farmos-dev docker`

0 comments on commit 1d905ca

Please sign in to comment.