Unverified Commit 8d13ab92 authored by Sam Ko's avatar Sam Ko Committed by GitHub

chore(examples): switch default from yarn to npm in Dockerfiles (#61348)

## Changes

- Switch default package manager to npm
- Fixes https://github.com/vercel/next.js/issues/61293

Closes NEXT-2291
parent e6e95f42
...@@ -7,7 +7,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ ...@@ -7,7 +7,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \ elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \
# Allow install without lockfile, so example works even without Node.js installed locally # Allow install without lockfile, so example works even without Node.js installed locally
else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \
fi fi
...@@ -28,5 +28,5 @@ CMD \ ...@@ -28,5 +28,5 @@ CMD \
if [ -f yarn.lock ]; then yarn dev; \ if [ -f yarn.lock ]; then yarn dev; \
elif [ -f package-lock.json ]; then npm run dev; \ elif [ -f package-lock.json ]; then npm run dev; \
elif [ -f pnpm-lock.yaml ]; then pnpm dev; \ elif [ -f pnpm-lock.yaml ]; then pnpm dev; \
else yarn dev; \ else npm run dev; \
fi fi
...@@ -8,7 +8,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ ...@@ -8,7 +8,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \ elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \
# Allow install without lockfile, so example works even without Node.js installed locally # Allow install without lockfile, so example works even without Node.js installed locally
else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \
fi fi
...@@ -36,7 +36,7 @@ RUN \ ...@@ -36,7 +36,7 @@ RUN \
if [ -f yarn.lock ]; then yarn build; \ if [ -f yarn.lock ]; then yarn build; \
elif [ -f package-lock.json ]; then npm run build; \ elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then pnpm build; \ elif [ -f pnpm-lock.yaml ]; then pnpm build; \
else yarn build; \ else npm run build; \
fi fi
# Start Next.js based on the preferred package manager # Start Next.js based on the preferred package manager
...@@ -44,5 +44,5 @@ CMD \ ...@@ -44,5 +44,5 @@ CMD \
if [ -f yarn.lock ]; then yarn start; \ if [ -f yarn.lock ]; then yarn start; \
elif [ -f package-lock.json ]; then npm run start; \ elif [ -f package-lock.json ]; then npm run start; \
elif [ -f pnpm-lock.yaml ]; then pnpm start; \ elif [ -f pnpm-lock.yaml ]; then pnpm start; \
else yarn start; \ else npm run start; \
fi fi
...@@ -11,7 +11,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ ...@@ -11,7 +11,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \ elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \
# Allow install without lockfile, so example works even without Node.js installed locally # Allow install without lockfile, so example works even without Node.js installed locally
else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \
fi fi
...@@ -37,7 +37,7 @@ RUN \ ...@@ -37,7 +37,7 @@ RUN \
if [ -f yarn.lock ]; then yarn build; \ if [ -f yarn.lock ]; then yarn build; \
elif [ -f package-lock.json ]; then npm run build; \ elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then pnpm build; \ elif [ -f pnpm-lock.yaml ]; then pnpm build; \
else yarn build; \ else npm run build; \
fi fi
# Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here # Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here
......
...@@ -12,7 +12,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ ...@@ -12,7 +12,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \ elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \ else echo "Lockfile not found." && exit 1; \
fi fi
...@@ -23,7 +23,7 @@ COPY --from=deps /app/node_modules ./node_modules ...@@ -23,7 +23,7 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
# This will do the trick, use the corresponding env file for each environment. # This will do the trick, use the corresponding env file for each environment.
COPY .env.development.sample .env.production COPY .env.development.sample .env.production
RUN yarn build RUN npm run build
# 3. Production image, copy all the files and run next # 3. Production image, copy all the files and run next
FROM base AS runner FROM base AS runner
......
...@@ -12,7 +12,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ ...@@ -12,7 +12,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \ elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \ else echo "Lockfile not found." && exit 1; \
fi fi
...@@ -24,7 +24,7 @@ COPY --from=deps /app/node_modules ./node_modules ...@@ -24,7 +24,7 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
# This will do the trick, use the corresponding env file for each environment. # This will do the trick, use the corresponding env file for each environment.
COPY .env.production.sample .env.production COPY .env.production.sample .env.production
RUN yarn build RUN npm run build
# 3. Production image, copy all the files and run next # 3. Production image, copy all the files and run next
FROM base AS runner FROM base AS runner
......
...@@ -12,7 +12,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ ...@@ -12,7 +12,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \ elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \ else echo "Lockfile not found." && exit 1; \
fi fi
...@@ -24,7 +24,7 @@ COPY --from=deps /app/node_modules ./node_modules ...@@ -24,7 +24,7 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
# This will do the trick, use the corresponding env file for each environment. # This will do the trick, use the corresponding env file for each environment.
COPY .env.staging.sample .env.production COPY .env.staging.sample .env.production
RUN yarn build RUN npm run build
# 3. Production image, copy all the files and run next # 3. Production image, copy all the files and run next
FROM base AS runner FROM base AS runner
......
...@@ -11,7 +11,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ ...@@ -11,7 +11,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \ elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \ else echo "Lockfile not found." && exit 1; \
fi fi
...@@ -27,7 +27,7 @@ COPY . . ...@@ -27,7 +27,7 @@ COPY . .
# Uncomment the following line in case you want to disable telemetry during the build. # Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1 # ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build RUN npm run build
# If using npm comment out above and use below instead # If using npm comment out above and use below instead
# RUN npm run build # RUN npm run build
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment