Skip to content

Commit ddc7a5c

Browse files
authored
fix: enable corepack by default, set explicit corepack home directory (#20)
1 parent f7f9417 commit ddc7a5c

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
/dist/
33
.idea/
4+
tmp/

runtime/node.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (d *Node) GenerateDockerfile(path string) ([]byte, error) {
7676
installCMD = "yarn --frozen-lockfile"
7777
packageManager = "yarn"
7878
} else if _, err := os.Stat(filepath.Join(path, "pnpm-lock.yaml")); err == nil {
79-
installCMD = "corepack enable pnpm && pnpm i --frozen-lockfile"
79+
installCMD = "pnpm i --frozen-lockfile"
8080
packageManager = "pnpm"
8181
}
8282

@@ -167,6 +167,7 @@ var startScriptRe = regexp.MustCompile(`^.*?\b(ts-)?node(mon)?\b.*?(index|main|s
167167
var nodeTemplate = strings.TrimSpace(`
168168
ARG VERSION={{.Version}}
169169
FROM node:${VERSION}-slim AS base
170+
RUN corepack enable
170171
171172
FROM base AS deps
172173
WORKDIR /app
@@ -188,7 +189,9 @@ FROM base AS runtime
188189
WORKDIR /app
189190
190191
RUN apt-get update && apt-get install -y --no-install-recommends wget && apt-get clean && rm -f /var/lib/apt/lists/*_*
191-
RUN addgroup --system nonroot && adduser --system --ingroup nonroot nonroot
192+
RUN addgroup --system nonroot && adduser --disabled-login --ingroup nonroot nonroot
193+
ENV COREPACK_HOME=/app/.cache
194+
RUN mkdir -p /app/.cache
192195
RUN chown -R nonroot:nonroot /app
193196
194197
COPY --chown=nonroot:nonroot --from=builder /app .

runtime/node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestNodeGenerateDockerfile(t *testing.T) {
6060
{
6161
name: "Node project with pnpm",
6262
path: "../testdata/node-pnpm",
63-
expected: []any{`ARG VERSION=16.0.0`, `ARG INSTALL_CMD="corepack enable pnpm && pnpm i --frozen-lockfile"`, `ARG BUILD_CMD="pnpm run build:prod"`, `ARG START_CMD="pnpm run start:production"`},
63+
expected: []any{`ARG VERSION=16.0.0`, `ARG INSTALL_CMD="pnpm i --frozen-lockfile"`, `ARG BUILD_CMD="pnpm run build:prod"`, `ARG START_CMD="pnpm run start:production"`},
6464
},
6565
{
6666
name: "Node project with yarn",

runtime/php.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ func (d *PHP) GenerateDockerfile(path string) ([]byte, error) {
102102
buildCommands := []string{"build:prod", "build:production", "build-prod", "build-production", "build"}
103103
for _, cmd := range buildCommands {
104104
if _, ok := scripts[cmd].(string); ok {
105-
buildCMD = fmt.Sprintf("%s run %s", packageManager, cmd)
105+
corepack := ""
106+
if packageManager == "pnpm" {
107+
corepack = "corepack enable pnpm &&"
108+
}
109+
buildCMD = fmt.Sprintf("%s%s run %s", corepack, packageManager, cmd)
106110
d.Log.Info("Detected build command in package.json: " + buildCMD)
107111
break
108112
}

0 commit comments

Comments
 (0)