From ace9b0e589066b832fbc832ee49b2a2b55eae4a7 Mon Sep 17 00:00:00 2001 From: Dor Date: Mon, 10 Jun 2019 13:31:04 -0700 Subject: [PATCH] Improved upgradability of PHP (#201) * PHP AB#903911 * Improved PHP upgradability with build image * Styling --- build/__php-versions.sh | 2 ++ build/build-buildimages.sh | 4 +++- build/build-constants.yaml | 2 ++ images/build/Dockerfile | 23 ++++++++++++++++------- images/runtime/php/generateDockerfiles.sh | 2 +- src/BuildScriptGenerator/PhpVersions.cs | 2 ++ vsts/pipelines/buildimage-bases.yml | 4 ++-- 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/build/__php-versions.sh b/build/__php-versions.sh index f15209cda4..1a34bdbbbb 100644 --- a/build/__php-versions.sh +++ b/build/__php-versions.sh @@ -1,5 +1,7 @@ # This file was auto-generated from 'build-constants.yaml'. Changes may be overridden. +PHP_BUILD_BASE_TAG='20190530.1' +PHP_RUNTIME_BASE_TAG='20190530.1' COMPOSER_VERSION='1.8.4' COMPOSER_SHA384='48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5' PHP73_VERSION='7.3.5' diff --git a/build/build-buildimages.sh b/build/build-buildimages.sh index 6ad7dd0389..74fd66fd59 100755 --- a/build/build-buildimages.sh +++ b/build/build-buildimages.sh @@ -10,6 +10,7 @@ declare -r REPO_DIR=$( cd $( dirname "$0" ) && cd .. && pwd ) # Load all variables source $REPO_DIR/build/__variables.sh +source $REPO_DIR/build/__php-versions.sh cd "$BUILD_IMAGES_BUILD_CONTEXT_DIR" @@ -61,8 +62,9 @@ BuildAndTagStage buildscriptbuilder builtImageTag="$DOCKER_BUILD_IMAGES_REPO:latest" docker build -t $builtImageTag \ - --build-arg AI_KEY=$APPLICATION_INSIGHTS_INSTRUMENTATION_KEY \ --build-arg AGENTBUILD=$BUILD_SIGNED \ + --build-arg PHP_BUILD_BASE_TAG=$PHP_BUILD_BASE_TAG \ + --build-arg AI_KEY=$APPLICATION_INSIGHTS_INSTRUMENTATION_KEY \ $ctxArgs -f "$BUILD_IMAGES_DOCKERFILE" . echo diff --git a/build/build-constants.yaml b/build/build-constants.yaml index a70cf0b928..77dcf4041b 100644 --- a/build/build-constants.yaml +++ b/build/build-constants.yaml @@ -61,6 +61,8 @@ file-name-prefix: __ - name: php-versions constants: + php-build-base-tag: 20190530.1 + php-runtime-base-tag: 20190530.1 composer-version: 1.8.4 composer-sha384: 48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5 php73-version: 7.3.5 diff --git a/images/build/Dockerfile b/images/build/Dockerfile index 70e5626cfa..98d71a0c5c 100644 --- a/images/build/Dockerfile +++ b/images/build/Dockerfile @@ -1,7 +1,8 @@ -# Start declaration of Build-Arg to determine where the image is getting built (devops agents or local) +# Start declaration of Build-Arg to determine where the image is getting built (DevOps agents or local) ARG AGENTBUILD +ARG PHP_BUILD_BASE_TAG FROM buildpack-deps:stretch AS main -# End declaration of Build-Arg to determine where the image is getting built (devops agents or local) +# End declaration of Build-Arg to determine where the image is getting built (DevOps agents or local) # Configure locale (required for Python) # NOTE: Do NOT move it from here as it could have global implications @@ -319,6 +320,12 @@ RUN if [ -z "$AGENTBUILD" ]; then \ fi RUN chmod a+x /opt/buildscriptgen/GenerateBuildScript +# Docker doesn't support variables in --from, so we're using an intermediate stage +FROM mcr.microsoft.com/oryx/php-build-base:5.6-${PHP_BUILD_BASE_TAG} AS php56-build-base +FROM mcr.microsoft.com/oryx/php-build-base:7.0-${PHP_BUILD_BASE_TAG} AS php70-build-base +FROM mcr.microsoft.com/oryx/php-build-base:7.2-${PHP_BUILD_BASE_TAG} AS php72-build-base +FROM mcr.microsoft.com/oryx/php-build-base:7.3-${PHP_BUILD_BASE_TAG} AS php73-build-base + ### # Build run script generators (to be used by the `oryx run-script` command) ### @@ -365,16 +372,18 @@ COPY --from=mcr.microsoft.com/oryx/build-yarn-cache:20190326.8 /usr/local/share/ # Copy PHP versions COPY images/build/php/prereqs/install-prereqs.sh /tmp/php/install-prereqs.sh RUN . /tmp/php/install-prereqs.sh -COPY --from=mcr.microsoft.com/oryx/php-build-base:5.6-20190530.1 /opt /opt -COPY --from=mcr.microsoft.com/oryx/php-build-base:7.0-20190530.1 /opt /opt -COPY --from=mcr.microsoft.com/oryx/php-build-base:7.2-20190530.1 /opt /opt -COPY --from=mcr.microsoft.com/oryx/php-build-base:7.3-20190530.1 /opt /opt + +COPY --from=php56-build-base /opt /opt +COPY --from=php70-build-base /opt /opt +COPY --from=php72-build-base /opt /opt +COPY --from=php73-build-base /opt /opt + RUN ln -s /opt/php/5.6 /opt/php/5 \ && ln -s /opt/php/7.3 /opt/php/7 \ && ln -s /opt/php/7 /opt/php/lts \ && ln -s /opt/php/lts/bin/php /usr/local/bin/php -# Build script generator content, currently docker doesn't support variables in --from +# Build script generator content. Docker doesn't support variables in --from # so we are building an extra stage to copy binaries from correct build stage COPY --from=buildscriptbuilder /opt/buildscriptgen/ /opt/buildscriptgen/ RUN ln -s /opt/buildscriptgen/GenerateBuildScript /usr/local/bin/oryx diff --git a/images/runtime/php/generateDockerfiles.sh b/images/runtime/php/generateDockerfiles.sh index 6236f2956a..872c7c98c9 100755 --- a/images/runtime/php/generateDockerfiles.sh +++ b/images/runtime/php/generateDockerfiles.sh @@ -33,6 +33,6 @@ do sed -i "s|$IMAGE_NAME_PLACEHOLDER|$PHP_IMAGE_NAME|g" "$TARGET_DOCKERFILE_BASE" sed -i "s|$PHP_VERSION_PLACEHOLDER|$PHP_VERSION|g" "$TARGET_DOCKERFILE_BASE" - RUNTIME_BASE_IMAGE_NAME="mcr.microsoft.com/oryx/php-base:$VERSION_DIRECTORY-20190530.1" + RUNTIME_BASE_IMAGE_NAME="mcr.microsoft.com/oryx/php-base:$VERSION_DIRECTORY-$PHP_RUNTIME_BASE_TAG" sed -i "s|$RUNTIME_BASE_IMAGE_NAME_PLACEHOLDER|$RUNTIME_BASE_IMAGE_NAME|g" "$TARGET_DOCKERFILE" done diff --git a/src/BuildScriptGenerator/PhpVersions.cs b/src/BuildScriptGenerator/PhpVersions.cs index c1a7f31981..f9a6fa56e4 100644 --- a/src/BuildScriptGenerator/PhpVersions.cs +++ b/src/BuildScriptGenerator/PhpVersions.cs @@ -4,6 +4,8 @@ namespace Microsoft.Oryx.Common { public static class PhpVersions { + public const string PhpBuildBaseTag = "20190530.1"; + public const string PhpRuntimeBaseTag = "20190530.1"; public const string ComposerVersion = "1.8.4"; public const string ComposerSha384 = "48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5"; public const string Php73Version = "7.3.5"; diff --git a/vsts/pipelines/buildimage-bases.yml b/vsts/pipelines/buildimage-bases.yml index ba2c50e493..1eecf76656 100644 --- a/vsts/pipelines/buildimage-bases.yml +++ b/vsts/pipelines/buildimage-bases.yml @@ -20,14 +20,14 @@ jobs: - template: templates/_buildimage-bases.job-template.yml parameters: - displayName: Build and push PHP base images for build + displayName: Build and push PHP build base images scriptPath: ./build/build-buildimage-bases.sh imageDir: php artifactsFileName: php-buildimage-bases.txt - template: templates/_buildimage-bases.job-template.yml parameters: - displayName: Build and push PHP base images for runtime + displayName: Build and push PHP runtime base images scriptPath: ./build/build-runtimeimages-bases.sh imageDir: php artifactsFileName: php-runtimeimage-bases.txt