Skip to content

Commit

Permalink
feat: add hooks for docker image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jan 24, 2024
1 parent adb75d3 commit d0a198d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
18 changes: 18 additions & 0 deletions cmd/project/docker_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,29 @@ func configureDockerfileTemplate(ctx context.Context, shopCfg *shop.Config) (map
}
}

hooks := make(map[string]string)
if shopCfg.Docker.Hooks.PreUpdate != "" {
hooks["pre_update"] = shopCfg.Docker.Hooks.PreUpdate
}

if shopCfg.Docker.Hooks.PostUpdate != "" {
hooks["post_update"] = shopCfg.Docker.Hooks.PostUpdate
}

if shopCfg.Docker.Hooks.PreInstall != "" {
hooks["pre_install"] = shopCfg.Docker.Hooks.PreInstall
}

if shopCfg.Docker.Hooks.PostInstall != "" {
hooks["post_install"] = shopCfg.Docker.Hooks.PostInstall
}

templateVars := map[string]interface{}{
"PHP": shopCfg.Docker.PHP,
"ExcludePaths": shopCfg.Docker.ExcludePaths,
"BuildEnv": strings.Join(buildEnvironments, " "),
"RunEnv": strings.Join(runEnvironments, " "),
"Hooks": hooks,
}

return templateVars, nil
Expand Down
6 changes: 6 additions & 0 deletions cmd/project/templates/Dockerfile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ FROM base-extended
ENV {{ .RunEnv }}
{{- end }}

{{- range $key, $value := .Hooks }}
COPY --chmod=555 <<EOF /usr/local/shopware/{{ $key }}.d/01-generated.sh
{{ $value }}
EOF
{{- end }}

COPY --from=build --chown=www-data --link /src /var/www/html
10 changes: 9 additions & 1 deletion shop/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ type ConfigDockerPHP struct {

type ConfigDocker struct {
Environment []ConfigDockerEnvironmentVariable `yaml:"env,omitempty"`
PHP ConfigDockerPHP `yaml:"php"`
PHP ConfigDockerPHP `yaml:"php,omitempty"`
ExcludePaths []string `yaml:"exclude_paths,omitempty"`
Hooks ConfigDockerHooks `yaml:"hooks,omitempty"`
}

type ConfigDockerHooks struct {
PreUpdate string `yaml:"pre_update,omitempty"`
PostUpdate string `yaml:"post_update,omitempty"`
PreInstall string `yaml:"pre_install,omitempty"`
PostInstall string `yaml:"post_install,omitempty"`
}

type ConfigDockerEnvironmentVariable struct {
Expand Down
22 changes: 22 additions & 0 deletions shop/shopware-project-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@
"type": "array",
"items": {"type": "string"}
},
"hooks": {
"type": "object",
"additionalProperties": false,
"properties": {
"pre_update": {
"type": "array",
"items": {"type": "string"}
},
"post_update": {
"type": "array",
"items": {"type": "string"}
},
"pre_install": {
"type": "array",
"items": {"type": "string"}
},
"post_install": {
"type": "array",
"items": {"type": "string"}
}
}
},
"env": {
"type": "array",
"items": {
Expand Down

0 comments on commit d0a198d

Please sign in to comment.