Compare commits

...

6 Commits

Author SHA1 Message Date
Aldo 84e386b78f
Merge 1d905ca311 into d16bc107ad 2023-12-06 05:00:42 -07:00
Paul Weidner d16bc107ad Use strict identical operator when checking geometry format #756 2023-11-30 14:02:13 -05:00
Paul Weidner 56b3b4de95 Correct alter hook to add password grant to static scopes #755 2023-11-30 13:55:52 -05:00
AlMaVizca 1d905ca311
Development image 2023-11-20 16:36:07 +07:00
AlMaVizca ed742a8d83
Production image 2023-11-19 21:30:01 +07:00
AlMaVizca 0bdfd3d0af
Define baseimage with arguments required in multiple stages
Change versions, add common paths

Keep drupal path
2023-11-19 20:41:07 +07:00
10 changed files with 153 additions and 127 deletions

View File

@ -48,7 +48,7 @@ jobs:
# farmOS Composer project 3.x branch is always used. # farmOS Composer project 3.x branch is always used.
- name: Build and save farmOS dev Docker image - name: Build and save farmOS dev Docker image
run: | 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 docker save farmos/farmos:3.x-dev > /tmp/farmos-dev.tar
- name: Cache farmOS dev Docker image - name: Cache farmOS dev Docker image
uses: actions/cache@v3 uses: actions/cache@v3

