-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
207 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
config/folder | ||
/var | ||
.git | ||
node_modules | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
ARG PHP_VERSION | ||
#syntax=docker/dockerfile:1.4 | ||
|
||
FROM ghcr.io/friendsofshopware/shopware-cli-base:${PHP_VERSION} | ||
# pin versions | ||
FROM shopware/docker-base:8.2 as base-image | ||
FROM ghcr.io/friendsofshopware/shopware-cli:latest-php-8.2 as shopware-cli | ||
|
||
COPY shopware-cli /usr/local/bin/ | ||
FROM base-image as base-extended | ||
RUN install-php-extensions opentelemetry | ||
|
||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh", "shopware-cli"] | ||
CMD ["--help"] | ||
RUN echo "display_errors = 1" >> /usr/local/etc/php/conf.d/99-z-custom.ini | ||
|
||
|
||
FROM shopware-cli as build | ||
|
||
ADD . /src | ||
WORKDIR /src | ||
|
||
RUN --mount=type=secret,id=composer_auth,dst=/src/auth.json \ | ||
--mount=type=cache,target=/root/.composer \ | ||
--mount=type=cache,target=/root/.npm \ | ||
/usr/local/bin/entrypoint.sh shopware-cli project ci /src | ||
|
||
FROM base-extended | ||
|
||
COPY --from=build --chown=www-data --link /src /var/www/html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package project | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
var dockerRootCmd = &cobra.Command{ | ||
Use: "docker", | ||
Short: "Docker Tools", | ||
} | ||
|
||
func init() { | ||
projectRootCmd.AddCommand(dockerRootCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package project | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"github.com/FriendsOfShopware/shopware-cli/extension" | ||
"github.com/FriendsOfShopware/shopware-cli/logging" | ||
"github.com/FriendsOfShopware/shopware-cli/shop" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
//go:embed templates/Dockerfile.tpl | ||
var dockerFileTemplate string | ||
|
||
var dockerBuildCmd = &cobra.Command{ | ||
Use: "build [name]", | ||
Short: "Build Docker Image", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
shopCfg, err := shop.ReadConfig(projectConfigPath, true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if shopCfg.Docker.PHP.PhpVersion == "" { | ||
projectRoot, err := os.Getwd() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
constraint, err := extension.GetShopwareProjectConstraint(projectRoot) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
phpVersion, err := extension.GetPhpVersion(cmd.Context(), constraint) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
shopCfg.Docker.PHP.PhpVersion = phpVersion | ||
logging.FromContext(cmd.Context()).Infof("No PHP version set, using PHP version %s", phpVersion) | ||
} | ||
|
||
var buf bytes.Buffer | ||
|
||
if err := template. | ||
Must(template.New("Dockerfile"). | ||
Parse(dockerFileTemplate)). | ||
Execute(&buf, *shopCfg.Docker); err != nil { | ||
return err | ||
} | ||
|
||
if err := os.WriteFile("Dockerfile", buf.Bytes(), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
shopCfg.Docker.ExcludePaths = append(shopCfg.Docker.ExcludePaths, "/var", ".git", "node_modules", ".idea") | ||
|
||
if err := os.WriteFile(".dockerignore", []byte(strings.Join(shopCfg.Docker.ExcludePaths, "\n")), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
return runTransparentCommand(exec.CommandContext(cmd.Context(), "docker", "build", "-t", args[0], ".")) | ||
}, | ||
} | ||
|
||
func init() { | ||
dockerRootCmd.AddCommand(dockerBuildCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#syntax=docker/dockerfile:1.4 | ||
|
||
# pin versions | ||
FROM shopware/docker-base:{{.PHP.PhpVersion}} as base-image | ||
FROM ghcr.io/friendsofshopware/shopware-cli:latest-php-{{.PHP.PhpVersion}} as shopware-cli | ||
|
||
FROM base-image as base-extended | ||
|
||
USER root | ||
|
||
{{- if .PHP.Extensions }} | ||
RUN /usr/local/bin/install-php-extensions {{- range $key, $value := .PHP.Extensions }} {{$value}} {{- end }} | ||
{{- end }} | ||
{{- if .PHP.Settings }} | ||
|
||
COPY <<EOF /usr/local/etc/php/conf.d/99-z-custom.ini | ||
{{- range $key, $value := .PHP.Settings }} | ||
|
||
{{$key}} = {{$value}} | ||
|
||
{{- end }} | ||
EOF | ||
|
||
{{- end }} | ||
|
||
USER 1000 | ||
|
||
FROM shopware-cli as build | ||
|
||
ADD . /src | ||
WORKDIR /src | ||
|
||
RUN --mount=type=secret,id=composer_auth,dst=/src/auth.json \ | ||
--mount=type=cache,target=/root/.composer \ | ||
--mount=type=cache,target=/root/.npm \ | ||
/usr/local/bin/entrypoint.sh shopware-cli project ci /src | ||
|
||
FROM base-extended | ||
|
||
COPY --from=build --chown=www-data --link /src /var/www/html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters