Skip to content

Commit 111cf49

Browse files
committed
fix: make lockfiles optional and improve build flexibility
**Lockfile Changes:** - npm: Replace 'npm ci' with 'npm install --no-audit --prefer-offline' - yarn: Use 'yarn.lock*' wildcard and remove '--frozen-lockfile' - pnpm: Use 'pnpm-lock.yaml*' wildcard and remove '--frozen-lockfile' - pipenv: Remove '--deploy' flag to allow builds without Pipfile.lock - gradle: Use 'settings.gradle.kts*' wildcard for single-module projects **Build Robustness Improvements:** - Next.js: Ensure public directory exists in builder stage - Spring Boot: Improve JAR file selection logic with fallback - Kotlin Spring Boot: Improve JAR file selection logic with fallback - Django/FastAPI: Simplify Python package copying to avoid version mismatch Allow builds without lockfiles for maximum flexibility while still using lockfiles when available for reproducible builds. Affected templates: - Frontend: React, Next.js, Vue.js - Backend Node.js: Express.js, NestJS - Backend Python: Django, FastAPI, Flask - Backend JVM: Spring Boot, Kotlin Spring Boot LP-492
1 parent d3cc40b commit 111cf49

10 files changed

Lines changed: 44 additions & 48 deletions

File tree

templates/django/template.tmpl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN poetry config virtualenvs.create false && poetry install --only main --no-ro
1212
{{ else }}
1313
RUN pip install --no-cache-dir pipenv
1414
COPY Pipfile Pipfile.lock* ./
15-
RUN pipenv install --system --deploy && pip install --no-cache-dir {{ .wsgi_server }}
15+
RUN pipenv install --system && pip install --no-cache-dir {{ .wsgi_server }}
1616
{{ end }}
1717

1818
FROM python:{{ .python_version }}-slim
@@ -21,11 +21,8 @@ WORKDIR /app
2121

2222
{{ if eq .dependency_manager "pip" }}
2323
COPY --from=builder /root/.local /usr/local
24-
{{ else if eq .dependency_manager "poetry" }}
25-
COPY --from=builder /usr/local/lib/python{{ .python_version }}/site-packages /usr/local/lib/python{{ .python_version }}/site-packages
26-
COPY --from=builder /usr/local/bin /usr/local/bin
2724
{{ else }}
28-
COPY --from=builder /usr/local/lib/python{{ .python_version }}/site-packages /usr/local/lib/python{{ .python_version }}/site-packages
25+
COPY --from=builder /usr/local/lib /usr/local/lib
2926
COPY --from=builder /usr/local/bin /usr/local/bin
3027
{{ end }}
3128

templates/expressjs/template.tmpl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ WORKDIR /app
55
{{ if eq .package_manager "npm" }}
66
COPY package*.json ./
77
{{ else if eq .package_manager "yarn" }}
8-
COPY package.json yarn.lock ./
8+
COPY package.json yarn.lock* ./
99
{{ else }}
10-
COPY package.json pnpm-lock.yaml ./
10+
COPY package.json pnpm-lock.yaml* ./
1111
RUN npm install -g pnpm
1212
{{ end }}
1313

1414
{{ if eq .node_env "production" }}
1515
{{ if eq .package_manager "npm" }}
16-
RUN npm ci --only=production
16+
RUN npm install --only=production --no-audit --prefer-offline
1717
{{ else if eq .package_manager "yarn" }}
18-
RUN yarn install --production --frozen-lockfile
18+
RUN yarn install --production
1919
{{ else }}
20-
RUN pnpm install --prod --frozen-lockfile
20+
RUN pnpm install --prod
2121
{{ end }}
2222
{{ else }}
2323
{{ if eq .package_manager "npm" }}
24-
RUN npm ci
24+
RUN npm install --no-audit --prefer-offline
2525
{{ else if eq .package_manager "yarn" }}
26-
RUN yarn install --frozen-lockfile
26+
RUN yarn install
2727
{{ else }}
28-
RUN pnpm install --frozen-lockfile
28+
RUN pnpm install
2929
{{ end }}
3030
{{ end }}
3131

