Skip to content

Commit

Permalink
fix: enable corepack by default, set explicit corepack home directory (
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredLunde authored May 21, 2024
1 parent f7f9417 commit ddc7a5c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
/dist/
.idea/
tmp/
7 changes: 5 additions & 2 deletions runtime/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *Node) GenerateDockerfile(path string) ([]byte, error) {
installCMD = "yarn --frozen-lockfile"
packageManager = "yarn"
} else if _, err := os.Stat(filepath.Join(path, "pnpm-lock.yaml")); err == nil {
installCMD = "corepack enable pnpm && pnpm i --frozen-lockfile"
installCMD = "pnpm i --frozen-lockfile"
packageManager = "pnpm"
}

Expand Down Expand Up @@ -167,6 +167,7 @@ var startScriptRe = regexp.MustCompile(`^.*?\b(ts-)?node(mon)?\b.*?(index|main|s
var nodeTemplate = strings.TrimSpace(`
ARG VERSION={{.Version}}
FROM node:${VERSION}-slim AS base
RUN corepack enable
FROM base AS deps
WORKDIR /app
Expand All @@ -188,7 +189,9 @@ FROM base AS runtime
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends wget && apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN addgroup --system nonroot && adduser --system --ingroup nonroot nonroot
RUN addgroup --system nonroot && adduser --disabled-login --ingroup nonroot nonroot
ENV COREPACK_HOME=/app/.cache
RUN mkdir -p /app/.cache
RUN chown -R nonroot:nonroot /app
COPY --chown=nonroot:nonroot --from=builder /app .
Expand Down
2 changes: 1 addition & 1 deletion runtime/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestNodeGenerateDockerfile(t *testing.T) {
{
name: "Node project with pnpm",
path: "../testdata/node-pnpm",
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"`},
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"`},
},
{
name: "Node project with yarn",
Expand Down
6 changes: 5 additions & 1 deletion runtime/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func (d *PHP) GenerateDockerfile(path string) ([]byte, error) {
buildCommands := []string{"build:prod", "build:production", "build-prod", "build-production", "build"}
for _, cmd := range buildCommands {
if _, ok := scripts[cmd].(string); ok {
buildCMD = fmt.Sprintf("%s run %s", packageManager, cmd)
corepack := ""
if packageManager == "pnpm" {
corepack = "corepack enable pnpm &&"
}
buildCMD = fmt.Sprintf("%s%s run %s", corepack, packageManager, cmd)
d.Log.Info("Detected build command in package.json: " + buildCMD)
break
}
Expand Down

0 comments on commit ddc7a5c

Please sign in to comment.