diff --git a/.dockerignore.default b/.dockerignore.default index 7263346bf..19db8e938 100644 --- a/.dockerignore.default +++ b/.dockerignore.default @@ -1,4 +1,5 @@ .git* +**/.git .idea .DS_Store node_modules diff --git a/bin/command/build/baked/build.sh b/bin/command/build/baked/build.sh index 28754a4be..1839a04cb 100644 --- a/bin/command/build/baked/build.sh +++ b/bin/command/build/baked/build.sh @@ -13,18 +13,15 @@ function Command::build() { subCommand=${1} case ${subCommand} in images | image) - Images::buildApplication --force - Assets::build - Images::buildFrontend --force + Images::build --force ;; assets | asset) + Images::build --force Assets::build --force - Images::buildFrontend --force ;; '') - Images::buildApplication --force + Images::build --force Assets::build --force - Images::buildFrontend --force ;; *) Console::error "Unknown build target '${subCommand}' is occurred. No action." >&2 diff --git a/bin/command/build/baked/export.sh b/bin/command/build/baked/export.sh index fafe5d109..f522d635d 100644 --- a/bin/command/build/baked/export.sh +++ b/bin/command/build/baked/export.sh @@ -2,7 +2,7 @@ Registry::addCommand "export" "Command::export" -Registry::Help::command -c "export images" -a "[-t ]" "Builds prod-like images (Yves, Zed, Glue, Frontend)." +Registry::Help::command -c "export images" -a "[-t ] [-d ecr]" "Builds prod-like images (Yves, Zed, Glue, Frontend)." Registry::Help::command -c "export assets" -a "[-t ] [-p ]" "[DEPRECATED] Builds assets and export as archives stored by given path." function _assertDestinationDirectory() { @@ -13,10 +13,12 @@ function _assertDestinationDirectory() { } function Command::export() { + local OPTIND=0 + local opt local subCommand='' local tag=${SPRYKER_DOCKER_TAG} local destinationPath='./' - local pushDestination='' + local pushDestination='print' subCommand=${1} shift || true @@ -32,14 +34,6 @@ function Command::export() { ;; d) pushDestination=${OPTARG} - local pushDestinationPath="sdk/images/baked/${pushDestination}.sh" - local pathToFile="${DEPLOYMENT_PATH}/bin/${pushDestinationPath}" - if [ ! -f "${pathToFile}" ]; then - Console::error "\nUnknown export images destination - '${OPTARG}'." - exit 1 - fi - - import ${pushDestinationPath} ;; # Unknown option specified \?) @@ -60,33 +54,27 @@ function Command::export() { done shift $((OPTIND - 1)) + local pushDestinationPath="sdk/images/destination/${pushDestination}.sh" + if [ ! -f "${DEPLOYMENT_PATH}/bin/${pushDestinationPath}" ]; then + Console::error "\nUnknown export images destination - '${pushDestination}'." + exit 1 + fi + + import ${pushDestinationPath} + case ${subCommand} in asset | assets) - Console::warn 'This command is DEPRECATED. Please, use just "export".' + Console::warn 'This command is DEPRECATED. Please, use just "export images".' _assertDestinationDirectory "${destinationPath}" - Images::buildApplication --force - Assets::build --force - Images::buildFrontend --force - Assets::export "${tag}" "${destinationPath}" + Images::export "${tag}" "print" + Assets::export "${tag}" "print" "${destinationPath}" ;; image | images) - Console::verbose "${INFO}Build and export images${NC}" - Images::buildApplication --force - Images::tagApplications "${tag}" - Assets::build --force - Images::buildFrontend --force - Images::tagFrontend "${tag}" - - if [ -n "${pushDestination}" ]; then - Images::push "${tag}" - fi - - if [ -z "${pushDestination}" ]; then - Images::printAll "${tag}" - fi + Images::export "${tag}" "${pushDestination}" + Images::print "${tag}" "${pushDestination}" ;; *) - Console::error "Unknown export '${subCommand}' is occurred. No action. Usage: ${HELP_SCR}${SELF_SCRIPT} export images [-t ]" >&2 + Console::error "Unknown export '${subCommand}' is occurred. No action. Usage: ${HELP_SCR}${SELF_SCRIPT} export images [-t ] [-d ecr]" >&2 exit 1 ;; esac diff --git a/bin/command/build/mount/build.sh b/bin/command/build/mount/build.sh index e37686ce5..4d3d99a61 100644 --- a/bin/command/build/mount/build.sh +++ b/bin/command/build/mount/build.sh @@ -11,23 +11,18 @@ function Command::build() { subCommand=${1} case ${subCommand} in images | image) - Images::buildApplication --force - Codebase::build - Assets::build - Images::buildFrontend --force + Images::build --force ;; codebase | code) Codebase::build --force ;; assets | asset) Assets::build --force - Images::buildFrontend --force ;; '') - Images::buildApplication --force + Images::build --force Codebase::build --force Assets::build --force - Images::buildFrontend --force ;; *) Console::error "Unknown build target '${subCommand}' is occurred. No action." >&2 diff --git a/bin/command/install/bootstrap.sh b/bin/command/install/bootstrap.sh index d6bc1d208..1fb64a346 100644 --- a/bin/command/install/bootstrap.sh +++ b/bin/command/install/bootstrap.sh @@ -13,6 +13,8 @@ Registry::Help::command -s -c "bootstrap | boot" -a "[-v] " "P Registry::Help::command -s -c "bootstrap | boot" -a "[-v]" "Prepares all the files to run the application based on ${HELP_HIGH}deploy.local.yml${HELP_DESC} or ${HELP_HIGH}deploy.yml${HELP_DESC}." function Command::bootstrap() { + local OPTIND=0 + local opt while getopts ":vsx" opt; do case ${opt} in @@ -42,6 +44,7 @@ function Command::bootstrap() { shift $((OPTIND - 1)) local gitHash=$(git rev-parse --verify HEAD 2>/dev/null || true) + local SPRYKER_SDK_REVISION="$(cd ${SOURCE_DIR} && git rev-parse --short HEAD 2>/dev/null || echo '')" local tmpDeploymentDir="${SOURCE_DIR}/deployment/_tmp" local defaultProjectYaml=$([ -f "./deploy.local.yml" ] && echo -n "./deploy.local.yml" || echo -n "./deploy.yml") local projectYaml=${1:-${defaultProjectYaml}} @@ -75,11 +78,12 @@ function Command::bootstrap() { Console::info "Using ${projectYaml}" local USER_FULL_ID=$(Environment::getFullUserId) + local USER_UID="${USER_FULL_ID%%:*}" Console::verbose::start "Building generator..." docker build -t spryker_docker_sdk \ -f "${SOURCE_DIR}/generator/Dockerfile" \ - --build-arg="USER_UID=${USER_FULL_ID%%:*}" \ + --build-arg="USER_UID=${USER_UID}" \ -q \ "${SOURCE_DIR}/generator" >/dev/null Console::end "[DONE]" @@ -103,12 +107,13 @@ function Command::bootstrap() { # To support root user local userToRun=("-u" "${USER_FULL_ID}") - if [ "${USER_FULL_ID%%:*}" != '0' ]; then + if [ "${USER_UID}" != '0' ]; then userToRun=() fi docker run -i --rm "${userToRun[@]}" \ -e SPRYKER_PLATFORM_IMAGE="${SPRYKER_PLATFORM_IMAGE:-""}" \ -e SPRYKER_DOCKER_SDK_PLATFORM="${_PLATFORM}" \ + -e SPRYKER_SDK_REVISION="${SPRYKER_SDK_REVISION}" \ -e SPRYKER_DOCKER_SDK_DEPLOYMENT_DIR="${DESTINATION_DIR}" \ -e VERBOSE="${VERBOSE}" \ -v "${tmpDeploymentDir}":/data/deployment:rw \ diff --git a/bin/command/install/config.sh b/bin/command/install/config.sh index e34738968..87d512f1b 100644 --- a/bin/command/install/config.sh +++ b/bin/command/install/config.sh @@ -23,11 +23,12 @@ function Command::config() { Console::info "Using ${projectYaml}" local USER_FULL_ID=$(Environment::getFullUserId) + local USER_UID="${USER_FULL_ID%%:*}" Console::verbose::start "Building generator..." docker build -t spryker_docker_sdk \ -f "${SOURCE_DIR}/generator/deploy-file-generator/Dockerfile" \ - --build-arg="USER_UID=${USER_FULL_ID%%:*}" \ + --build-arg="USER_UID=${USER_UID}" \ -q \ "${SOURCE_DIR}/generator" >/dev/null @@ -42,7 +43,7 @@ function Command::config() { # To support root user local userToRun=("-u" "${USER_FULL_ID}") - if [ "${USER_FULL_ID%%:*}" != '0' ]; then + if [ "${USER_UID}" != '0' ]; then userToRun=() fi docker run -i --rm "${userToRun[@]}" \ diff --git a/bin/environment/docker.sh b/bin/environment/docker.sh index 020e064a0..c0343f2ad 100644 --- a/bin/environment/docker.sh +++ b/bin/environment/docker.sh @@ -3,7 +3,7 @@ export DOCKER_BUILDKIT=1 require docker tr -require:linux ip grep awk +require:linux grep awk require:macos ipconfig require:windows tail cut @@ -87,7 +87,11 @@ function Environment::getHostIp() { case ${_PLATFORM} in linux) if ! Environment::isWSL; then - myIp=$(ip route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q') + if command -v ip &> /dev/null; then + myIp=$(ip route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q') + else + myIp=$(hostname -i | awk '{ print $1 }') + fi fi ;; macos) diff --git a/bin/registry/help.sh b/bin/registry/help.sh index 1c375a9fe..b39da7088 100644 --- a/bin/registry/help.sh +++ b/bin/registry/help.sh @@ -19,6 +19,7 @@ function Registry::Help::separator() { function Registry::Help::command() { local OPTIND=0 + local opt local OPTARG='' local OPTERR='' local envs='' diff --git a/bin/sdk/assets/baked.sh b/bin/sdk/assets/baked.sh index 7005ef6a4..8de068646 100755 --- a/bin/sdk/assets/baked.sh +++ b/bin/sdk/assets/baked.sh @@ -2,10 +2,11 @@ function Assets::export() { # deprecated - local tag=${1} - local destinationPath=${2%/} + local TARGET_TAG=${1:-${SPRYKER_DOCKER_TAG}} + local destination=${2} + local destinationPath=${3%/} - local builderAssetsImage=$(Assets::getImageTag) + local builderAssetsImage local dockerAssetsTmpDirectory="/_tmp" local projectDockerAssetsTmpDirectory=${DEPLOYMENT_DIR}${dockerAssetsTmpDirectory} @@ -19,6 +20,18 @@ function Assets::export() { Console::start "Preparing assets archives..." + source ${DEPLOYMENT_PATH}/images/export/${destination}.sh + + local targetData + for targetData in "${TARGET_TAGS[@]}"; do + eval "${targetData}" + + if [ "$TARGET" == 'frontend' ]; then + builderAssetsImage="${TAGS[0]}" + break + fi + done + # To support root user local userToRun=("-u" "${USER_FULL_ID}") if [ "${USER_FULL_ID%%:*}" != '0' ]; then @@ -29,7 +42,7 @@ function Assets::export() { -v "${DEPLOYMENT_DIR}/bin:/data/standalone" \ -v "${projectDockerAssetsTmpDirectory}:/data${dockerAssetsTmpDirectory}" \ --entrypoint='' \ - --name="${SPRYKER_DOCKER_PREFIX}_builder_assets" \ + --name="${SPRYKER_DOCKER_PREFIX}_frontend" \ "${builderAssetsImage}" \ sh -c "${command}" 2>&1 @@ -50,58 +63,12 @@ function Assets::export() { rm -rf "${projectDockerAssetsTmpDirectory}" } -function Assets::getImageTag() { - echo -n "${SPRYKER_DOCKER_PREFIX}_builder_assets:${SPRYKER_DOCKER_TAG}-${SPRYKER_REPOSITORY_HASH}" -} - function Assets::areBuilt() { - Console::start "Checking assets are built..." - - local builderAssetsImage=$(Assets::getImageTag) - - if docker image inspect "${builderAssetsImage}" >/dev/null 2>&1; then - Console::end "[BUILT]" - return "${TRUE}" - fi - - return "${FALSE}" + # Do nothing as everything is built before. Could be changed once assets are separated + : } function Assets::build() { - - local force='' - if [ "$1" == '--force' ]; then - force=1 - shift || true - fi - - if [ -z "${force}" ] && Assets::areBuilt; then - return "${TRUE}" - fi - - Console::start "Cleaning old assets..." - - # ${XARGS_NO_RUN_IF_EMPTY} must be without quotes - # shellcheck disable=SC2086 - docker images --filter "reference=${SPRYKER_DOCKER_PREFIX}_builder_assets:${SPRYKER_DOCKER_TAG}*" --format "{{.ID}}" | xargs ${XARGS_NO_RUN_IF_EMPTY} docker rmi -f - - Console::end "[DONE]" - Console::start "Building assets..." - - local builderAssetsImage=$(Assets::getImageTag) - local cliImage="${SPRYKER_DOCKER_PREFIX}_cli:${SPRYKER_DOCKER_TAG}" - local mode=${SPRYKER_ASSETS_MODE:-development} - - docker build \ - -t "${builderAssetsImage}" \ - -f "${DEPLOYMENT_PATH}/images/baked/assets/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${cliImage}" \ - --build-arg "SPRYKER_ASSETS_MODE=${mode}" \ - --build-arg "SPRYKER_PIPELINE=${SPRYKER_PIPELINE}" \ - --build-arg "SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH:-"current"}" \ - --build-arg "SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP:-""}" \ - . 1>&2 - - Console::end "[DONE]" + # Do nothing as everything is built before. Could be changed once assets are separated + : } diff --git a/bin/sdk/assets/mount.sh b/bin/sdk/assets/mount.sh index 439567e0b..c9f512d1a 100644 --- a/bin/sdk/assets/mount.sh +++ b/bin/sdk/assets/mount.sh @@ -6,10 +6,6 @@ function Assets::export() { return "${FALSE}" } -function Assets::getImageTag() { - echo -n "${SPRYKER_DOCKER_PREFIX}_cli:${SPRYKER_DOCKER_TAG}" -} - function Assets::areBuilt() { Console::start "Checking assets are built..." diff --git a/bin/sdk/compose.sh b/bin/sdk/compose.sh index b972a182d..d058a3244 100644 --- a/bin/sdk/compose.sh +++ b/bin/sdk/compose.sh @@ -141,10 +141,9 @@ function Compose::up() { Compose::cleanSourceDirectory fi - Images::buildApplication ${noCache} ${doBuild} + Images::build ${noCache} ${doBuild} Codebase::build ${noCache} ${doBuild} Assets::build ${noCache} ${doAssets} - Images::buildFrontend ${noCache} ${doBuild} Compose::run --build Compose::command restart frontend gateway diff --git a/bin/sdk/images/baked.sh b/bin/sdk/images/baked.sh index a38ac6488..e61571697 100644 --- a/bin/sdk/images/baked.sh +++ b/bin/sdk/images/baked.sh @@ -2,7 +2,7 @@ import sdk/images/common.sh -function Images::buildApplication() { +function Images::build() { for arg in "${@}"; do case "${arg}" in '--force') @@ -12,31 +12,14 @@ function Images::buildApplication() { # TODO implement --no-cache for build images ;; *) - Console::verbose "\nUnknown option ${INFO}${arg}${WARN} is acquired for Images::buildApplication." + Console::verbose "\nUnknown option ${INFO}${arg}${WARN} is acquired for Images::build." ;; esac done - Images::_buildApp baked - Images::tagApplications "${SPRYKER_DOCKER_TAG}" + Images::_build baked } -function Images::buildFrontend() { - for arg in "${@}"; do - case "${arg}" in - '--force') - # it is always it. - ;; - '--no-cache') - # TODO implement --no-cache for build images - ;; - *) - Console::verbose "\nUnknown option ${INFO}${arg}${WARN} is acquired for Images::buildFrontend." - ;; - esac - done - - Images::_buildFrontend baked - Images::_buildGateway - Images::tagFrontend "${SPRYKER_DOCKER_TAG}" +function Images::export() { + Images::_build export "${@}" } diff --git a/bin/sdk/images/baked/ecr.sh b/bin/sdk/images/baked/ecr.sh deleted file mode 100644 index 7931bfc83..000000000 --- a/bin/sdk/images/baked/ecr.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -import sdk/images/baked.sh - -function Images::buildApplication() { - Console::verbose "${INFO}Building application images for AWS ECR${NC}" - - Images::_buildApp baked "${TRUE}" -} - -function Images::buildFrontend() { - Console::verbose "${INFO}Building Frontend image for AWS ECR${NC}" - - Images::_buildFrontend baked - Images::_buildGateway -} - -function Images::tagApplications() { - local tag=${1:-${SPRYKER_DOCKER_TAG}} - - Console::verbose "${INFO}Tag images for AWS ECR${NC}" - for application in "${SPRYKER_APPLICATIONS[@]}"; do - local application="$(echo "$application" | tr '[:upper:]' '[:lower:]')" - docker tag "${SPRYKER_DOCKER_PREFIX}_app:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-${application}:${tag}" - docker tag "${SPRYKER_DOCKER_PREFIX}_app:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-${application}:latest" - done - - docker tag "${SPRYKER_DOCKER_PREFIX}_jenkins:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-jenkins:${tag}" - docker tag "${SPRYKER_DOCKER_PREFIX}_jenkins:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-jenkins:latest" - docker tag "${SPRYKER_DOCKER_PREFIX}_pipeline:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-pipeline:${tag}" - docker tag "${SPRYKER_DOCKER_PREFIX}_pipeline:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-pipeline:latest" -} - -function Images::tagFrontend() { - Console::verbose "${INFO}Tagging Frontend for AWS ECR${NC}" - - local tag=${1:-${SPRYKER_DOCKER_TAG}} - - docker tag "${SPRYKER_DOCKER_PREFIX}_frontend:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-frontend:${tag}" - docker tag "${SPRYKER_DOCKER_PREFIX}_frontend:${SPRYKER_DOCKER_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-frontend:latest" - -} - -function Images::push() { - Console::verbose "${INFO}Pushing images to AWS ECR${NC}" - local tag=${1:-${SPRYKER_DOCKER_TAG}} - - docker images | grep ecr - for application in "${SPRYKER_APPLICATIONS[@]}"; do - local application="$(echo "$application" | tr '[:upper:]' '[:lower:]')" - echo "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-${application}:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-${application}:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-${application}:latest" - done - echo "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-frontend:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-frontend:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-frontend:latest" - echo "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-jenkins:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-jenkins:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-jenkins:latest" - echo "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-pipeline:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-pipeline:${tag}" - docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${SPRYKER_PROJECT_NAME}-pipeline:latest" -} diff --git a/bin/sdk/images/common.sh b/bin/sdk/images/common.sh index 78226c887..6e4736b08 100644 --- a/bin/sdk/images/common.sh +++ b/bin/sdk/images/common.sh @@ -2,6 +2,8 @@ require docker +import sdk/images/destination/print.sh + function Images::pull() { docker pull "${SPRYKER_PLATFORM_IMAGE}" || true } @@ -11,232 +13,63 @@ function Images::destroy() { # ${XARGS_NO_RUN_IF_EMPTY} must be without quotes # shellcheck disable=SC2086 - docker images --filter "reference=${SPRYKER_DOCKER_PREFIX}_*:${SPRYKER_DOCKER_TAG}" --format "{{.ID}}" | xargs ${XARGS_NO_RUN_IF_EMPTY} docker rmi -f - docker images --filter "reference=${SPRYKER_DOCKER_PREFIX}_builder_assets*" --format "{{.ID}}" | xargs ${XARGS_NO_RUN_IF_EMPTY} docker rmi -f - docker images --filter "reference=spryker_docker_sdk*" --format "{{.ID}}" | xargs ${XARGS_NO_RUN_IF_EMPTY} docker rmi -f - - docker rmi -f "${SPRYKER_DOCKER_PREFIX}_cli" || true - docker rmi -f "${SPRYKER_DOCKER_PREFIX}_app" || true - docker rmi -f "${SPRYKER_PLATFORM_IMAGE}" || true + docker images --filter "label=spryker.project=${SPRYKER_DOCKER_PREFIX}" --format "{{.ID}}" | xargs ${XARGS_NO_RUN_IF_EMPTY} docker rmi -f 2>/dev/null + docker images --filter "reference=spryker_docker_sdk*" --format "{{.ID}}" | xargs ${XARGS_NO_RUN_IF_EMPTY} docker rmi -f 2>/dev/null + docker rmi -f "${SPRYKER_PLATFORM_IMAGE}" 2>/dev/null || true } -# Using temporary file for secrets as `docker secret` is only available for swarm mode. -function Images::_prepareSecrets() { - env - "${SECRETS_ENVIRONMENT[@]}" env > "${SECRETS_FILE_PATH}" +function Images::_checkBuildxVersion() { + min_version=${1} + version_regex="v([0-9]+\.[0-9]+\.[0-9]+)" + actual_version=$([[ $(docker buildx version) =~ $version_regex ]] && echo "${BASH_REMATCH[1]}") + greater_version=$(printf "%s\n%s\n" "${actual_version}" "${min_version}" | sort -t '.' -k 1,1 -k 2,2 -k 3,3 -g | tail -n 1) + if [ "$min_version" == "$greater_version" ]; then + return "${FALSE}" + fi } -function Images::_buildApp() { - - local -a sshArgument=() - local folder=${1} - local withPushImages=${2:-${FALSE}} - local baseAppImage="${SPRYKER_DOCKER_PREFIX}_base_app:${SPRYKER_DOCKER_TAG}" - local appImage="${SPRYKER_DOCKER_PREFIX}_app:${SPRYKER_DOCKER_TAG}" - local localAppImage="${SPRYKER_DOCKER_PREFIX}_local_app:${SPRYKER_DOCKER_TAG}" - local runtimeImage="${SPRYKER_DOCKER_PREFIX}_run_app:${SPRYKER_DOCKER_TAG}" - local baseCliImage="${SPRYKER_DOCKER_PREFIX}_base_cli:${SPRYKER_DOCKER_TAG}" - local cliImage="${SPRYKER_DOCKER_PREFIX}_cli:${SPRYKER_DOCKER_TAG}" - local pipelineImage="${SPRYKER_DOCKER_PREFIX}_pipeline:${SPRYKER_DOCKER_TAG}" - local runtimeCliImage="${SPRYKER_DOCKER_PREFIX}_run_cli:${SPRYKER_DOCKER_TAG}" - - if [ -n "${SSH_AUTH_SOCK_IN_CLI}" ]; then - sshArgument=('--ssh' 'default') +function Images::_build() { + + # Checking availability of docker bake or buildx + if docker buildx >/dev/null 2>&1; then + if Images::_checkBuildxVersion "0.6.99"; then + import sdk/images/engine/bake.sh + else + import sdk/images/engine/buildx.sh + Console::warn 'Warning! Upgrade `buildx` docker plugin to the latest version for better performance' + fi + else + import sdk/images/engine/build.sh + Console::warn 'Warning! Install `buildx` docker plugin for better performance' fi + # Using temporary file for secrets as `docker secret` is only available for swarm mode. + function Images::_prepareSecrets() { + env - "${SECRETS_ENVIRONMENT[@]}" env > "${SECRETS_FILE_PATH}" + } + Images::_prepareSecrets Registry::Trap::addExitHook 'removeBuildSecrets' "rm -f ${SECRETS_FILE_PATH}" - Console::verbose "${INFO}Building Application images${NC}" - - docker build \ - -t "${baseAppImage}" \ - -f "${DEPLOYMENT_PATH}/images/common/application/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PLATFORM_IMAGE=${SPRYKER_PLATFORM_IMAGE}" \ - --build-arg "SPRYKER_LOG_DIRECTORY=${SPRYKER_LOG_DIRECTORY}" \ - --build-arg "SPRYKER_PIPELINE=${SPRYKER_PIPELINE}" \ - --build-arg "APPLICATION_ENV=${APPLICATION_ENV}" \ - --build-arg "SPRYKER_DB_ENGINE=${SPRYKER_DB_ENGINE}" \ - --build-arg "KNOWN_HOSTS=${KNOWN_HOSTS}" \ - --build-arg "SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH:-"current"}" \ - --build-arg "SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP:-""}" \ - --build-arg "SPRYKER_NODE_IMAGE_VERSION=${SPRYKER_NODE_IMAGE_VERSION}" \ - --build-arg "SPRYKER_NODE_IMAGE_DISTRO=${SPRYKER_NODE_IMAGE_DISTRO}" \ - --build-arg "SPRYKER_NPM_VERSION=${SPRYKER_NPM_VERSION}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - - docker build \ - -t "${appImage}" \ - -f "${DEPLOYMENT_PATH}/images/${folder}/application/Dockerfile" \ - "${sshArgument[@]}" \ - --secret "id=secrets-env,src=$SECRETS_FILE_PATH" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${baseAppImage}" \ - --build-arg "SPRYKER_DOCKER_PREFIX=${SPRYKER_DOCKER_PREFIX}" \ - --build-arg "SPRYKER_DOCKER_TAG=${SPRYKER_DOCKER_TAG}" \ - --build-arg "USER_UID=${USER_FULL_ID%%:*}" \ - --build-arg "DEPLOYMENT_PATH=${DEPLOYMENT_PATH}" \ - --build-arg "SPRYKER_PIPELINE=${SPRYKER_PIPELINE}" \ - --build-arg "APPLICATION_ENV=${APPLICATION_ENV}" \ - --build-arg "SPRYKER_DB_ENGINE=${SPRYKER_DB_ENGINE}" \ - --build-arg "SPRYKER_COMPOSER_MODE=${SPRYKER_COMPOSER_MODE}" \ - --build-arg "SPRYKER_COMPOSER_AUTOLOAD=${SPRYKER_COMPOSER_AUTOLOAD}" \ - --build-arg "SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH:-"current"}" \ - --build-arg "SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP:-""}" \ - . 1>&2 - - docker build \ - -t "${localAppImage}" \ - -t "${runtimeImage}" \ - -f "${DEPLOYMENT_PATH}/images/common/application-local/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${appImage}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - - if [ -n "${SPRYKER_XDEBUG_MODE_ENABLE}" ]; then - docker build \ - -t "${runtimeImage}" \ - -f "${DEPLOYMENT_PATH}/images/debug/application/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${localAppImage}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - fi - - Console::verbose "${INFO}Building CLI images${NC}" - - docker build \ - -t "${baseCliImage}" \ - -t "${pipelineImage}" \ - -f "${DEPLOYMENT_PATH}/images/common/cli/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${localAppImage}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - - docker build \ - -t "${cliImage}" \ - -t "${runtimeCliImage}" \ - -f "${DEPLOYMENT_PATH}/images/${folder}/cli/Dockerfile" \ - "${sshArgument[@]}" \ - --secret "id=secrets-env,src=$SECRETS_FILE_PATH" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${baseCliImage}" \ - --build-arg "DEPLOYMENT_PATH=${DEPLOYMENT_PATH}" \ - --build-arg "SPRYKER_PIPELINE=${SPRYKER_PIPELINE}" \ - --build-arg "SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH:-"current"}" \ - --build-arg "SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP:-""}" \ - . 1>&2 - - if [ -n "${SPRYKER_XDEBUG_MODE_ENABLE}" ]; then - docker build \ - -t "${runtimeCliImage}" \ - -f "${DEPLOYMENT_PATH}/images/debug/cli/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${cliImage}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - fi - - if [ "${withPushImages}" == "${TRUE}" ]; then - local jenkinsImage="${SPRYKER_DOCKER_PREFIX}_jenkins:${SPRYKER_DOCKER_TAG}" - - docker build \ - -t "${jenkinsImage}" \ - -f "${DEPLOYMENT_PATH}/images/common/services/jenkins/export/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${appImage}" \ - "${DEPLOYMENT_PATH}/" 1>&2 - fi + Images::_build::perform "${@}" Registry::Trap::releaseExitHook 'removeBuildSecrets' } -function Images::_buildFrontend() { - local folder=${1} - local cliImage="${SPRYKER_DOCKER_PREFIX}_cli:${SPRYKER_DOCKER_TAG}" - local builderAssetsImage="$(Assets::getImageTag)" - local baseFrontendImage="${SPRYKER_DOCKER_PREFIX}_base_frontend:${SPRYKER_DOCKER_TAG}" - local frontendImage="${SPRYKER_DOCKER_PREFIX}_frontend:${SPRYKER_DOCKER_TAG}" - local runtimeFrontendImage="${SPRYKER_DOCKER_PREFIX}_run_frontend:${SPRYKER_DOCKER_TAG}" - - Console::verbose "${INFO}Building Frontend images${NC}" - - docker build \ - -t "${baseFrontendImage}" \ - -f "${DEPLOYMENT_PATH}/images/common/frontend/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_FRONTEND_IMAGE=${SPRYKER_FRONTEND_IMAGE}" \ - --build-arg "SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH:-"current"}" \ - --build-arg "SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP:-""}" \ - --build-arg "SPRYKER_MAINTENANCE_MODE_ENABLED=${SPRYKER_MAINTENANCE_MODE_ENABLED}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - - docker build \ - -t "${frontendImage}" \ - -t "${runtimeFrontendImage}" \ - -f "${DEPLOYMENT_PATH}/images/${folder}/frontend/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${baseFrontendImage}" \ - --build-arg "SPRYKER_ASSETS_BUILDER_IMAGE=${builderAssetsImage}" \ - --build-arg "SPRYKER_MAINTENANCE_MODE_ENABLED=${SPRYKER_MAINTENANCE_MODE_ENABLED}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - - if [ -n "${SPRYKER_XDEBUG_MODE_ENABLE}" ]; then - docker build \ - -t "${runtimeFrontendImage}" \ - -f "${DEPLOYMENT_PATH}/images/debug/frontend/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - --build-arg "SPRYKER_PARENT_IMAGE=${frontendImage}" \ - --build-arg "SPRYKER_XDEBUG_MODE_ENABLE=${SPRYKER_XDEBUG_MODE_ENABLE}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 - fi -} +function Images::print() { -function Images::_buildGateway() { - local gatewayImage="${SPRYKER_DOCKER_PREFIX}_gateway:${SPRYKER_DOCKER_TAG}" + local TARGET_TAG=${1:-${SPRYKER_DOCKER_TAG}} + local destination=${2:-print} - Console::verbose "${INFO}Building Gateway image${NC}" + source ${DEPLOYMENT_PATH}/images/export/${destination}.sh - docker build \ - -t "${gatewayImage}" \ - -f "${DEPLOYMENT_PATH}/images/common/gateway/Dockerfile" \ - --progress="${PROGRESS_TYPE}" \ - "${DEPLOYMENT_PATH}/context" 1>&2 -} + local imageData + for imageData in "${IMAGE_TAGS[@]}"; do + eval "${imageData}" -function Images::_tagByApp() { - local applicationName=$1 - local imageName=$2 - local baseImageName=${3:-${imageName}} - local applicationPrefix="$(echo "$applicationName" | tr '[:upper:]' '[:lower:]')" - local tag="${imageName}-${applicationPrefix}" + for tag in "${TAGS[@]}"; do + echo -e "$IMAGE $tag" + done - docker tag "${baseImageName}" "${tag}" -} - -function Images::tagApplications() { - local tag=${1:-${SPRYKER_DOCKER_TAG}} - - for application in "${SPRYKER_APPLICATIONS[@]}"; do - Images::_tagByApp "${application}" "${SPRYKER_DOCKER_PREFIX}_app:${tag}" "${SPRYKER_DOCKER_PREFIX}_app:${SPRYKER_DOCKER_TAG}" - Images::_tagByApp "${application}" "${SPRYKER_DOCKER_PREFIX}_run_app:${tag}" "${SPRYKER_DOCKER_PREFIX}_run_app:${SPRYKER_DOCKER_TAG}" - done - - Images::_tagByApp pipeline "${SPRYKER_DOCKER_PREFIX}_pipeline:${tag}" "${SPRYKER_DOCKER_PREFIX}_pipeline:${SPRYKER_DOCKER_TAG}" -} - -function Images::tagFrontend() { - local tag=${1:-${SPRYKER_DOCKER_TAG}} - - Images::_tagByApp frontend "${SPRYKER_DOCKER_PREFIX}_frontend:${tag}" "${SPRYKER_DOCKER_PREFIX}_frontend:${SPRYKER_DOCKER_TAG}" -} - -function Images::printAll() { - local tag=${1:-${SPRYKER_DOCKER_TAG}} - - for application in "${SPRYKER_APPLICATIONS[@]}"; do - local applicationPrefix=$(echo "${application}" | tr '[:upper:]' '[:lower:]') - printf "%s %s_app:%s\n" "${application}" "${SPRYKER_DOCKER_PREFIX}" "${tag}-${applicationPrefix}" done - - printf "%s %s_frontend:%s\n" "frontend" "${SPRYKER_DOCKER_PREFIX}" "${tag}-frontend" - printf "%s %s_pipeline:%s\n" "pipeline" "${SPRYKER_DOCKER_PREFIX}" "${tag}-pipeline" } diff --git a/bin/sdk/images/destination/ecr.sh b/bin/sdk/images/destination/ecr.sh new file mode 100644 index 000000000..76f752c53 --- /dev/null +++ b/bin/sdk/images/destination/ecr.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +function Images::needPush() { + return ${TRUE} +} diff --git a/bin/sdk/images/destination/print.sh b/bin/sdk/images/destination/print.sh new file mode 100644 index 000000000..33af82fa1 --- /dev/null +++ b/bin/sdk/images/destination/print.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +function Images::needPush() { + return ${FALSE} +} diff --git a/bin/sdk/images/engine/bake.sh b/bin/sdk/images/engine/bake.sh new file mode 100644 index 000000000..f75b8a936 --- /dev/null +++ b/bin/sdk/images/engine/bake.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +function Images::_build::perform() { + + local folder=${1} + local TARGET_TAG=${2:-${SPRYKER_DOCKER_TAG}} + local destination=${3:-print} + + local -a arguments=() + + if Images::needPush; then + arguments+=('--push') + Console::verbose "${INFO}Building, tagging and pushing images${NC}" + else + Console::verbose "${INFO}Building and tagging images${NC}" + fi + + export TARGET_TAG + export SPRYKER_BUILD_SSH=$([ -n "${SSH_AUTH_SOCK_IN_CLI}" ] && echo 'default' || echo '') + + docker buildx bake \ + -f ${DEPLOYMENT_PATH}/images/${folder}/${destination}.docker-bake.hcl \ + "${arguments[@]}" \ + --progress="${PROGRESS_TYPE}" + +} diff --git a/bin/sdk/images/engine/build.common.sh b/bin/sdk/images/engine/build.common.sh new file mode 100644 index 000000000..ee2529c19 --- /dev/null +++ b/bin/sdk/images/engine/build.common.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +require docker + +function Images::_build::perform() { + + local folder=${1} + local TARGET_TAG=${2:-${SPRYKER_DOCKER_TAG}} + local destination=${3:-print} + + local targetImage="${SPRYKER_DOCKER_PREFIX}_target:${SPRYKER_DOCKER_TAG}" + + Console::verbose "${INFO}Building images${NC}" + + # Primal build including all stages to fully benefit from multistage features + Images::build::_runBuild --target "target" -t "${targetImage}" + + # Tagging all the images by running the same build targeting different stages + source ${DEPLOYMENT_PATH}/images/${folder}/${destination}.sh + + local -a arguments=('--quiet' '--progress' 'auto') + + if [ -n "${SSH_AUTH_SOCK_IN_CLI}" ]; then + arguments+=('--ssh' 'default') + fi + + if Images::needPush; then + Console::verbose "${INFO}Tagging and pushing images${NC}" + else + Console::verbose "${INFO}Tagging images${NC}" + fi + + arguments+=($(Images::_build::prepareArguments)) + + local targetData + for targetData in "${TARGET_TAGS[@]}"; do + eval "${targetData}" + + local -a tagArguments=() + local tag + for tag in "${TAGS[@]}"; do + tagArguments+=('-t' "${tag}") + done + + Console::info "${YELLOW}Target:${NC} ${TARGET}" + Console::verbose "${YELLOW}Tags:${NC}" + Console::verbose "${DGRAY}${TAGS[@]}${NC}" + Console::verbose "${YELLOW}Hash:${NC}" + Images::build::_runBuild --target "${TARGET}" "${arguments[@]}" "${tagArguments[@]}" + + Images::_build::afterTaggingAnImage "${TAGS[@]}" + done + + docker rmi -f "${targetImage}" >/dev/null 2>&1 || true +} + +function Images::build::_runBuild { + + docker build \ + -f "${DEPLOYMENT_PATH}/images/${folder}/Dockerfile" \ + "${@}" \ + --secret "id=secrets-env,src=$SECRETS_FILE_PATH" \ + --label "spryker.project=${SPRYKER_DOCKER_PREFIX}" \ + --label "spryker.revision=${SPRYKER_BUILD_HASH}" \ + --label "spryker.sdk.revision=${SPRYKER_SDK_REVISION}" \ + --build-arg "DEPLOYMENT_PATH=${DEPLOYMENT_PATH}" \ + --build-arg "SPRYKER_PLATFORM_IMAGE=${SPRYKER_PLATFORM_IMAGE}" \ + --build-arg "SPRYKER_FRONTEND_IMAGE=${SPRYKER_FRONTEND_IMAGE}" \ + --build-arg "SPRYKER_LOG_DIRECTORY=${SPRYKER_LOG_DIRECTORY}" \ + --build-arg "SPRYKER_PIPELINE=${SPRYKER_PIPELINE}" \ + --build-arg "APPLICATION_ENV=${APPLICATION_ENV}" \ + --build-arg "SPRYKER_COMPOSER_MODE=${SPRYKER_COMPOSER_MODE}" \ + --build-arg "SPRYKER_COMPOSER_AUTOLOAD=${SPRYKER_COMPOSER_AUTOLOAD}" \ + --build-arg "SPRYKER_ASSETS_MODE=${SPRYKER_ASSETS_MODE}" \ + --build-arg "SPRYKER_DB_ENGINE=${SPRYKER_DB_ENGINE}" \ + --build-arg "KNOWN_HOSTS=${KNOWN_HOSTS}" \ + --build-arg "SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH}" \ + --build-arg "SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP}" \ + --build-arg "SPRYKER_NODE_IMAGE_VERSION=${SPRYKER_NODE_IMAGE_VERSION}" \ + --build-arg "SPRYKER_NODE_IMAGE_DISTRO=${SPRYKER_NODE_IMAGE_DISTRO}" \ + --build-arg "SPRYKER_NPM_VERSION=${SPRYKER_NPM_VERSION}" \ + --build-arg "USER_UID=${USER_UID}" \ + ./ >&2 +} diff --git a/bin/sdk/images/engine/build.sh b/bin/sdk/images/engine/build.sh new file mode 100644 index 000000000..04df5442d --- /dev/null +++ b/bin/sdk/images/engine/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +import sdk/images/engine/build.common.sh + +function Images::_build::prepareArguments() { + : +} + +function Images::_build::afterTaggingAnImage() { +set -x + local -a tagsToPush=("${@}") + + if Images::needPush; then + local tag + for tag in "${tagsToPush[@]}"; do + docker push ${tag} + done + fi +} diff --git a/bin/sdk/images/engine/buildx.sh b/bin/sdk/images/engine/buildx.sh new file mode 100644 index 000000000..1f04111c4 --- /dev/null +++ b/bin/sdk/images/engine/buildx.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +import sdk/images/engine/build.common.sh + +function Images::_build::prepareArguments() { + if Images::needPush; then + echo '--push' + fi +} + +function Images::_build::afterTaggingAnImage() { + : +} diff --git a/bin/sdk/images/mount.sh b/bin/sdk/images/mount.sh index a9c047797..37e7f4613 100644 --- a/bin/sdk/images/mount.sh +++ b/bin/sdk/images/mount.sh @@ -2,7 +2,7 @@ import sdk/images/common.sh -function Images::buildApplication() { +function Images::build() { for arg in "${@}"; do case "${arg}" in '--force') @@ -12,31 +12,15 @@ function Images::buildApplication() { # TODO implement --no-cache for build images ;; *) - Console::verbose "\nUnknown option ${INFO}${arg}${WARN} is acquired for Images::buildApplication." + Console::verbose "\nUnknown option ${INFO}${arg}${WARN} is acquired for Images::build." ;; esac done - Images::_buildApp mount - Images::tagApplications "${SPRYKER_DOCKER_TAG}" + Images::_build mount } -function Images::buildFrontend() { - for arg in "${@}"; do - case "${arg}" in - '--force') - # it is always it. - ;; - '--no-cache') - # TODO implement --no-cache for build images - ;; - *) - Console::verbose "\nUnknown option ${INFO}${arg}${WARN} is acquired for Images::buildFrontend." - ;; - esac - done - - Images::_buildFrontend mount - Images::_buildGateway - Images::tagFrontend "${SPRYKER_DOCKER_TAG}" +function Images::export() { + Console::error "Export is not available in development mode." + exit 1 } diff --git a/generator/Dockerfile b/generator/Dockerfile index d44b258e6..c3390b68e 100644 --- a/generator/Dockerfile +++ b/generator/Dockerfile @@ -1,5 +1,5 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PHP_VERSION=7.3 +# syntax = docker/dockerfile:1.5 +ARG SPRYKER_PHP_VERSION=8.2 FROM spryker/php:${SPRYKER_PHP_VERSION} @@ -22,7 +22,7 @@ RUN chmod 755 ${srcRoot}/openssl/generate.sh USER root ARG USER_UID -RUN usermod -u ${USER_UID} spryker && find / -user 1000 -exec chown -h spryker {} \ || true; +RUN usermod -u ${USER_UID} spryker && find / -user 1000 -exec chown -h spryker {} \; || true; USER spryker diff --git a/generator/deploy-file-generator/Dockerfile b/generator/deploy-file-generator/Dockerfile index eba9890f7..e9d5e7878 100644 --- a/generator/deploy-file-generator/Dockerfile +++ b/generator/deploy-file-generator/Dockerfile @@ -1,4 +1,4 @@ -# syntax = docker/dockerfile:experimental +# syntax = docker/dockerfile:1.5 ARG SPRYKER_PHP_VERSION=7.3 FROM spryker/php:${SPRYKER_PHP_VERSION} @@ -16,7 +16,7 @@ COPY --chown=spryker:spryker deploy-file-generator ${srcRoot}/deploy-file-genera USER root ARG USER_UID -RUN usermod -u ${USER_UID} spryker && find / -user 1000 -exec chown -h spryker {} \ || true; +RUN usermod -u ${USER_UID} spryker && find / -user 1000 -exec chown -h spryker {} \; || true; USER spryker diff --git a/generator/index.php b/generator/index.php index 7364c8bf5..cee4d40b2 100644 --- a/generator/index.php +++ b/generator/index.php @@ -22,6 +22,7 @@ $defaultDeploymentDir = getenv('SPRYKER_DOCKER_SDK_DEPLOYMENT_DIR') ?: './'; $platform = getenv('SPRYKER_DOCKER_SDK_PLATFORM') ?: 'linux'; // Possible values: linux windows macos +$sdkRevision = getenv('SPRYKER_SDK_REVISION') ?: ''; $loaders = new ChainLoader([ new FilesystemLoader(APPLICATION_SOURCE_DIR . DS . 'templates'), @@ -80,6 +81,7 @@ public function setIsActive(bool $isActive): void $projectData['_defaultDeploymentDir'] = $defaultDeploymentDir; $projectData['tag'] = $projectData['tag'] ?? uniqid(); $projectData['_platform'] = $platform; +$projectData['_sdk_revision'] = $sdkRevision; $mountMode = $projectData['_mountMode'] = retrieveMountMode($projectData, $platform); $projectData['_syncIgnore'] = buildSyncIgnore($deploymentDir); $projectData['_syncSessionName'] = preg_replace('/[^-a-zA-Z0-9]/', '-', $projectData['namespace'] . '-' . $projectData['tag'] . '-codebase'); @@ -575,11 +577,36 @@ static function ($endpoint) use ($projectData) { json_encode($environment, JSON_PRETTY_PRINT) ); +@mkdir($deploymentDir . DS . 'images' . DS . 'baked', 0777, true); file_put_contents( - $deploymentDir . DS . 'images' . DS . 'common' . DS . 'application' . DS . 'Dockerfile', - $twig->render('images' . DS . 'common' . DS . 'application' . DS . 'Dockerfile.twig', $projectData) + $deploymentDir . DS . 'images' . DS . 'baked' . DS . 'Dockerfile', + $twig->render('images' . DS . 'templates' . DS . 'baked' . DS . 'Dockerfile.twig', $projectData) ); -unlink($deploymentDir . DS . 'images' . DS . 'common' . DS . 'application' . DS . 'Dockerfile.twig'); +@mkdir($deploymentDir . DS . 'images' . DS . 'export', 0777, true); +file_put_contents( + $deploymentDir . DS . 'images' . DS . 'export' . DS . 'Dockerfile', + $twig->render('images' . DS . 'templates' . DS . 'export' . DS . 'Dockerfile.twig', $projectData) +); +@mkdir($deploymentDir . DS . 'images' . DS . 'mount', 0777, true); +file_put_contents( + $deploymentDir . DS . 'images' . DS . 'mount' . DS . 'Dockerfile', + $twig->render('images' . DS . 'templates' . DS . 'mount' . DS . 'Dockerfile.twig', $projectData) +); + +foreach (['baked' => 'runtime', 'mount' => 'runtime', 'export' => 'export'] as $buildMode => $tagMode) { + foreach (['bake' => 'docker-bake.hcl', 'build' => 'sh'] as $buildEngine => $fileExtension) { + foreach (['ecr', 'print'] as $buildDestination) { + if ($tagMode === 'runtime' && $buildDestination === 'ecr') continue; + file_put_contents( + $deploymentDir . DS . 'images' . DS . $buildMode . DS . "${buildDestination}.${fileExtension}", + $twig->render( + 'images' . DS . 'templates' . DS . 'plans' . DS . "${buildMode}.${fileExtension}", + ['_applications' => $projectData['_applications'], 'tagMode' => $tagMode, 'buildDestination' => $buildDestination] + ) + ); + } + } +} file_put_contents( $deploymentDir . DS . 'docker-compose.yml', diff --git a/generator/src/templates/deploy.bash.twig b/generator/src/templates/deploy.bash.twig index 18952361a..d9d1977e7 100644 --- a/generator/src/templates/deploy.bash.twig +++ b/generator/src/templates/deploy.bash.twig @@ -102,12 +102,13 @@ readonly PROJECT_DIR="$(pwd)" readonly DEPLOYMENT_DIR="$(cd "${BASH_SOURCE%/*}" >/dev/null 2>&1 && pwd)" readonly DEPLOYMENT_PATH="${DEPLOYMENT_DIR/$PROJECT_DIR/.}" readonly SECRETS_FILE_PATH="${DEPLOYMENT_DIR}/.secrets" -readonly PROGRESS_TYPE=${PROGRESS_TYPE:-tty} +readonly SPRYKER_SDK_REVISION="{{ _sdk_revision | raw }}" +readonly PROGRESS_TYPE=${PROGRESS_TYPE:-auto} VERBOSE=${VERBOSE:-0} # Predefined constants readonly APPLICATION_ENV="{{ environment | default('docker') }}" -declare -a -r SPRYKER_APPLICATIONS=({{ _applications | join(' ') | raw }}) +# deprecated with Image::export declare -a -r SPRYKER_ENTRYPOINTS=({{ _entryPoints | join(' ') | raw }}) readonly COMPOSE_PROJECT_NAME={{ namespace | default('spryker') }} readonly SPRYKER_PIPELINE=${SPRYKER_PIPELINE:-{{ pipeline | default('docker') }}} @@ -132,10 +133,10 @@ readonly SPRYKER_SYNC_VOLUME="${SPRYKER_DOCKER_PREFIX}_${SPRYKER_DOCKER_TAG}_dat readonly DOCKER_COMPOSE_FILES_EXTRA="{{ docker['compose']['yamls'] | default([]) | join(' ') }}" readonly SPRYKER_DASHBOARD_ENDPOINT="{{ _dashboardEndpoint }}" readonly KNOWN_HOSTS="{{ _knownHosts | default("") }}" -readonly SPRYKER_BUILD_HASH="${SPRYKER_BUILD_HASH}" -readonly SPRYKER_BUILD_DATE="${SPRYKER_BUILD_DATE}" +readonly SPRYKER_BUILD_HASH="${SPRYKER_BUILD_HASH:-current}" +readonly SPRYKER_BUILD_STAMP="${SPRYKER_BUILD_STAMP:-now}" readonly SPRYKER_REPOSITORY_HASH="${SPRYKER_BUILD_HASH:-"$(git rev-parse --verify HEAD 2>/dev/null || echo "head")"}" -readonly SPRYKER_MAINTENANCE_MODE_ENABLED="{{ docker['maintenance']['enabled'] | default('false') }}" +readonly SPRYKER_MAINTENANCE_MODE_ENABLED="${SPRYKER_MAINTENANCE_MODE_ENABLED:-{{ docker['maintenance']['enabled'] ? 1 : 0 | default(0) }}}" # PHP extensions {% for phpExtensionName in _phpExtensions %} @@ -172,6 +173,7 @@ readonly SSH_AUTH_SOCK_IN_CLI="$([ -n "${SSH_AUTH_SOCK}" ] && [ -z "${COMPOSER_A # Global variables readonly USER_FULL_ID=$(Environment::getFullUserId) +readonly USER_UID="${USER_FULL_ID%%:*}" readonly SPRYKER_XDEBUG_HOST_IP=$(Environment::getHostIp) readonly SECRETS_ENVIRONMENT=("COMPOSER_AUTH='${COMPOSER_AUTH}'") @@ -208,9 +210,11 @@ shift $((OPTIND - 1)) # Exporting for docker-compose export DEPLOYMENT_PATH +export SPRYKER_SDK_REVISION export SPRYKER_XDEBUG_HOST_IP export SSH_AUTH_SOCK_ON_HOST export COMPOSE_PROJECT_NAME +export SPRYKER_PROJECT_NAME export SPRYKER_DOCKER_PREFIX export SPRYKER_DOCKER_TAG export SPRYKER_TESTING_ENABLE @@ -218,7 +222,22 @@ export SPRYKER_XDEBUG_MODE_ENABLE export SPRYKER_XDEBUG_ENABLE export SPRYKER_LOG_DIRECTORY export SPRYKER_BUILD_HASH -export SPRYKER_BUILD_DATE +export SPRYKER_BUILD_STAMP +export SECRETS_FILE_PATH +export SPRYKER_PLATFORM_IMAGE +export SPRYKER_FRONTEND_IMAGE +export SPRYKER_PIPELINE +export APPLICATION_ENV +export SPRYKER_COMPOSER_MODE +export SPRYKER_COMPOSER_AUTOLOAD +export SPRYKER_ASSETS_MODE +export SPRYKER_DB_ENGINE +export KNOWN_HOSTS +export SPRYKER_NODE_IMAGE_VERSION +export SPRYKER_NODE_IMAGE_DISTRO +export SPRYKER_NPM_VERSION +export SPRYKER_MAINTENANCE_MODE_ENABLED +export USER_UID export BLACKFIRE_SERVER_ID=${BLACKFIRE_SERVER_ID} export BLACKFIRE_SERVER_TOKEN=${BLACKFIRE_SERVER_TOKEN} export BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID} diff --git a/generator/src/templates/docker-compose.yml.twig b/generator/src/templates/docker-compose.yml.twig index d8ce809bb..a841ef130 100644 --- a/generator/src/templates/docker-compose.yml.twig +++ b/generator/src/templates/docker-compose.yml.twig @@ -73,6 +73,7 @@ services: ALLOWED_IP: "127.0.0.1" SPRYKER_TESTING_ENABLE: ${SPRYKER_TESTING_ENABLE} BLACKFIRE_APM_ENABLED: ${BLACKFIRE_APM_ENABLED} + SPRYKER_MAINTENANCE_MODE_ENABLED: ${SPRYKER_MAINTENANCE_MODE_ENABLED:-0} {% if docker['debug']['xdebug']['enabled'] is not defined or docker['debug']['xdebug']['enabled'] == true %} SPRYKER_XDEBUG_ENABLE: ${SPRYKER_XDEBUG_ENABLE} {% endif %} diff --git a/generator/src/templates/mount/nfs.yml.twig b/generator/src/templates/mount/nfs.yml.twig index 6bab37313..2b6412e3a 100644 --- a/generator/src/templates/mount/nfs.yml.twig +++ b/generator/src/templates/mount/nfs.yml.twig @@ -2,7 +2,7 @@ {% set port = docker['mount'][_mountMode]['anticache']['port'] | default(8998) %} {% if enabled is not empty %} anticache: - image: ${SPRYKER_DOCKER_PREFIX}_cli:${SPRYKER_DOCKER_TAG} + image: ${SPRYKER_DOCKER_PREFIX}_run_cli:${SPRYKER_DOCKER_TAG} ports: - "{{ port }}:8998" healthcheck: diff --git a/generator/src/templates/service/dashboard/default/dashboard.yml.twig b/generator/src/templates/service/dashboard/default/dashboard.yml.twig index 997151cfa..35f300feb 100644 --- a/generator/src/templates/service/dashboard/default/dashboard.yml.twig +++ b/generator/src/templates/service/dashboard/default/dashboard.yml.twig @@ -1,7 +1,13 @@ {{ serviceName }}: build: context: ./${DEPLOYMENT_PATH}/ - dockerfile: images/common/dashboard/Dockerfile + dockerfile: images/services/dashboard/Dockerfile + tags: + - "${SPRYKER_DOCKER_PREFIX}_dashboard:${SPRYKER_DOCKER_TAG}" + labels: + "spryker.image": "none" + "spryker.project": "${SPRYKER_DOCKER_PREFIX}" + "spryker.sdk.revision": "${SPRYKER_SDK_REVISION}" networks: - public - private diff --git a/generator/src/templates/service/tideways/default/tideways.yml.twig b/generator/src/templates/service/tideways/default/tideways.yml.twig index ac6c075ff..42d0e39f2 100644 --- a/generator/src/templates/service/tideways/default/tideways.yml.twig +++ b/generator/src/templates/service/tideways/default/tideways.yml.twig @@ -1,9 +1,15 @@ {{ serviceName }}: build: - context: ./${DEPLOYMENT_PATH}/images/common/services/tideways/ + context: ./${DEPLOYMENT_PATH}/images/services/tideways/ dockerfile: Dockerfile args: TIDEWAYS_ENVIRONMENT_DEFAULT: "{{ serviceData.environment | default('production') }}" + tags: + - "${SPRYKER_DOCKER_PREFIX}_tideways:${SPRYKER_DOCKER_TAG}" + labels: + "spryker.image": "none" + "spryker.project": "${SPRYKER_DOCKER_PREFIX}" + "spryker.sdk.revision": "${SPRYKER_SDK_REVISION}" networks: - private labels: diff --git a/images/baked/.gitkeep b/images/baked/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/images/baked/application/Dockerfile b/images/baked/application/Dockerfile deleted file mode 100644 index aeeceae8e..000000000 --- a/images/baked/application/Dockerfile +++ /dev/null @@ -1,59 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE - -FROM ${SPRYKER_PARENT_IMAGE} AS application-production-dependencies - -USER spryker - -# Install composer modules for Spryker -COPY --chown=spryker:spryker composer.json composer.lock ${srcRoot}/ -ARG SPRYKER_COMPOSER_MODE -RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache,uid=1000 \ - --mount=type=ssh,uid=1000 --mount=type=secret,id=secrets-env,uid=1000 \ - set -o allexport && . /run/secrets/secrets-env && set +o allexport \ - && composer install --no-scripts --no-interaction ${SPRYKER_COMPOSER_MODE} -vvv - -FROM application-production-dependencies AS application-production-codebase - -COPY --chown=spryker:spryker src ${srcRoot}/src -COPY --chown=spryker:spryker config ${srcRoot}/config -COPY --chown=spryker:spryker *.php ${srcRoot}/ -# TODO: Move codebase related stuff from data folder to src. In ideal: translations in /data are needed for build below -COPY --chown=spryker:spryker data ${srcRoot}/data -RUN chmod 600 ${srcRoot}/config/Zed/*.key 2>/dev/null || true - -RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache,uid=1000 \ - composer dump-autoload -o - -ARG SPRYKER_PIPELINE -ENV SPRYKER_PIPELINE=${SPRYKER_PIPELINE} -ARG APPLICATION_ENV -ARG SPRYKER_DB_ENGINE -ENV APPLICATION_ENV=${APPLICATION_ENV} -ENV SPRYKER_DB_ENGINE=${SPRYKER_DB_ENGINE} - -COPY --chown=spryker:spryker data ${srcRoot}/data -RUN vendor/bin/install -r ${SPRYKER_PIPELINE} -s build -s build-production -vvv - -ARG SPRYKER_COMPOSER_AUTOLOAD -RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache,uid=1000 \ - composer dump-autoload ${SPRYKER_COMPOSER_AUTOLOAD} - -FROM application-production-codebase AS application-production - -COPY --chown=spryker:spryker public ${srcRoot}/public -COPY --chown=spryker:spryker frontend ${srcRoot}/frontend -COPY --chown=spryker:spryker .yarn* ${srcRoot}/.yarn -COPY --chown=spryker:spryker .* *.* LICENSE ${srcRoot}/ - -USER root -RUN rm -rf /var/run/opcache/* -RUN chown -R spryker:spryker /home/spryker - -ARG SPRYKER_BUILD_HASH='current' -ENV SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH} -ARG SPRYKER_BUILD_STAMP='' -ENV SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP} - -CMD [ "php-fpm", "--nodaemonize" ] -EXPOSE 9000 diff --git a/images/baked/assets/Dockerfile b/images/baked/assets/Dockerfile deleted file mode 100644 index 5e990fe16..000000000 --- a/images/baked/assets/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE - -FROM ${SPRYKER_PARENT_IMAGE} AS assets-builder - -USER spryker - -COPY --chown=spryker:spryker package.json package-lock.json ${srcRoot}/ -COPY --chown=spryker:spryker frontend* ${srcRoot}/frontend -COPY --chown=spryker:spryker tsconfig*.json ${srcRoot}/ -COPY --chown=spryker:spryker config/Yves ${srcRoot}/config/Yves - -ARG SPRYKER_ASSETS_MODE='development' -ENV SPRYKER_ASSETS_MODE=${SPRYKER_ASSETS_MODE} -ARG SPRYKER_PIPELINE -ENV SPRYKER_PIPELINE=${SPRYKER_PIPELINE} - -RUN --mount=type=cache,id=npm,sharing=locked,target=/root/.npm \ - echo "BUILD HASH: ${SPRYKER_BUILD_HASH}" \ - && echo "MODE: ${SPRYKER_ASSETS_MODE}" \ - && vendor/bin/install -r ${SPRYKER_PIPELINE} -s build-static -s build-static-${SPRYKER_ASSETS_MODE} -vvv diff --git a/images/baked/cli/Dockerfile b/images/baked/cli/Dockerfile deleted file mode 100644 index a019d0e4b..000000000 --- a/images/baked/cli/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE - -FROM ${SPRYKER_PARENT_IMAGE} as cli-production - -USER spryker - -# Install composer modules for Spryker -COPY --chown=spryker:spryker composer.json composer.lock ${srcRoot}/ -ARG SPRYKER_COMPOSER_MODE -RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache,uid=1000 \ - --mount=type=ssh,uid=1000 --mount=type=secret,id=secrets-env,uid=1000 \ - set -o allexport && . /run/secrets/secrets-env && set +o allexport \ - && composer install --no-interaction ${SPRYKER_COMPOSER_MODE} - -ARG SPRYKER_COMPOSER_AUTOLOAD -RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache,uid=1000 \ - composer dump-autoload ${SPRYKER_COMPOSER_AUTOLOAD} - -# Tests contain transfer declaration -COPY --chown=spryker:spryker tests ${srcRoot}/tests - -ENV DEVELOPMENT_CONSOLE_COMMANDS=1 -RUN vendor/bin/install -r ${SPRYKER_PIPELINE} -s build-development diff --git a/images/baked/frontend/Dockerfile b/images/baked/frontend/Dockerfile deleted file mode 100644 index 1b3416b2f..000000000 --- a/images/baked/frontend/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE -ARG SPRYKER_ASSETS_BUILDER_IMAGE - -FROM ${SPRYKER_ASSETS_BUILDER_IMAGE} as assets-builder - -FROM ${SPRYKER_PARENT_IMAGE} as frontend-production - -RUN mkdir -p /data/public && chmod 0777 /data/public -COPY --from=assets-builder --chown=root:root /data/public /data/public diff --git a/images/common/application-local/Dockerfile b/images/common/application-local/Dockerfile deleted file mode 100644 index 1dd3fc224..000000000 --- a/images/common/application-local/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE -FROM ${SPRYKER_PARENT_IMAGE} AS application-local - -# Make self-signed certificate to be trusted locally -COPY nginx/ssl/ca.crt /usr/local/share/ca-certificates -RUN update-ca-certificates diff --git a/images/common/application/Dockerfile.twig b/images/common/application/Dockerfile.twig deleted file mode 100644 index be4ad5d3d..000000000 --- a/images/common/application/Dockerfile.twig +++ /dev/null @@ -1,70 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PLATFORM_IMAGE=spryker/php:7.3 -ARG SPRYKER_NODE_IMAGE_VERSION -ARG SPRYKER_NODE_IMAGE_DISTRO - -FROM node:${SPRYKER_NODE_IMAGE_VERSION}-${SPRYKER_NODE_IMAGE_DISTRO} AS node - -ARG SPRYKER_NPM_VERSION - -RUN npm install -g npm@${SPRYKER_NPM_VERSION} - -FROM ${SPRYKER_PLATFORM_IMAGE} AS application-basic - -ENV SPRYKER_IN_DOCKER=1 -ENV COMPOSER_IGNORE_CHROMEDRIVER=1 -{% for envName, envValue in _envs %} -ENV {{ envName }}='{{ envValue }}' -{% endfor %} - -WORKDIR /data - -# Create log directory -ARG SPRYKER_LOG_DIRECTORY -ENV SPRYKER_LOG_DIRECTORY=${SPRYKER_LOG_DIRECTORY} -RUN mkdir -p ${SPRYKER_LOG_DIRECTORY} && \ -chown spryker:spryker ${SPRYKER_LOG_DIRECTORY} - -# Creates the list of known hosts -ARG KNOWN_HOSTS -RUN mkdir -p /home/spryker/.ssh && chmod 0700 /home/spryker/.ssh -RUN bash -c '[ ! -z "${KNOWN_HOSTS}" ] && ssh-keyscan -t rsa ${KNOWN_HOSTS} >> /home/spryker/.ssh/known_hosts || true' -RUN chown spryker:spryker -R /home/spryker/.ssh - -# PHP-FPM environment variables -ENV PHP_FPM_PM=dynamic -ENV PHP_FPM_PM_MAX_CHILDREN=4 -ENV PHP_FPM_PM_START_SERVERS=2 -ENV PHP_FPM_PM_MIN_SPARE_SERVERS=1 -ENV PHP_FPM_PM_MAX_SPARE_SERVERS=2 -ENV PHP_FPM_PM_MAX_REQUESTS=500 -ENV PHP_FPM_REQUEST_TERMINATE_TIMEOUT=1m - -# PHP configuration -COPY php/php-fpm.d/worker.conf /usr/local/etc/php-fpm.d/worker.conf -RUN bash -c "php -r 'exit(PHP_VERSION_ID > 70400 ? 1 : 0);' && sed -i '' -e 's/decorate_workers_output/;decorate_workers_output/g' /usr/local/etc/php-fpm.d/worker.conf || true" -COPY php/php.ini /usr/local/etc/php/ -COPY php/conf.d/90-opcache.ini /usr/local/etc/php/conf.d -# removing default opcache.ini -RUN rm -f /usr/local/etc/php/conf.d/opcache.ini - -{% if _phpExtensions is defined and _phpExtensions is not empty %} -{% for phpExtention in _phpExtensions %} -RUN mv /usr/local/etc/php/disabled/{{phpExtention}}.ini /usr/local/etc/php/conf.d/90-{{phpExtention}}.ini -{% endfor %} -{% endif %} - -COPY php/conf.d/99-from-deploy-yaml-php.ini /usr/local/etc/php/conf.d/ - -# Jenkins -COPY --chown=spryker:spryker jenkins/jenkins.docker.xml.twig /home/spryker/jenkins.docker.xml.twig - -# Build info -COPY --chown=spryker:spryker php/build.php /home/spryker/build.php - -# NodeJS + NPM -COPY --from=node /usr/lib /usr/lib -COPY --from=node /usr/local/share /usr/local/share -COPY --from=node /usr/local/lib /usr/local/lib -COPY --from=node /usr/local/include /usr/local/include -COPY --from=node /usr/local/bin /usr/local/bin diff --git a/images/common/cli/Dockerfile b/images/common/cli/Dockerfile deleted file mode 100644 index 661117ecf..000000000 --- a/images/common/cli/Dockerfile +++ /dev/null @@ -1,78 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE - -FROM ${SPRYKER_PARENT_IMAGE} as cli-basic - -# Blackfire client -RUN mkdir -p /tmp/blackfire \ - && architecture=$(case $(uname -m) in i386 | i686 | x86) echo "i386" ;; x86_64 | amd64) echo "amd64" ;; aarch64 | arm64 | armv8) echo "arm64" ;; *) echo "amd64" ;; esac) \ - && curl -A "Docker" -L https://blackfire.io/api/v1/releases/cli/linux/$architecture | tar zxp -C /tmp/blackfire \ - && mv /tmp/blackfire/blackfire /usr/bin/blackfire \ - && rm -Rf /tmp/blackfire - -ENV PATH=/data/vendor/bin:$PATH - -RUN --mount=type=cache,id=aptlib,sharing=locked,target=/var/lib/apt \ - --mount=type=cache,id=aptcache,sharing=locked,target=/var/cache/apt \ - bash -c 'if [ ! -z "$(which apt)" ]; then apt update -y && apt install -y \ - inotify-tools \ - netcat-openbsd \ - git \ - redis-tools \ - jq \ - python3 \ - g++ \ - make \ - ; fi' - -# Debian contains outdated Yarn package -RUN --mount=type=cache,id=aptlib,sharing=locked,target=/var/lib/apt \ - --mount=type=cache,id=aptcache,sharing=locked,target=/var/cache/apt \ - bash -c 'if [ ! -z "$(which apt)" ]; then \ - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ - apt update -y && apt install -y \ - yarn \ - ; fi' - -RUN --mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk mkdir -p /etc/apk && ln -vsf /var/cache/apk /etc/apk/cache && \ - bash -c 'if [ ! -z "$(which apk)" ]; then apk update && apk add \ - inotify-tools \ - netcat-openbsd \ - coreutils \ - ncurses \ - git \ - redis \ - yarn \ - jq \ - python3 \ - g++ \ - make \ - ; fi' - -# TODO Not-available feature: autoload-cache. Should be switchable -#RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache \ -# chown spryker:spryker /home/spryker/.composer/cache && chmod 0777 /home/spryker/.composer/cache -#USER spryker -#RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache \ -# composer global require sprymiker/autoload-cache:0.3.4 -#USER root -#RUN rm -rf /home/spryker/.composer/cache -# -#RUN --mount=type=cache,id=npm,sharing=locked,target=/root/.npm \ -# npm install autoload-cache@0.3.4 -g - -USER spryker - -RUN mkdir -p /home/spryker/env -COPY --chown=spryker:spryker cli /home/spryker/bin -RUN find /home/spryker/bin -type f -exec chmod +x {} \; -ENV PATH=/home/spryker/bin:$PATH - -RUN mkdir -p /home/spryker/ssh-relay/ && chmod 777 /home/spryker/ssh-relay && touch /home/spryker/ssh-relay/ssh-auth.sock && chmod 666 /home/spryker/ssh-relay/ssh-auth.sock \ - && touch /tmp/stdout && touch /tmp/stderr && chmod 666 /tmp/stdout && chmod 666 /tmp/stderr - -RUN mkdir -p /home/spryker/history && touch /home/spryker/history/.bash_history && chmod 0600 /home/spryker/history/.bash_history -ENV HISTFILE=/home/spryker/history/.bash_history - -ENV NEWRELIC_ENABLED=0 diff --git a/images/common/dashboard/Dockerfile b/images/common/dashboard/Dockerfile deleted file mode 100644 index d7aaab8d4..000000000 --- a/images/common/dashboard/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM node:alpine AS dashboard - -RUN mkdir -p /dashboard -WORKDIR /dashboard -ENV HOME=/dashboard - -RUN npm install log.io pm2 -g - -COPY context/dashboard/package.json context/dashboard/package-lock.json /dashboard/ -RUN npm install - -COPY context/dashboard/.log.io /dashboard/.log.io/ -COPY context/dashboard/assets /dashboard/assets/ -COPY context/dashboard/src /dashboard/src/ -COPY context/dashboard/views /dashboard/views/ -COPY context/dashboard/process.yml /dashboard/ - -EXPOSE 3000 6689 - -CMD ["pm2-runtime", "process.yml"] diff --git a/images/common/frontend/Dockerfile b/images/common/frontend/Dockerfile deleted file mode 100644 index 1a9cab66d..000000000 --- a/images/common/frontend/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -# syntax = docker/dockerfile:experimental -# For brotli support you can use something like fholzer/nginx-brotli:v1.18.0 -ARG SPRYKER_FRONTEND_IMAGE=nginx:alpine - -FROM ${SPRYKER_FRONTEND_IMAGE} as frontend-basic - -RUN mkdir -p /etc/nginx/template/ && chmod 0777 /etc/nginx/template/ -COPY --chown=root:root nginx/nginx.original.conf /etc/nginx/nginx.conf -COPY --chown=root:root nginx/conf.d/frontend.default.conf.tmpl /etc/nginx/template/default.conf.tmpl -COPY --chown=root:root nginx/conf.d/resolver.conf.tmpl /etc/nginx/template/resolver.conf.tmpl -COPY --chown=root:root nginx/auth /etc/nginx/auth -COPY --chown=root:root nginx/entrypoint.sh / -RUN chmod +x /entrypoint.sh - -ENV SPRYKER_DNS_RESOLVER_FLAGS="valid=10s ipv6=off" -ENV SPRYKER_DNS_RESOLVER_IP="" - -ARG SPRYKER_MAINTENANCE_MODE_ENABLED -ENV SPRYKER_MAINTENANCE_MODE_ENABLED=${SPRYKER_MAINTENANCE_MODE_ENABLED} - -# Build info -ARG SPRYKER_BUILD_HASH='current' -ENV SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH} -ARG SPRYKER_BUILD_STAMP='' -ENV SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP} -COPY --chown=root:root nginx/build.json /tmp/build.json -RUN mkdir -p /usr/share/nginx/ \ - && envsubst '${SPRYKER_BUILD_HASH} ${SPRYKER_BUILD_STAMP}' < /tmp/build.json > /usr/share/nginx/build.json \ - && rm -f /tmp/build.json - -ENTRYPOINT [ "/entrypoint.sh" ] - -CMD ["nginx", "-g", "daemon off;"] diff --git a/images/common/gateway/Dockerfile b/images/common/gateway/Dockerfile deleted file mode 100644 index 5fc928891..000000000 --- a/images/common/gateway/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_GATEWAY_IMAGE=nginx:alpine - -FROM ${SPRYKER_GATEWAY_IMAGE} as gateway - -COPY --chown=root:root nginx/nginx.with.stream.conf /etc/nginx/nginx.conf -COPY --chown=root:root nginx/conf.d/gateway.default.conf /etc/nginx/templates/default.conf.template -COPY --chown=root:root nginx/stream.d/gateway.default.conf /etc/nginx/stream.d/default.conf -COPY --chown=root:root nginx/vhost.d/ssl.default.conf /etc/nginx/vhost.d/ssl.default.conf -COPY --chown=root:root nginx/ssl /etc/nginx/ssl - -ENV SPRYKER_XDEBUG_ENABLE=0 - -CMD ["nginx", "-g", "daemon off;"] diff --git a/images/common/services/jenkins/export/Dockerfile b/images/common/services/jenkins/export/Dockerfile deleted file mode 100644 index 611f5d024..000000000 --- a/images/common/services/jenkins/export/Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE - -FROM spryker/jenkins-boilerplate:2.361.1 as spryker-jenkins-boilerplate -FROM ${SPRYKER_PARENT_IMAGE} as spryker_jenkins -EXPOSE 8080 -COPY context/jenkins/export/jenkins.docker.xml.twig ./config/Zed/cronjobs/jenkins.docker.xml.twig - -COPY --from=spryker-jenkins-boilerplate /usr/share/jenkins/ref/plugins /usr/share/jenkins/ref/plugins -COPY --from=spryker-jenkins-boilerplate /usr/share/jenkins/jenkins.war /usr/share/jenkins/jenkins.war -COPY --from=spryker-jenkins-boilerplate /usr/share/jenkins/jenkins-cli.jar /usr/share/jenkins/jenkins-cli.jar - -# Install packages on Alpine -RUN bash -c 'if [ ! -z "$(which apk)" ]; then apk --no-cache add \ - curl \ - bash \ - openjdk11 \ - ttf-dejavu \ - gettext \ - jq && \ - mkdir -p /envs \ - ; fi' - -# Install packages on Debian -RUN bash -c 'if [ ! -z "$(which apt)" ]; then apt update -y && \ - apt-get install -y software-properties-common && \ - apt-add-repository "deb http://security.debian.org/debian-security bullseye-security main" && \ - apt-add-repository "deb http://ftp.de.debian.org/debian bullseye main" && \ - apt update -y && apt install -y \ - curl \ - bash \ - openjdk-11-jdk \ - fonts-dejavu \ - gettext \ - jq \ - && \ - mkdir -p /envs \ - ; fi' - -COPY terraform/cli /envs/ -COPY context/jenkins/export/entrypoint.sh /entrypoint.sh -COPY context/jenkins/export/jenkins.model.JenkinsLocationConfiguration.xml /opt/jenkins.model.JenkinsLocationConfiguration.xml -COPY context/jenkins/export/nr-credentials.xml /opt/nr-credentials.xml -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/images/common/services/tideways/Dockerfile b/images/common/services/tideways/Dockerfile deleted file mode 100644 index 541050438..000000000 --- a/images/common/services/tideways/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM debian:stable-slim AS tideways-daemon - -ARG TIDEWAYS_ENVIRONMENT_DEFAULT=production -ENV TIDEWAYS_ENVIRONMENT=$TIDEWAYS_ENVIRONMENT_DEFAULT - -RUN apt update -y && apt install -yq --no-install-recommends gnupg2 curl sudo ca-certificates wget - -RUN echo 'deb https://packages.tideways.com/apt-packages-main any-version main' > /etc/apt/sources.list.d/tideways.list && \ - wget -qO - 'https://packages.tideways.com/key.gpg' | apt-key add - -RUN DEBIAN_FRONTEND=noninteractive apt update -y && apt install -yq tideways-daemon && \ - apt autoremove --assume-yes && \ - apt clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -ENTRYPOINT ["tideways-daemon","--hostname=tideways","--address=0.0.0.0:9135"] diff --git a/images/debug/application/Dockerfile b/images/debug/application/Dockerfile deleted file mode 100644 index ee1fb2f08..000000000 --- a/images/debug/application/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE -FROM ${SPRYKER_PARENT_IMAGE} AS application-debug - -RUN --mount=type=cache,id=aptlib,sharing=locked,target=/var/lib/apt \ - --mount=type=cache,id=aptcache,sharing=locked,target=/var/cache/apt \ - bash -c 'if [ ! -z "$(which apt)" ]; then apt update -y && apt install -y \ - supervisor \ - ; fi' - -RUN --mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk mkdir -p /etc/apk && ln -vsf /var/cache/apk /etc/apk/cache && \ - bash -c 'if [ ! -z "$(which apk)" ]; then apk update && apk add \ - supervisor \ - ; fi' - -RUN /usr/bin/install -d -m 777 /var/run/opcache/debug -COPY php/debug/etc/ /usr/local/etc/ -RUN bash -c "php -r 'exit(PHP_VERSION_ID > 70400 ? 1 : 0);' && sed -i '' -e 's/decorate_workers_output/;decorate_workers_output/g' /usr/local/etc/debug.php-fpm.conf/worker.conf || true" -COPY php/debug/supervisord.conf /etc/supervisor/supervisord.conf -RUN mkdir -p /var/log/supervisor - -CMD [ "/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf" ] -EXPOSE 9000 9001 diff --git a/images/debug/cli/Dockerfile b/images/debug/cli/Dockerfile deleted file mode 100644 index f06c6cf40..000000000 --- a/images/debug/cli/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE -FROM ${SPRYKER_PARENT_IMAGE} AS cli-debug - -USER root -RUN /usr/bin/install -d -m 777 /var/run/opcache/debug -USER spryker -COPY php/debug/etc/ /usr/local/etc/ diff --git a/images/debug/frontend/Dockerfile b/images/debug/frontend/Dockerfile deleted file mode 100644 index a0b2f8fe7..000000000 --- a/images/debug/frontend/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE -FROM ${SPRYKER_PARENT_IMAGE} AS frontend-debug - -ARG SPRYKER_XDEBUG_MODE_ENABLE -ENV SPRYKER_XDEBUG_MODE_ENABLE=${SPRYKER_XDEBUG_MODE_ENABLE} - -COPY --chown=root:root nginx/conf.d/debug.default.conf /etc/nginx/template/debug.default.conf diff --git a/images/export/.gitkeep b/images/export/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/images/mount/.gitkeep b/images/mount/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/images/mount/application/Dockerfile b/images/mount/application/Dockerfile deleted file mode 100644 index 064db1efd..000000000 --- a/images/mount/application/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE -FROM ${SPRYKER_PARENT_IMAGE} as application-development - -ARG APPLICATION_ENV -ENV APPLICATION_ENV=${APPLICATION_ENV} -ARG SPRYKER_DB_ENGINE -ENV SPRYKER_DB_ENGINE=${SPRYKER_DB_ENGINE} -ARG DEPLOYMENT_PATH -ENV SPRYKER_DB_ENGINE=${SPRYKER_DB_ENGINE} - -ENV PATH=/data/vendor/bin:$PATH - -ARG USER_UID -RUN usermod -u ${USER_UID} spryker && find / -user 1000 -exec chown -h spryker {} \ || true; - -COPY ${DEPLOYMENT_PATH}/context/php/conf.d/91-opcache-dev.ini /usr/local/etc/php/conf.d - -ARG SPRYKER_PIPELINE -ENV SPRYKER_PIPELINE=${SPRYKER_PIPELINE} -ARG SPRYKER_BUILD_HASH='current' -ENV SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH} -ARG SPRYKER_BUILD_STAMP='' -ENV SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP} - -CMD [ "php-fpm", "--nodaemonize" ] -EXPOSE 9000 diff --git a/images/mount/cli/Dockerfile b/images/mount/cli/Dockerfile deleted file mode 100644 index e6c0d8589..000000000 --- a/images/mount/cli/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE - -FROM ${SPRYKER_PARENT_IMAGE} as cli-development - -ENV DEVELOPMENT_CONSOLE_COMMANDS=1 - diff --git a/images/mount/frontend/Dockerfile b/images/mount/frontend/Dockerfile deleted file mode 100644 index 59dcd1076..000000000 --- a/images/mount/frontend/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -# syntax = docker/dockerfile:experimental -ARG SPRYKER_PARENT_IMAGE - -FROM ${SPRYKER_PARENT_IMAGE} as frontend-development diff --git a/images/services/dashboard/Dockerfile b/images/services/dashboard/Dockerfile new file mode 100644 index 000000000..b20e416bd --- /dev/null +++ b/images/services/dashboard/Dockerfile @@ -0,0 +1,19 @@ +FROM node:alpine AS dashboard +LABEL "spryker.image" "dashboard" + +WORKDIR /dashboard +ENV HOME=/dashboard + +COPY context/dashboard/package.json context/dashboard/package-lock.json /dashboard/ + +RUN < /etc/apt/sources.list.d/tideways.list + wget -qO - 'https://packages.tideways.com/key.gpg' | apt-key add - + apt update -y + apt install -yq tideways-daemon + apt autoremove --assume-yes + apt clean + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +EOT + +ENTRYPOINT ["tideways-daemon","--hostname=tideways","--address=0.0.0.0:9135"] diff --git a/images/templates/baked/Dockerfile.twig b/images/templates/baked/Dockerfile.twig new file mode 100644 index 000000000..f0c5d6b49 --- /dev/null +++ b/images/templates/baked/Dockerfile.twig @@ -0,0 +1,77 @@ +# syntax = docker/dockerfile:1.5 + +{% include "images/templates/common/args.Dockerfile" with _context %} + +{% include "images/templates/common/node.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/baked/npm.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/common/application.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/baked/application.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/common/pipeline.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/baked/assets.builder.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/common/frontend.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/common/gateway.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/common/application.dev.Dockerfile" with _context %} +{%if _context['docker']['debug']['enabled'] %} +{% include "images/templates/common/debug/application.Dockerfile" with _context %} +{%endif%} + +# ----------------------------- + +{% include "images/templates/baked/pipeline.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/common/cli.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/baked/cli.Dockerfile" with _context %} +{%if _context['docker']['debug']['enabled'] %} +{% include "images/templates/common/debug/cli.Dockerfile" with _context %} +{%endif%} + +# ----------------------------- + +{% include "images/templates/baked/frontend.Dockerfile" with _context %} + +# ----------------------------- + +{% include "images/templates/common/frontend.dev.Dockerfile" with _context %} +{%if _context['docker']['debug']['enabled'] %} +{% include "images/templates/common/debug/frontend.Dockerfile" with _context %} +{%endif%} + +# ----------------------------- + +# To build all necessary stages at once this fake stage has dependency to all of them (for `docker build`) +FROM busybox as target +LABEL "spryker.image" "none" + +COPY --from=application-dev /tmp/.dependency* /tmp/ +COPY --from=cli /tmp/.dependency* /tmp/ +COPY --from=frontend-dev /tmp/.dependency* /tmp/ +COPY --from=gateway /tmp/.dependency* /tmp/ diff --git a/images/templates/baked/application.Dockerfile b/images/templates/baked/application.Dockerfile new file mode 100644 index 000000000..eb747727f --- /dev/null +++ b/images/templates/baked/application.Dockerfile @@ -0,0 +1,110 @@ +# ----------------------------- + +FROM busybox AS stash-src + +COPY src /data/src +COPY public /data/public +COPY config /data/config +COPY resource[s] /data/resources +COPY composer.json composer.lock *.php LICENSE /data + +FROM stash-src AS stash-src-with-data-excluding-import +LABEL "spryker.image" "none" + +COPY data /data/data + +RUN rm -rf /data/data/import + +# ----------------------------- + +FROM ${SPRYKER_PLATFORM_IMAGE} AS stash-rsync +LABEL "spryker.image" "none" + +RUN --mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk \ + --mount=type=cache,id=aptlib,sharing=locked,target=/var/lib/apt \ + --mount=type=cache,id=aptcache,sharing=locked,target=/var/cache/apt \ + </ { print $3 }' | xargs -I '{}' cp -fp '{}' /rsync +EOT + +# ----------------------------- + +FROM ${SPRYKER_PLATFORM_IMAGE} AS application-codebase +LABEL "spryker.image" "none" + +USER spryker:spryker + +COPY --chown=spryker:spryker composer.json composer.lock *.php ${srcRoot}/ +ARG SPRYKER_COMPOSER_MODE +RUN --mount=type=cache,id=composer,sharing=locked,target=/home/spryker/.composer/cache,uid=1000 \ + --mount=type=ssh,uid=1000 --mount=type=secret,id=secrets-env,uid=1000 \ + </dev/null || true + vendor/bin/install -r ${SPRYKER_PIPELINE} -s build -s build-production + composer dump-autoload ${SPRYKER_COMPOSER_AUTOLOAD} +EOT + +USER root + +CMD [ "php-fpm", "--nodaemonize" ] +EXPOSE 9000 + +FROM application-before-stamp AS application +LABEL "spryker.image" "application" + +ARG SPRYKER_BUILD_HASH +ENV SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH} +ARG SPRYKER_BUILD_STAMP +ENV SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP} diff --git a/images/templates/baked/assets.builder.Dockerfile b/images/templates/baked/assets.builder.Dockerfile new file mode 100644 index 000000000..f28e2b8fa --- /dev/null +++ b/images/templates/baked/assets.builder.Dockerfile @@ -0,0 +1,51 @@ +FROM pipeline-basic AS assets-builder +LABEL "spryker.image" "none" + +USER root + +RUN --mount=type=cache,id=apk,sharing=locked,target=/var/cache/apk \ + --mount=type=cache,id=aptlib,sharing=locked,target=/var/lib/apt \ + --mount=type=cache,id=aptcache,sharing=locked,target=/var/cache/apt \ + </dev/null || true + vendor/bin/install -r ${SPRYKER_PIPELINE} -s build -s build-development + composer dump-autoload ${SPRYKER_COMPOSER_AUTOLOAD} +EOT + +COPY --link --chown=spryker:spryker fronten[d] ${srcRoot}/frontend +COPY --link --chown=spryker:spryker .yar[n] ${srcRoot}/.yarn +COPY --link --chown=spryker:spryker .* *.* ${srcRoot} + +FROM pipeline-before-stamp as pipeline +LABEL "spryker.image" "pipeline" + +ARG SPRYKER_BUILD_HASH +ENV SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH} +ARG SPRYKER_BUILD_STAMP +ENV SPRYKER_BUILD_STAMP=${SPRYKER_BUILD_STAMP} diff --git a/images/templates/common/application.Dockerfile b/images/templates/common/application.Dockerfile new file mode 100644 index 000000000..bd9a59e71 --- /dev/null +++ b/images/templates/common/application.Dockerfile @@ -0,0 +1,59 @@ +FROM ${SPRYKER_PLATFORM_IMAGE} AS application-basic +LABEL "spryker.image" "none" + +ENV SPRYKER_IN_DOCKER=1 +ENV COMPOSER_IGNORE_CHROMEDRIVER=1 +ENV SPRYKER_JENKINS_TEMPLATE_PATH=/home/spryker/jenkins.docker.xml.twig +{% for envName, envValue in _envs %} +ENV {{ envName }}='{{ envValue }}' +{% endfor %} + +# PHP-FPM environment variables +ENV PHP_FPM_PM=dynamic +ENV PHP_FPM_PM_MAX_CHILDREN=4 +ENV PHP_FPM_PM_START_SERVERS=2 +ENV PHP_FPM_PM_MIN_SPARE_SERVERS=1 +ENV PHP_FPM_PM_MAX_SPARE_SERVERS=2 +ENV PHP_FPM_PM_MAX_REQUESTS=500 +ENV PHP_FPM_REQUEST_TERMINATE_TIMEOUT=1m + +WORKDIR /data + +ARG DEPLOYMENT_PATH +COPY ${DEPLOYMENT_PATH}/context/php/php-fpm.d/worker.conf /usr/local/etc/php-fpm.d/worker.conf +COPY ${DEPLOYMENT_PATH}/context/php/php.ini /usr/local/etc/php/ +COPY ${DEPLOYMENT_PATH}/context/php/conf.d/90-opcache.ini /usr/local/etc/php/conf.d +COPY ${DEPLOYMENT_PATH}/context/php/conf.d/99-from-deploy-yaml-php.ini /usr/local/etc/php/conf.d/ +COPY --link --chown=spryker:spryker ${DEPLOYMENT_PATH}/context/jenkins/jenkins.docker.xml.twig /home/spryker/jenkins.docker.xml.twig +COPY --link --chown=spryker:spryker ${DEPLOYMENT_PATH}/context/php/build.php /home/spryker/build.php + +ARG SPRYKER_LOG_DIRECTORY +ARG KNOWN_HOSTS +ENV SPRYKER_LOG_DIRECTORY=${SPRYKER_LOG_DIRECTORY} +RUN <> /home/spryker/.ssh/known_hosts + fi + chown spryker:spryker -R /home/spryker/.ssh + rm -f /usr/local/etc/php/conf.d/opcache.ini +{% if _phpExtensions is defined and _phpExtensions is not empty %} +{% for phpExtention in _phpExtensions %} + mv /usr/local/etc/php/disabled/{{phpExtention}}.ini /usr/local/etc/php/conf.d/90-{{phpExtention}}.ini +{% endfor %} +{% endif %} + rm -rf /var/run + /usr/bin/install -d -m 777 /var/run/opcache + php -r 'exit(PHP_VERSION_ID > 70400 ? 1 : 0);' && sed -i '' -e 's/decorate_workers_output/;decorate_workers_output/g' /usr/local/etc/php-fpm.d/worker.conf || true +EOT + +ARG SPRYKER_PIPELINE +ENV SPRYKER_PIPELINE=${SPRYKER_PIPELINE} +ARG SPRYKER_DB_ENGINE +ENV SPRYKER_DB_ENGINE=${SPRYKER_DB_ENGINE} +ARG APPLICATION_ENV +ENV APPLICATION_ENV=${APPLICATION_ENV} +ENV PATH=${srcRoot}/vendor/bin:$PATH diff --git a/images/templates/common/application.dev.Dockerfile b/images/templates/common/application.dev.Dockerfile new file mode 100644 index 000000000..770409fbb --- /dev/null +++ b/images/templates/common/application.dev.Dockerfile @@ -0,0 +1,6 @@ +FROM application as application-dev +LABEL "spryker.image" "none" + +# Make self-signed certificate to be trusted locally +COPY --link ${DEPLOYMENT_PATH}/context/nginx/ssl/ca.crt /usr/local/share/ca-certificates +RUN update-ca-certificates diff --git a/images/templates/common/args.Dockerfile b/images/templates/common/args.Dockerfile new file mode 100644 index 000000000..9c799b84e --- /dev/null +++ b/images/templates/common/args.Dockerfile @@ -0,0 +1,4 @@ +ARG SPRYKER_PLATFORM_IMAGE +ARG SPRYKER_FRONTEND_IMAGE +ARG SPRYKER_NODE_IMAGE_VERSION +ARG SPRYKER_NODE_IMAGE_DISTRO diff --git a/context/nginx/build.json b/images/templates/common/build.json similarity index 100% rename from context/nginx/build.json rename to images/templates/common/build.json diff --git a/images/templates/common/cli.Dockerfile b/images/templates/common/cli.Dockerfile new file mode 100644 index 000000000..699f817a4 --- /dev/null +++ b/images/templates/common/cli.Dockerfile @@ -0,0 +1,71 @@ +FROM ${SPRYKER_PLATFORM_IMAGE} as cli-dependencies +LABEL "spryker.image" "none" + +USER root + +# Blackfire client +RUN < 70400 ? 1 : 0);' && sed -i '' -e 's/decorate_workers_output/;decorate_workers_output/g' /usr/local/etc/debug.php-fpm.conf/worker.conf || true +EOT + +CMD [ "/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf" ] +EXPOSE 9000 9001 diff --git a/images/templates/common/debug/cli.Dockerfile b/images/templates/common/debug/cli.Dockerfile new file mode 100644 index 000000000..ed0af657a --- /dev/null +++ b/images/templates/common/debug/cli.Dockerfile @@ -0,0 +1,8 @@ +USER root + +RUN /usr/bin/install -d -m 777 /var/run/opcache/debug + +USER spryker:spryker + +ARG DEPLOYMENT_PATH +COPY --link ${DEPLOYMENT_PATH}/context/php/debug/etc/ /usr/local/etc/ diff --git a/images/templates/common/debug/frontend.Dockerfile b/images/templates/common/debug/frontend.Dockerfile new file mode 100644 index 000000000..1e1bd969f --- /dev/null +++ b/images/templates/common/debug/frontend.Dockerfile @@ -0,0 +1,4 @@ +ENV SPRYKER_XDEBUG_MODE_ENABLE=1 + +ARG DEPLOYMENT_PATH +COPY --link --chown=root:root ${DEPLOYMENT_PATH}/context/nginx/conf.d/debug.default.conf /etc/nginx/template/debug.default.conf diff --git a/images/templates/common/frontend.Dockerfile b/images/templates/common/frontend.Dockerfile new file mode 100644 index 000000000..1745a2978 --- /dev/null +++ b/images/templates/common/frontend.Dockerfile @@ -0,0 +1,20 @@ +# For brotli support you can use something like fholzer/nginx-brotli:v1.18.0 +FROM ${SPRYKER_FRONTEND_IMAGE} as frontend-basic +LABEL "spryker.image" "frontend-basic" + +ENV srcRoot /data + +ARG DEPLOYMENT_PATH +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/nginx.original.conf /etc/nginx/nginx.conf +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/conf.d/frontend.default.conf.tmpl /etc/nginx/template/default.conf.tmpl +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/conf.d/resolver.conf.tmpl /etc/nginx/template/resolver.conf.tmpl +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/auth /etc/nginx/auth +COPY --chown=root:root --link --chmod=755 ${DEPLOYMENT_PATH}/context/nginx/entrypoint.sh / + +ENV SPRYKER_DNS_RESOLVER_FLAGS="valid=10s ipv6=off" +ENV SPRYKER_DNS_RESOLVER_IP="" +ENV SPRYKER_MAINTENANCE_MODE_ENABLED="0" + +ENTRYPOINT [ "/entrypoint.sh" ] + +CMD ["nginx", "-g", "daemon off;"] diff --git a/images/templates/common/frontend.dev.Dockerfile b/images/templates/common/frontend.dev.Dockerfile new file mode 100644 index 000000000..eb12ebbf2 --- /dev/null +++ b/images/templates/common/frontend.dev.Dockerfile @@ -0,0 +1,2 @@ +FROM frontend as frontend-dev +LABEL "spryker.image" "frontend" diff --git a/images/templates/common/gateway.Dockerfile b/images/templates/common/gateway.Dockerfile new file mode 100644 index 000000000..8eaa4388c --- /dev/null +++ b/images/templates/common/gateway.Dockerfile @@ -0,0 +1,13 @@ +FROM nginx:alpine as gateway +LABEL "spryker.image" "gateway" + +ARG DEPLOYMENT_PATH +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/nginx.with.stream.conf /etc/nginx/nginx.conf +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/conf.d/gateway.default.conf /etc/nginx/templates/default.conf.template +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/stream.d/gateway.default.conf /etc/nginx/stream.d/default.conf +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/vhost.d/ssl.default.conf /etc/nginx/vhost.d/ssl.default.conf +COPY --chown=root:root --link ${DEPLOYMENT_PATH}/context/nginx/ssl /etc/nginx/ssl + +ENV SPRYKER_XDEBUG_ENABLE=0 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/images/templates/common/node.Dockerfile b/images/templates/common/node.Dockerfile new file mode 100644 index 000000000..659e2f927 --- /dev/null +++ b/images/templates/common/node.Dockerfile @@ -0,0 +1,16 @@ +FROM node:${SPRYKER_NODE_IMAGE_VERSION}-${SPRYKER_NODE_IMAGE_DISTRO} AS node-distributive +LABEL "spryker.image" "none" + +ARG SPRYKER_NPM_VERSION +RUN npm install -g npm@${SPRYKER_NPM_VERSION} + +RUN <