templates/fastapi/template.tmpl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN poetry config virtualenvs.create false && poetry install --only main --no-ro
1212
{{ else }}
1313
RUN pip install --no-cache-dir pipenv
1414
COPY Pipfile Pipfile.lock* ./
15-
RUN pipenv install --system --deploy && pip install --no-cache-dir {{ .asgi_server }}
15+
RUN pipenv install --system && pip install --no-cache-dir {{ .asgi_server }}
1616
{{ end }}
1717

1818
FROM python:{{ .python_version }}-slim
@@ -24,11 +24,8 @@ RUN addgroup --system --gid 1001 app && \
2424

2525
{{ if eq .dependency_manager "pip" }}
2626
COPY --from=builder /root/.local /usr/local
27-
{{ else if eq .dependency_manager "poetry" }}
28-
COPY --from=builder /usr/local/lib/python{{ .python_version }}/site-packages /usr/local/lib/python{{ .python_version }}/site-packages
29-
COPY --from=builder /usr/local/bin /usr/local/bin
3027
{{ else }}
31-
COPY --from=builder /usr/local/lib/python{{ .python_version }}/site-packages /usr/local/lib/python{{ .python_version }}/site-packages
28+
COPY --from=builder /usr/local/lib /usr/local/lib
3229
COPY --from=builder /usr/local/bin /usr/local/bin
3330
{{ end }}
3431

templates/flask/template.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN poetry config virtualenvs.create false && poetry install --only main --no-ro
1212
{{ else }}
1313
RUN pip install --no-cache-dir pipenv
1414
COPY Pipfile Pipfile.lock* ./
15-
RUN pipenv install --system --deploy && pip install --no-cache-dir {{ .wsgi_server }}
15+
RUN pipenv install --system && pip install --no-cache-dir {{ .wsgi_server }}
1616
{{ end }}
1717

1818
COPY . .

templates/kotlin-spring-boot/template.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ FROM gradle:{{ .gradle_version }}-jdk{{ .java_version }}-alpine AS build
22

33
WORKDIR /app
44

5-
COPY build.gradle.kts settings.gradle.kts ./
5+
COPY build.gradle.kts settings.gradle.kts* ./
66

77
RUN gradle dependencies --no-daemon
88

99
COPY src ./src
1010

1111
RUN gradle clean build -x test --no-daemon
1212

