Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Customizable composer flags (#368)
Browse files Browse the repository at this point in the history
* Customizable composer flags

* Use the correct option `--no-scripts` for composer install

* Fixed the tests for the Runtime Builder
  • Loading branch information
Takashi Matsuo authored Sep 15, 2017
1 parent f12ea29 commit e007dae
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 50 deletions.
6 changes: 4 additions & 2 deletions builder/gen-dockerfile/src/Builder/GenFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ protected function envsFromRuntimeConfig()
: [];
$maps = [
'builder_debug_output' => 'BUILDER_DEBUG_OUTPUT',
'composer_flags' => 'COMPOSER_FLAGS',
'document_root' => 'DOCUMENT_ROOT',
'enable_stackdriver_integration' => self::STACKDRIVER_INTEGRATION_ENV,
'front_controller_file' => 'FRONT_CONTROLLER_FILE',
Expand Down Expand Up @@ -250,7 +251,8 @@ public function createDockerfile($baseImage)
+ $this->envsFromAppYaml()
+ [
'FRONT_CONTROLLER_FILE' => self::DEFAULT_FRONT_CONTROLLER_FILE,
'GOOGLE_RUNTIME_RUN_COMPOSER_SCRIPT' => 'true',
// default composer flags for the runtime builder
'COMPOSER_FLAGS' => '--no-dev --prefer-dist',
'DETECTED_PHP_VERSION' => $this->detectedPhpVersion
];
// Fail if DOCUMENT_ROOT is not set.
Expand All @@ -275,7 +277,7 @@ public function createDockerfile($baseImage)
}
$envString = 'ENV ';
foreach ($envs as $key => $value) {
$envString .= "$key=$value \\\n";
$envString .= "$key='$value' \\\n";
}
// Remove the last new line and the backslash
$envString = rtrim($envString, "\n");
Expand Down
2 changes: 1 addition & 1 deletion builder/gen-dockerfile/src/templates/Dockerfile.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

FROM {{ base_image }}

{{ env_string }}
{{ env_string|raw }}

ARG BUILDER_PROJECT_ID
ENV GCLOUD_PROJECT ${BUILDER_PROJECT_ID}
Expand Down
74 changes: 37 additions & 37 deletions builder/gen-dockerfile/tests/GenFilesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testGenFilesCommand(
$dockerfile = file_get_contents(self::$testDir . '/Dockerfile');
$this->assertTrue($dockerfile !== false, 'Dockerfile should exist');
$this->assertContains(
'DOCUMENT_ROOT=' . $expectedDocRoot,
"DOCUMENT_ROOT='$expectedDocRoot'",
$dockerfile
);
$this->assertContains('FROM ' . $expectedFrom, $dockerfile);
Expand Down Expand Up @@ -134,9 +134,9 @@ public function dataProvider()
'/app',
'added by the php runtime builder',
'gcr.io/google-appengine/php71:latest',
["GOOGLE_RUNTIME_RUN_COMPOSER_SCRIPT=true \\\n",
"FRONT_CONTROLLER_FILE=index.php \\\n",
"DETECTED_PHP_VERSION=7.1 \n"
["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n",
"FRONT_CONTROLLER_FILE='index.php' \\\n",
"DETECTED_PHP_VERSION='7.1' \n"
]
],
[
Expand All @@ -158,10 +158,10 @@ public function dataProvider()
'/app/web',
'added by the php runtime builder',
'gcr.io/google-appengine/php71:latest',
["GOOGLE_RUNTIME_RUN_COMPOSER_SCRIPT=true \\\n",
"FRONT_CONTROLLER_FILE=index.php \\\n",
"DETECTED_PHP_VERSION=7.1 \\\n",
"IS_BATCH_DAEMON_RUNNING=true \n",
["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n",
"FRONT_CONTROLLER_FILE='index.php' \\\n",
"DETECTED_PHP_VERSION='7.1' \\\n",
"IS_BATCH_DAEMON_RUNNING='true' \n",
"enable_stackdriver_integration.sh"
]
],
Expand All @@ -173,10 +173,10 @@ public function dataProvider()
'/app/web',
'added by the php runtime builder',
'gcr.io/google-appengine/php71:latest',
["GOOGLE_RUNTIME_RUN_COMPOSER_SCRIPT=true \\\n",
"FRONT_CONTROLLER_FILE=index.php \\\n",
"DETECTED_PHP_VERSION=7.1 \\\n",
"IS_BATCH_DAEMON_RUNNING=true \n",
["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n",
"FRONT_CONTROLLER_FILE='index.php' \\\n",
"DETECTED_PHP_VERSION='7.1' \\\n",
"IS_BATCH_DAEMON_RUNNING='true' \n",
"enable_stackdriver_integration.sh --individual"
]
],
Expand Down Expand Up @@ -243,9 +243,9 @@ public function dataProvider()
'/app',
'added by the php runtime builder',
'gcr.io/google-appengine/php56:latest',
["GOOGLE_RUNTIME_RUN_COMPOSER_SCRIPT=true \\\n",
"FRONT_CONTROLLER_FILE=index.php \\\n",
"DETECTED_PHP_VERSION=5.6 \n"
["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n",
"FRONT_CONTROLLER_FILE='index.php' \\\n",
"DETECTED_PHP_VERSION='5.6' \n"
]
],
[
Expand All @@ -256,9 +256,9 @@ public function dataProvider()
'/app',
'added by the php runtime builder',
'gcr.io/google-appengine/php70:latest',
["GOOGLE_RUNTIME_RUN_COMPOSER_SCRIPT=true \\\n",
"FRONT_CONTROLLER_FILE=index.php \\\n",
"DETECTED_PHP_VERSION=7.0 \n"
["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n",
"FRONT_CONTROLLER_FILE='index.php' \\\n",
"DETECTED_PHP_VERSION='7.0' \n"
]
],
[
Expand All @@ -270,15 +270,15 @@ public function dataProvider()
'added by the php runtime builder',
'gcr.io/google-appengine/php71:latest',
[
"WHITELIST_FUNCTIONS=exec \\\n",
"FRONT_CONTROLLER_FILE=app.php",
"NGINX_CONF_HTTP_INCLUDE=files/nginx-http.conf",
"NGINX_CONF_INCLUDE=files/nginx-app.conf",
"NGINX_CONF_OVERRIDE=files/nginx.conf",
"PHP_FPM_CONF_OVERRIDE=files/php-fpm.conf",
"PHP_INI_OVERRIDE=files/php.ini",
"SUPERVISORD_CONF_ADDITION=files/additional-supervisord.conf",
"SUPERVISORD_CONF_OVERRIDE=files/supervisord.conf"
"WHITELIST_FUNCTIONS='exec' \\\n",
"FRONT_CONTROLLER_FILE='app.php'",
"NGINX_CONF_HTTP_INCLUDE='files/nginx-http.conf'",
"NGINX_CONF_INCLUDE='files/nginx-app.conf'",
"NGINX_CONF_OVERRIDE='files/nginx.conf'",
"PHP_FPM_CONF_OVERRIDE='files/php-fpm.conf'",
"PHP_INI_OVERRIDE='files/php.ini'",
"SUPERVISORD_CONF_ADDITION='files/additional-supervisord.conf'",
"SUPERVISORD_CONF_OVERRIDE='files/supervisord.conf'"
]
],
[
Expand All @@ -301,15 +301,15 @@ public function dataProvider()
'added by the php runtime builder',
'gcr.io/google-appengine/php71:latest',
[
"WHITELIST_FUNCTIONS=exec \\\n",
"FRONT_CONTROLLER_FILE=app.php",
"NGINX_CONF_HTTP_INCLUDE=files/nginx-http.conf",
"NGINX_CONF_INCLUDE=files/nginx-app.conf",
"NGINX_CONF_OVERRIDE=files/nginx.conf",
"PHP_FPM_CONF_OVERRIDE=files/php-fpm.conf",
"PHP_INI_OVERRIDE=files/php.ini",
"SUPERVISORD_CONF_ADDITION=files/additional-supervisord.conf",
"SUPERVISORD_CONF_OVERRIDE=files/supervisord.conf"
"WHITELIST_FUNCTIONS='exec' \\\n",
"FRONT_CONTROLLER_FILE='app.php'",
"NGINX_CONF_HTTP_INCLUDE='files/nginx-http.conf'",
"NGINX_CONF_INCLUDE='files/nginx-app.conf'",
"NGINX_CONF_OVERRIDE='files/nginx.conf'",
"PHP_FPM_CONF_OVERRIDE='files/php-fpm.conf'",
"PHP_INI_OVERRIDE='files/php.ini'",
"SUPERVISORD_CONF_ADDITION='files/additional-supervisord.conf'",
"SUPERVISORD_CONF_OVERRIDE='files/supervisord.conf'"
],
'\\Google\\Cloud\\Runtimes\\Builder\\Exception\\EnvConflictException'
],
Expand All @@ -321,7 +321,7 @@ public function dataProvider()
'/app',
'added by the php runtime builder',
'gcr.io/google-appengine/php71:latest',
["FRONT_CONTROLLER_FILE=app.php \\\n"]
["FRONT_CONTROLLER_FILE='app.php' \\\n"]
],
[
// Different yaml path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM gcr.io/google_appengine/debian

ENV DOCUMENT_ROOT=/test
ENV DOCUMENT_ROOT='/test'
13 changes: 5 additions & 8 deletions php-base/build-scripts/composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,15 @@ EOF

echo "Running composer..."
# Run Composer.
if [ -n "${GOOGLE_RUNTIME_RUN_COMPOSER_SCRIPT}" ]; then
NOSCRIPT=''
else
NOSCRIPT='--no-scripts'
if [ -z "${COMPOSER_FLAGS}" ]; then
COMPOSER_FLAGS='--no-scripts --no-dev --prefer-dist'
fi
cd ${APP_DIR} && \
su -m www-data -c "php -d auto_prepend_file='' /usr/local/bin/composer \
install ${NOSCRIPT} \
--no-dev \
--prefer-dist \
install \
--optimize-autoloader \
--no-interaction \
--no-ansi \
--no-progress"
--no-progress \
${COMPOSER_FLAGS}"
fi
4 changes: 4 additions & 0 deletions php-onbuild/Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

FROM ${PHP_71_IMAGE}

# Allow customizing some composer flags
ONBUILD ARG COMPOSER_FLAGS='--no-scripts --no-dev --prefer-dist'
ONBUILD ENV COMPOSER_FLAGS=${COMPOSER_FLAGS}

# Copy the app and change the owner
ONBUILD COPY . $APP_DIR
ONBUILD RUN chown -R www-data.www-data $APP_DIR
Expand Down
2 changes: 1 addition & 1 deletion testapps/builder_test/tests/DockerfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function testDockerfile()
{
$dockerfile = file_get_contents('/workspace/Dockerfile');
$this->assertTrue($dockerfile !== false);
$this->assertContains('DOCUMENT_ROOT=/app/web', $dockerfile);
$this->assertContains("DOCUMENT_ROOT='/app/web'", $dockerfile);
}
}

0 comments on commit e007dae

Please sign in to comment.