Skip to content

Commit

Permalink
feat(planner/php): Allow disabling optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
pan93412 committed Nov 8, 2024
1 parent c2844b5 commit b6b5f5f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,16 @@ ARG BUILD_COMMAND
RUN if [ -n "${BUILD_COMMAND}" ]; then ${BUILD_COMMAND}; fi

# optimization for frameworks
ARG PHP_OPTIMIZE
RUN <<EOF
set -ux

if [ ! "${PHP_OPTIMIZE}" = "true" ]; then
echo "ZBPACK_PHP_OPTIMIZE is not set to true, skipping optimization"
echo "You will need to run cache, optimization, and some build command manually."
exit 0
fi

if [ -x artisan ]; then
# Laravel
php artisan optimize
Expand Down
3 changes: 3 additions & 0 deletions internal/php/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ package php

// ConfigPHPVersion defines the PHP version to use.
const ConfigPHPVersion = "php.version"

// ConfigPHPOptimize decides if we should run optimization on build.
const ConfigPHPOptimize = "php.optimize"
3 changes: 3 additions & 0 deletions internal/php/identify.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package php

import (
"strconv"
"strings"

"github.com/spf13/afero"
Expand Down Expand Up @@ -33,6 +34,7 @@ func (i *identify) PlanMeta(options plan.NewPlannerOptions) types.PlanMeta {
exts := DeterminePHPExtensions(options.Source)
buildCommand := DetermineBuildCommand(options.Config)
startCommand := DetermineStartCommand(options.Config)
phpOptimize := DeterminePHPOptimize(options.Config)

// Some meta will be added to the plan dynamically later.
meta := types.PlanMeta{
Expand All @@ -42,6 +44,7 @@ func (i *identify) PlanMeta(options plan.NewPlannerOptions) types.PlanMeta {
"exts": strings.Join(exts, " "),
"buildCommand": buildCommand,
"startCommand": startCommand,
"optimize": strconv.FormatBool(phpOptimize),
}

return meta
Expand Down
1 change: 1 addition & 0 deletions internal/php/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GenerateDockerfile(meta types.PlanMeta) (string, error) {
"PHP_EXTENSIONS": meta["exts"],
"BUILD_COMMAND": meta["buildCommand"],
"START_COMMAND": meta["startCommand"],
"PHP_OPTIMIZE": meta["optimize"],
}

for k, v := range variables {
Expand Down
5 changes: 5 additions & 0 deletions internal/php/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,8 @@ func DetermineBuildCommand(config plan.ImmutableProjectConfiguration) string {

return ""
}

// DeterminePHPOptimize determines if we should run optimization on build.
func DeterminePHPOptimize(config plan.ImmutableProjectConfiguration) bool {
return plan.Cast(config.Get(ConfigPHPOptimize), cast.ToBoolE).TakeOr(true)
}

0 comments on commit b6b5f5f

Please sign in to comment.