13-
RUN cp build/libs/*[!n].jar app.jar
13+
RUN cp $(find build/libs -name "*[!n].jar" -type f | head -n 1) app.jar 2>/dev/null || cp build/libs/*.jar app.jar
1414
1515
FROM eclipse-temurin:{{ .java_version }}-jre-alpine
1616

templates/nestjs/template.tmpl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ WORKDIR /app
44

55
{{ if eq .package_manager "npm" }}
66
COPY package*.json ./
7-
RUN npm ci
7+
RUN npm install --no-audit --prefer-offline
88
{{ else if eq .package_manager "yarn" }}
9-
COPY package.json yarn.lock ./
10-
RUN yarn install --frozen-lockfile
9+
COPY package.json yarn.lock* ./
10+
RUN yarn install
1111
{{ else }}
12-
COPY package.json pnpm-lock.yaml ./
13-
RUN npm install -g pnpm && pnpm install --frozen-lockfile
12+
COPY package.json pnpm-lock.yaml* ./
13+
RUN npm install -g pnpm && pnpm install
1414
{{ end }}
1515

1616
COPY . .
@@ -29,13 +29,13 @@ WORKDIR /app
2929

3030
{{ if eq .package_manager "npm" }}
3131
COPY package*.json ./
32-
RUN npm ci --only=production
32+
RUN npm install --only=production --no-audit --prefer-offline
3333
{{ else if eq .package_manager "yarn" }}
34-
COPY package.json yarn.lock ./
35-
RUN yarn install --production --frozen-lockfile
34+
COPY package.json yarn.lock* ./
35+
RUN yarn install --production
3636
{{ else }}
37-
COPY package.json pnpm-lock.yaml ./
38-
RUN npm install -g pnpm && pnpm install --prod --frozen-lockfile
37+
COPY package.json pnpm-lock.yaml* ./
38+
RUN npm install -g pnpm && pnpm install --prod
3939
{{ end }}
4040

4141
COPY --from=builder /app/dist ./dist

templates/nextjs/template.tmpl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ WORKDIR /app
44

55
{{ if eq .package_manager "npm" }}
66
COPY package*.json ./
7-
RUN npm ci
7+
RUN npm install --no-audit --prefer-offline
88
{{ else if eq .package_manager "yarn" }}
9-
COPY package.json yarn.lock ./
10-
RUN yarn install --frozen-lockfile
9+
COPY package.json yarn.lock* ./
10+
RUN yarn install
1111
{{ else }}
12-
COPY package.json pnpm-lock.yaml ./
13-
RUN npm install -g pnpm && pnpm install --frozen-lockfile
12+
COPY package.json pnpm-lock.yaml* ./
13+
RUN npm install -g pnpm && pnpm install
1414
{{ end }}
1515

1616
FROM node:{{ .node_version }}-alpine AS builder
@@ -24,6 +24,8 @@ RUN npm install -g pnpm
2424
COPY --from=deps /app/node_modules ./node_modules
2525
COPY . .
2626

27+
RUN mkdir -p public
28+
2729
{{ if eq .package_manager "npm" }}
2830
RUN npm run build
2931
{{ else if eq .package_manager "yarn" }}

templates/react/template.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ WORKDIR /app
44

55
{{ if eq .package_manager "npm" }}
66
COPY package*.json ./
7-
RUN npm ci
7+
RUN npm install --no-audit --prefer-offline
88
{{ else if eq .package_manager "yarn" }}
9-
COPY package.json yarn.lock ./
10-
RUN yarn install --frozen-lockfile
9+
COPY package.json yarn.lock* ./
10+
RUN yarn install
1111
{{ else }}
12-
COPY package.json pnpm-lock.yaml ./
13-
RUN npm install -g pnpm && pnpm install --frozen-lockfile
12+
COPY package.json pnpm-lock.yaml* ./
13+
RUN npm install -g pnpm && pnpm install
1414
{{ end }}
1515

1616
COPY . .

templates/spring-boot/template.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ COPY src ./src
1313
RUN mvn clean package -DskipTests
1414
RUN cp target/*.jar app.jar
1515
{{ else }}
16-
COPY build.gradle.kts settings.gradle.kts ./
16+
COPY build.gradle.kts settings.gradle.kts* ./
1717
RUN gradle dependencies --no-daemon
1818
COPY src ./src
1919
RUN gradle clean build -x test --no-daemon
20-
RUN cp build/libs/*[!n].jar app.jar
20+
RUN cp $(find build/libs -name "*[!n].jar" -type f | head -n 1) app.jar 2>/dev/null || cp build/libs/*.jar app.jar
2121
{{ end }}
2222
2323
FROM eclipse-temurin:{{ .java_version }}-jre-alpine

templates/vuejs/template.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ WORKDIR /app
33

44
{{ if eq .package_manager "npm" }}
55
COPY package*.json ./
6-
RUN npm ci
6+
RUN npm install --no-audit --prefer-offline
77
{{ else if eq .package_manager "yarn" }}
8-
COPY package.json yarn.lock ./
9-
RUN yarn install --frozen-lockfile
8+
COPY package.json yarn.lock* ./
9+
RUN yarn install
1010
{{ else }}
11-
COPY package.json pnpm-lock.yaml ./
12-
RUN npm install -g pnpm && pnpm install --frozen-lockfile
11+
COPY package.json pnpm-lock.yaml* ./
12+
RUN npm install -g pnpm && pnpm install
1313
{{ end }}
1414

1515
COPY . .

0 commit comments

Comments
 (0)