View File

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed
- [Correct alter hook to add password grant to static scopes #755](https://github.com/farmOS/farmOS/pull/755)
- [Use strict identical operator when checking geometry format #756](https://github.com/farmOS/farmOS/pull/756)
## [3.0.0-beta3] 2023-11-27 ## [3.0.0-beta3] 2023-11-27
### Fixed ### Fixed

View File

@ -1,7 +1,20 @@
# Use the official Drupal 10 image to build GEOS PHP extension. # Use the official Drupal 10 image to build GEOS PHP extension.
FROM drupal:10.1 as php-dependencies FROM drupal:10.1 as baseimage
# Define common paths.
ENV FARMOS_PATH=/var/farmOS
ENV DRUPAL_PATH=/opt/drupal
# Set the farmOS and composer project repository URLs and versions.
ARG FARMOS_REPO=https://github.com/farmOS/farmOS.git
ARG FARMOS_VERSION=3.x
ARG PROJECT_VERSION=3.x
ARG PROJECT_REPO=https://github.com/farmOS/composer-project/raw/${PROJECT_VERSION}/composer.json
##
# Build PHP extensions, GEOS and bcmath.
FROM baseimage as php-dependencies
# Build and install the GEOS PHP extension.
# See https://git.osgeo.org/gitea/geos/php-geos # See https://git.osgeo.org/gitea/geos/php-geos
ARG PHP_GEOS_VERSION=e77d5a16abbf89a59d947d1fe49381a944762c9d ARG PHP_GEOS_VERSION=e77d5a16abbf89a59d947d1fe49381a944762c9d
ADD https://github.com/libgeos/php-geos/archive/${PHP_GEOS_VERSION}.tar.gz /opt/php-geos.tar.gz ADD https://github.com/libgeos/php-geos/archive/${PHP_GEOS_VERSION}.tar.gz /opt/php-geos.tar.gz
@ -17,51 +30,119 @@ RUN apt-get update && apt-get install -y libgeos-dev \
# Install the BCMath PHP extension. # Install the BCMath PHP extension.
RUN docker-php-ext-install bcmath RUN docker-php-ext-install bcmath
# Inherit from the official Drupal 10 image. ##
FROM drupal:10.1 # Setup dependencies and sources for composer installations.
FROM baseimage as composer-file
# Set the farmOS and composer project repository URLs and versions. # Set the COMPOSER environment variables.
ARG FARMOS_REPO=https://github.com/farmOS/farmOS.git ENV COMPOSER_HOME=tmp \
ARG FARMOS_VERSION=3.x # Set the COMPOSER_MEMORY_LIMIT environment variable to unlimited.
ARG PROJECT_REPO=https://github.com/farmOS/composer-project.git COMPOSER_MEMORY_LIMIT=-1 \
ARG PROJECT_VERSION=3.x # Allow root to install plugins.
COMPOSER_ALLOW_SUPERUSER=1
# Install apt dependencies.
RUN apt-get update && apt-get install -y \
# Install git and unzip (needed by Composer).
git unzip
# Add the build-farmOS.sh script.
COPY build-farmOS.sh /usr/local/bin/
# Setup composer file for non interactive installation.
WORKDIR ${FARMOS_PATH}
RUN build-farmOS.sh
##
# Create layer with farmOS sources.
FROM composer-file as farmos-sources
# Install sources.
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
# Set Apache ServerName directive globally to suppress AH00558 message. # Set Apache ServerName directive globally to suppress AH00558 message.
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# Install and enable geos. # Enable PHP dependencies.
COPY --from=php-dependencies /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/ COPY --from=php-dependencies /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
RUN docker-php-ext-enable geos bcmath RUN docker-php-ext-enable geos bcmath
# Add custom PHP configurations. # Add custom PHP configurations.
COPY conf.d/ /usr/local/etc/php/conf.d COPY conf.d/ /usr/local/etc/php/conf.d
# Install apt dependencies. # Install apt dependencies and clean up.
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
# Install git and unzip (needed by Composer).
git unzip \
# Install postgresql-client so Drush can connect to the database. # Install postgresql-client so Drush can connect to the database.
postgresql-client \ postgresql-client \
# Install libgeos-c1v5 so geos php extension can use libgeos_c.so.1. # Install libgeos-c1v5 so geos php extension can use libgeos_c.so.1.
libgeos-c1v5 \ libgeos-c1v5 \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& apt-get clean && apt-get clean \
# Clean up ${DRUPAL_PATH}.
# Set the COMPOSER_MEMORY_LIMIT environment variable to unlimited. && rm -r ${DRUPAL_PATH} \
ENV COMPOSER_MEMORY_LIMIT=-1 && mkdir ${DRUPAL_PATH}
# 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. # Set the entrypoint.
COPY docker-entrypoint.sh /usr/local/bin/ COPY --chown=www-data docker-entrypoint.sh /usr/local/bin/
# Set the working directory, entrypoint and command.
WORKDIR ${DRUPAL_PATH}
ENTRYPOINT ["docker-entrypoint.sh"] ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"] 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}

35
docker/build-farmOS.sh Normal file → Executable file
View File

@ -2,26 +2,18 @@
set -e set -e
### ###
# This script will build the farmOS codebase in /var/farmOS. # This script will build the farmOS codebase in ${FARMOS_PATH},
# by default it is /var/farmOS.
### ###
# If /var/farmOS is not empty, bail. # If ${FARMOS_PATH} is not empty, bail.
if [ "$(ls -A /var/farmOS/)" ]; then if [ "$(ls -A ${FARMOS_PATH})" ]; then
echo "The ${FARMOS_PATH} is not empty, terminate."
exit 1 exit 1
fi fi
# Make /var/farmOS the working directory. # Fetch composer template
cd /var/farmOS curl -L ${PROJECT_REPO} -o composer.json
# 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
# Create a temporary Composer cache directory.
export COMPOSER_HOME="$(mktemp -d)"
# If FARMOS_VERSION is a valid semantic versioning string, we assume that it is # If FARMOS_VERSION is a valid semantic versioning string, we assume that it is
# a tagged version. # a tagged version.
@ -62,15 +54,4 @@ for plugin in ${allowedPlugins[@]}; do
composer config --no-plugins allow-plugins.$plugin true composer config --no-plugins allow-plugins.$plugin true
done done
# Run composer install with optional arguments passed into this script. mkdir -p ${FARMOS_PATH}/web/sites/simpletest/browser_output
if [ $# -eq 0 ]; then
composer install
else
composer install "$*"
fi
# Set the version in farm.info.yml.
sed -i "s|version: 3.x|version: ${FARMOS_VERSION}|g" /var/farmOS/web/profiles/farm/farm.info.yml
# Remove the Composer cache directory.
rm -rf "$COMPOSER_HOME"

View File

@ -1,63 +0,0 @@
# Inherit from the farmOS 3.x image.
FROM farmos/farmos:3.x
# Set the farmOS and composer project repository URLs and versions.
ARG FARMOS_REPO=https://github.com/farmOS/farmOS.git
ARG FARMOS_VERSION=3.x
ARG PROJECT_REPO=https://github.com/farmOS/composer-project.git
ARG PROJECT_VERSION=3.x
# Install and enable XDebug extension.
RUN yes | pecl install xdebug \
&& docker-php-ext-enable xdebug
# Add opcache revalidation frequency configuration.
COPY conf.d/ /usr/local/etc/php/conf.d
# 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
# Create a fresh /var/farmOS directory owned by www-data.
# We do this in two steps because of a known issue with Moby.
# @see https://github.com/farmOS/farmOS/pull/440
RUN rm -r /var/farmOS
RUN mkdir /var/farmOS && chown www-data:www-data /var/farmOS
# Change to the www-data user.
USER www-data
# Build the farmOS codebase in /var/farmOS.
RUN /usr/local/bin/build-farmOS.sh
# Add Configurartions for PHP CodeSniffer, PHPStan.
COPY --chown=www-data ./files/ /var/farmOS/
# Configure PHPUnit.
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 '/failOnWarning="true"/a \ failOnIncomplete="true"' /var/farmOS/phpunit.xml \
&& sed -i '/failOnWarning="true"/a \ failOnSkipped="true"' /var/farmOS/phpunit.xml \
&& sed -i 's|name="SIMPLETEST_BASE_URL" value=""|name="SIMPLETEST_BASE_URL" value="http://www"|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|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' /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 \
&& sed -i 's| </php>| <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>'"\n"' </php>|g' /var/farmOS/phpunit.xml \
&& mkdir -p /var/farmOS/web/sites/simpletest/browser_output
# Change back to the root user.
USER root
# Copy the farmOS codebase into /opt/drupal.
RUN rm -r /opt/drupal && cp -rp /var/farmOS /opt/drupal
# Create a Composer config directory for the www-data user.
RUN mkdir /var/www/.composer && chown www-data:www-data /var/www/.composer

15
docker/dev/files/phpunit.sh Executable file
View File

@ -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

View File

@ -8,15 +8,15 @@ set -e
### ###
# If the Drupal directory is empty, populate it from pre-built files. # 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." 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 fi
# If the sites directory is empty, populate it from pre-built files. # 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." 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 fi
if [ -n "$FARMOS_FS_READY_SENTINEL_FILENAME" ]; then if [ -n "$FARMOS_FS_READY_SENTINEL_FILENAME" ]; then

View File

@ -17,7 +17,9 @@ Available arguments and their default values are described below:
check out. check out.
- Default: `3.x` - 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 - `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 image. Setting this to the ID of the developer's user on the host machine
@ -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: container. If your user ID is not `1000`, build the image with:
`--build-arg WWW_DATA_ID=$(id -u)` `--build-arg WWW_DATA_ID=$(id -u)`
- Default: `1000` - 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`

View File

@ -104,7 +104,7 @@ class ContentEntityGeometryNormalizer implements NormalizerInterface, Serializer
// Check that the data is a content entity. // Check that the data is a content entity.
// Only formats that are prefixed with "geometry_" are supported. // Only formats that are prefixed with "geometry_" are supported.
// This makes it easier for other modules to provide geometry encoders. // This makes it easier for other modules to provide geometry encoders.
return $data instanceof ContentEntityInterface && strpos($format, 'geometry_') == 0; return $data instanceof ContentEntityInterface && strpos($format, 'geometry_') === 0;
} }
/** /**

View File

@ -18,7 +18,7 @@ function farm_role_roles_oauth2_scope_info_alter(array &$scopes) {
'farm_viewer', 'farm_viewer',
]; ];
foreach ($target_scopes as $scope_id) { foreach ($target_scopes as $scope_id) {
if (isset($target_scopes[$scope_id])) { if (isset($scopes[$scope_id])) {
$scopes[$scope_id]['grant_types']['password'] = [ $scopes[$scope_id]['grant_types']['password'] = [
'status' => TRUE, 'status' => TRUE,
]; ];