Skip to content

Commit 8a005c9

Browse files
committed
refactor: add context to SetupTools and improve Docker container configuration
1 parent 01368bf commit 8a005c9

8 files changed

Lines changed: 31 additions & 7 deletions

File tree

Dockerfile.base

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ EOF
7171

7272
ENV SHOPWARE_CLI_TOOLS_DIR=/opt/verifier
7373

74-
7574
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
7675

7776
CMD ["sh"]

cmd/extension/extension_fix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var extensionFixCmd = &cobra.Command{
1717
Use: "fix",
1818
Short: "Fix an extension",
1919
PreRunE: func(cmd *cobra.Command, args []string) error {
20-
return verifier.SetupTools(cmd.Root().Version)
20+
return verifier.SetupTools(cmd.Context(), cmd.Root().Version)
2121
},
2222
RunE: func(cmd *cobra.Command, args []string) error {
2323
allowNonGit, _ := cmd.Flags().GetBool("allow-non-git")

cmd/extension/extension_format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var extensionFormat = &cobra.Command{
1616
Use: "format",
1717
Short: "Format an extension",
1818
PreRunE: func(cmd *cobra.Command, args []string) error {
19-
return verifier.SetupTools(cmd.Root().Version)
19+
return verifier.SetupTools(cmd.Context(), cmd.Root().Version)
2020
},
2121
RunE: func(cmd *cobra.Command, args []string) error {
2222
dryRun, _ := cmd.Flags().GetBool("dry-run")

cmd/extension/extension_validate.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/shopware/shopware-cli/extension"
1212
"github.com/shopware/shopware-cli/internal/system"
1313
"github.com/shopware/shopware-cli/internal/verifier"
14+
"github.com/shopware/shopware-cli/logging"
1415
)
1516

1617
var extensionValidateCmd = &cobra.Command{
@@ -49,8 +50,18 @@ var extensionValidateCmd = &cobra.Command{
4950
var toolCfg *verifier.ToolConfig
5051

5152
if stat.IsDir() {
52-
if err := system.CopyFiles(args[0], tmpDir); err != nil {
53-
return err
53+
if isFull {
54+
if err := system.CopyFiles(args[0], tmpDir); err != nil {
55+
return err
56+
}
57+
58+
defer func() {
59+
if err := os.RemoveAll(tmpDir); err != nil {
60+
logging.FromContext(cmd.Context()).Error("Failed to remove temporary directory:", err)
61+
}
62+
}()
63+
} else {
64+
tmpDir = args[0]
5465
}
5566

5667
ext, err := extension.GetExtensionByFolder(path)
@@ -126,6 +137,6 @@ func init() {
126137
return nil
127138
}
128139

129-
return verifier.SetupTools("latest")
140+
return verifier.SetupTools(cmd.Context(), cmd.Root().Version)
130141
}
131142
}

cmd/project/project_fix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
var projectFixCmd = &cobra.Command{
1515
Use: "fix",
1616
Short: "Fix project",
17+
PreRunE: func(cmd *cobra.Command, args []string) error {
18+
return verifier.SetupTools(cmd.Context(), cmd.Root().Version)
19+
},
1720
RunE: func(cmd *cobra.Command, args []string) error {
1821
allowNonGit, _ := cmd.Flags().GetBool("allow-non-git")
1922
gitPath := filepath.Join(args[0], ".git")

cmd/project/project_format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
var projectFormatCmd = &cobra.Command{
1414
Use: "format",
1515
Short: "Format project",
16+
PreRunE: func(cmd *cobra.Command, args []string) error {
17+
return verifier.SetupTools(cmd.Context(), cmd.Root().Version)
18+
},
1619
RunE: func(cmd *cobra.Command, args []string) error {
1720
var err error
1821
only, _ := cmd.Flags().GetString("only")

cmd/project/project_validate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515
var projectValidateCmd = &cobra.Command{
1616
Use: "validate",
1717
Short: "Validate project",
18+
PreRunE: func(cmd *cobra.Command, args []string) error {
19+
return verifier.SetupTools(cmd.Context(), cmd.Root().Version)
20+
},
1821
RunE: func(cmd *cobra.Command, args []string) error {
1922
reportingFormat, _ := cmd.Flags().GetString("reporter")
2023
only, _ := cmd.Flags().GetString("only")

internal/verifier/embed.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package verifier
22

33
import (
4+
"context"
45
"embed"
56
"fmt"
67
"log"
@@ -9,14 +10,16 @@ import (
910
"path"
1011

1112
"github.com/shopware/shopware-cli/internal/system"
13+
"github.com/shopware/shopware-cli/logging"
1214
)
1315

1416
//go:embed php/composer.json php/composer.lock php/configs js/configs js/packages js/package*.json
1517
var toolsFS embed.FS
1618

17-
func SetupTools(currentVersion string) error {
19+
func SetupTools(ctx context.Context, currentVersion string) error {
1820
customToolDir := os.Getenv("SHOPWARE_CLI_TOOLS_DIR")
1921
if customToolDir != "" {
22+
logging.FromContext(ctx).Debugf("Using custom tool directory: %s", customToolDir)
2023
setToolDirectory(customToolDir)
2124
return nil
2225
}
@@ -25,10 +28,12 @@ func SetupTools(currentVersion string) error {
2528
toolsDir := path.Join(cacheDir, "tools", currentVersion)
2629

2730
if _, err := os.Stat(toolsDir); err == nil {
31+
logging.FromContext(ctx).Debugf("Using cached tool directory: %s", toolsDir)
2832
setToolDirectory(toolsDir)
2933
return nil
3034
}
3135

36+
logging.FromContext(ctx).Debugf("Using tool directory: %s", toolsDir)
3237
if err := os.MkdirAll(toolsDir, os.ModePerm); err != nil {
3338
return fmt.Errorf("failed to create directory %s: %w", toolsDir, err)
3439
}

0 commit comments

Comments
 (0)