Unverified Commit b7997105 authored by Duc Tran's avatar Duc Tran Committed by GitHub

fix: use `if...else` in dockerfile (#39263)

* fix: use if-else in dockerfile

* fix: remove typo
parent cd3e054f
...@@ -5,9 +5,11 @@ WORKDIR /app ...@@ -5,9 +5,11 @@ WORKDIR /app
# Install dependencies based on the preferred package manager # Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \ RUN \
[ -f package-lock.json ] && npm install || \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
[ -f pnpm-lock.yaml ] && yarn global add pnpm && pnpm install || \ elif [ -f package-lock.json ]; then npm ci; \
yarn install elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \
fi
COPY src ./src COPY src ./src
COPY public ./public COPY public ./public
......
...@@ -6,7 +6,7 @@ WORKDIR /app ...@@ -6,7 +6,7 @@ WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
# Omit --production flag for TypeScript devDependencies # Omit --production flag for TypeScript devDependencies
RUN \ RUN \
if [ -f yarn.lock ]; then yarn install --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 yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \ else echo "Lockfile not found." && exit 1; \
......
...@@ -7,7 +7,7 @@ WORKDIR /app ...@@ -7,7 +7,7 @@ WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
# Omit --production flag for TypeScript devDependencies # Omit --production flag for TypeScript devDependencies
RUN \ RUN \
if [ -f yarn.lock ]; then yarn install --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 yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \ else echo "Lockfile not found." && exit 1; \
......
...@@ -8,10 +8,10 @@ WORKDIR /app ...@@ -8,10 +8,10 @@ WORKDIR /app
# Install dependencies based on the preferred package manager # Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ 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 yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1;\ else echo "Lockfile not found." && exit 1; \
fi fi
# 2. Rebuild the source code only when needed # 2. Rebuild the source code only when needed
......
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