Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(internal): Improve docker build performance #5839

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
13 changes: 7 additions & 6 deletions generators/csharp/model/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
FROM node:20.18-alpine3.20 AS node
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine3.18
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine3.21

RUN apk --no-cache add bash curl git zip && git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

RUN dotnet tool install -g csharpier
ENV PATH="$PATH:/root/.dotnet/tools"
ENV YARN_CACHE_FOLDER=/.yarn
ENV PATH="$PATH:/root/.dotnet/tools"

COPY generators/csharp/model/dist /dist
RUN apk --no-cache add bash curl git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"
RUN dotnet tool install -g csharpier

# Copy over node contents to be able to run the compiled CLI
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx

COPY generators/csharp/model/dist /dist

ENTRYPOINT ["node", "/dist/cli.cjs"]
2 changes: 2 additions & 0 deletions generators/csharp/model/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!generators/csharp/model/dist
15 changes: 8 additions & 7 deletions generators/csharp/sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
FROM node:20.18-alpine3.20 AS node
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine3.18
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine3.21

RUN apk --no-cache add bash curl git zip && git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

RUN dotnet tool install -g csharpier
ENV PATH="$PATH:/root/.dotnet/tools"
ENV YARN_CACHE_FOLDER=/.yarn
ENV PATH="$PATH:/root/.dotnet/tools"

COPY generators/csharp/sdk/dist /dist
COPY generators/csharp/sdk/features.yml /assets/features.yml
RUN apk --no-cache add bash curl git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"
RUN dotnet tool install -g csharpier

# Copy over node contents to be able to run the compiled CLI
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx

COPY generators/csharp/sdk/features.yml /assets/features.yml
COPY generators/csharp/sdk/dist /dist

ENTRYPOINT ["node", "/dist/cli.cjs", "csharp-sdk"]
3 changes: 3 additions & 0 deletions generators/csharp/sdk/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!generators/csharp/sdk/features.yml
!generators/csharp/sdk/dist
6 changes: 6 additions & 0 deletions generators/go/fiber/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!go.mod
!go.sum
!cmd
!internal
!version.go
6 changes: 6 additions & 0 deletions generators/go/model/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!go.mod
!go.sum
!cmd
!internal
!version.go
6 changes: 3 additions & 3 deletions generators/go/sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Stage 1: Build Node CLI
FROM node:20.18-alpine3.20 AS node

RUN apk --no-cache add git zip \
&& git config --global user.name "fern" \
&& git config --global user.email "hey@buildwithfern.com"
RUN apk --no-cache add git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

COPY generators/go-v2/sdk/dist/cli.cjs /dist/cli.cjs

Expand All @@ -13,6 +12,7 @@ FROM golang:1.22.7-alpine3.19
WORKDIR /workspace

RUN apk add --no-cache ca-certificates git nodejs
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

COPY generators/go/go.mod generators/go/go.sum /workspace/
RUN go mod download
Expand Down
7 changes: 7 additions & 0 deletions generators/go/sdk/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
!generators/go-v2/sdk/dist/cli.cjs
!generators/go/go.mod
!generators/go/go.sum
!generators/go/cmd
!generators/go/internal
!generators/go/version.go
3 changes: 3 additions & 0 deletions generators/java/model/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!build/distributions/model.tar
!init.sh
3 changes: 3 additions & 0 deletions generators/java/sdk/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!build/distributions/sdk.tar
!init.sh
3 changes: 3 additions & 0 deletions generators/java/spring/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!build/distributions/spring.tar
!init.sh
2 changes: 2 additions & 0 deletions generators/openapi/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!dist
12 changes: 7 additions & 5 deletions generators/php/model/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
FROM node:20.18-alpine3.20 AS node
FROM composer:2.7.9

RUN apk --no-cache add bash curl git zip && git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

RUN curl -L https://cs.symfony.com/download/php-cs-fixer-v3.phar -o /usr/local/bin/php-cs-fixer \
&& chmod +x /usr/local/bin/php-cs-fixer
ENV YARN_CACHE_FOLDER=/.yarn

COPY generators/php/model/dist /dist
RUN apk --no-cache add bash curl git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

# Copy over node contents to be able to run the compiled CLI
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx

RUN curl -L https://cs.symfony.com/download/php-cs-fixer-v3.phar -o /usr/local/bin/php-cs-fixer \
&& chmod +x /usr/local/bin/php-cs-fixer

COPY generators/php/model/dist /dist

ENTRYPOINT ["node", "/dist/cli.cjs"]
2 changes: 2 additions & 0 deletions generators/php/model/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!generators/php/model/dist
14 changes: 8 additions & 6 deletions generators/php/sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
FROM node:20.18-alpine3.20 AS node
FROM composer:2.7.9

RUN apk --no-cache add bash curl git zip && git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

RUN curl -L https://cs.symfony.com/download/php-cs-fixer-v3.phar -o /usr/local/bin/php-cs-fixer \
&& chmod +x /usr/local/bin/php-cs-fixer
ENV YARN_CACHE_FOLDER=/.yarn

COPY generators/php/sdk/dist /dist
COPY generators/php/sdk/features.yml /assets/features.yml
RUN apk --no-cache add bash curl git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

# Copy over node contents to be able to run the compiled CLI
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx

RUN curl -L https://cs.symfony.com/download/php-cs-fixer-v3.phar -o /usr/local/bin/php-cs-fixer \
&& chmod +x /usr/local/bin/php-cs-fixer

COPY generators/php/sdk/features.yml /assets/features.yml
COPY generators/php/sdk/dist /dist

ENTRYPOINT ["node", "/dist/cli.cjs"]
3 changes: 3 additions & 0 deletions generators/php/sdk/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!generators/php/sdk/features.yml
!generators/php/sdk/dist
2 changes: 2 additions & 0 deletions generators/postman/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!dist
2 changes: 2 additions & 0 deletions generators/python-v2/fastapi/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!generators/python-v2/fastapi/dist
2 changes: 2 additions & 0 deletions generators/python-v2/pydantic-model/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!generators/python-v2/pydantic-model/dist
13 changes: 8 additions & 5 deletions generators/python/fastapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ FROM python:3.9.14
ENV PYTHONPATH=${PYTHONPATH}:${PWD}
ENV _TYPER_STANDARD_TRACEBACK=1

RUN pip3 install poetry==1.8.5
RUN poetry config virtualenvs.create false

COPY pyproject.toml ./pyproject.toml
COPY poetry.lock ./poetry.lock
COPY ./core_utilities/fastapi /assets/core_utilities
COPY ./core_utilities/shared /assets/core_utilities
COPY ./src/__init__.py ./src/__init__.py
COPY ./src/fern_python/__init__.py ./src/fern_python/__init__.py

RUN pip3 install poetry==1.8.5 &&\
poetry config virtualenvs.create false &&\
poetry install
RUN poetry install

COPY ./core_utilities/fastapi /assets/core_utilities
COPY ./core_utilities/shared /assets/core_utilities
COPY ./src ./src

RUN poetry install
Expand Down
6 changes: 6 additions & 0 deletions generators/python/fastapi/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!pyproject.toml
!poetry.lock
!./core_utilities/fastapi
!./core_utilities/shared
!./src
13 changes: 8 additions & 5 deletions generators/python/pydantic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ FROM python:3.9.14
ENV PYTHONPATH=${PYTHONPATH}:${PWD}
ENV _TYPER_STANDARD_TRACEBACK=1

RUN pip3 install poetry==1.8.5
RUN poetry config virtualenvs.create false

COPY pyproject.toml ./pyproject.toml
COPY poetry.lock ./poetry.lock
COPY ./core_utilities/pydantic /assets/core_utilities
COPY ./core_utilities/shared /assets/core_utilities
COPY ./src/__init__.py ./src/__init__.py
COPY ./src/fern_python/__init__.py ./src/fern_python/__init__.py

RUN pip3 install poetry==1.8.5 &&\
poetry config virtualenvs.create false &&\
poetry install
RUN poetry install

COPY ./core_utilities/pydantic /assets/core_utilities
COPY ./core_utilities/shared /assets/core_utilities
COPY ./src ./src

RUN poetry install
Expand Down
6 changes: 6 additions & 0 deletions generators/python/pydantic/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!pyproject.toml
!poetry.lock
!./core_utilities/pydantic
!./core_utilities/shared
!./src
26 changes: 9 additions & 17 deletions generators/python/sdk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,21 @@ ENV PYTHONPATH=${PYTHONPATH}:${PWD}
ENV _TYPER_STANDARD_TRACEBACK=1
ENV HTTPX_LOG_LEVEL=trace

RUN pip3 install poetry==1.8.5
RUN poetry config virtualenvs.create false

COPY pyproject.toml ./pyproject.toml
COPY poetry.lock ./poetry.lock
COPY ./src/__init__.py ./src/__init__.py
COPY ./src/fern_python/__init__.py ./src/fern_python/__init__.py

RUN poetry install

COPY ./core_utilities/sdk /assets/core_utilities
COPY ./core_utilities/shared /assets/core_utilities
COPY ./sdk/features.yml /assets/features.yml
COPY ./tests /assets/tests

RUN pip3 install poetry==1.8.5 &&\
poetry config virtualenvs.create false &&\
poetry install

COPY ./src ./src

RUN poetry install

ENTRYPOINT ["python", "-m", "src.fern_python.generators.sdk.cli"]

## NOTE: Uncomment the below to generate a flame graph for the python generator.
## To visualize the flamegraph you can run:
## - poetry add snakeviz
## - poetry run snakeviz output.prof
# RUN mkdir -p /fern/output
## For a time-limited run, uncomment the below line and comment the next line.
# ENTRYPOINT ["timeout", "-s", "INT", "5m", "python", "-m", "cProfile", "-o", "/fern/output/output.prof", "/src/fern_python/generators/sdk/cli.py"]
## For a regularly profiled run, uncomment the below line and comment the previous line.
# ENTRYPOINT ["python", "-m", "cProfile", "-o", "/fern/output/output.prof", "/src/fern_python/generators/sdk/cli.py"]
ENTRYPOINT ["python", "-m", "src.fern_python.generators.sdk.cli"]
8 changes: 8 additions & 0 deletions generators/python/sdk/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*
!pyproject.toml
!poetry.lock
!./sdk/features.yml
!./core_utilities/sdk
!./core_utilities/shared
!./tests
!./src
3 changes: 3 additions & 0 deletions generators/ruby/model/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!packages/generators/docker/cache_heavy_deps.sh
!generators/ruby/model/dist
4 changes: 2 additions & 2 deletions generators/ruby/sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# syntax = edrevo/dockerfile-plus
INCLUDE+ packages/generators/docker/Dockerfile.base

COPY generators/ruby/sdk/dist /dist

# Install Ruby and Rubocop for formatting
RUN apk update && apk add --no-cache build-base ruby ruby-dev && gem install rubocop

COPY generators/ruby/sdk/dist /dist

ENTRYPOINT ["node", "/dist/cli.cjs", "ruby-sdk"]
3 changes: 3 additions & 0 deletions generators/ruby/sdk/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!packages/generators/docker/cache_heavy_deps.sh
!generators/ruby/sdk/dist
10 changes: 5 additions & 5 deletions generators/typescript/express/cli/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM node:20.18-alpine3.20

RUN apk --no-cache add git zip \
&& git config --global user.name "fern" \
&& git config --global user.email "hey@buildwithfern.com"

ENV YARN_CACHE_FOLDER=/.yarn

RUN apk --no-cache add git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

COPY generators/typescript/express/cli/docker/cache_heavy_dependencies.sh /
RUN /cache_heavy_dependencies.sh && rm /cache_heavy_dependencies.sh
RUN /cache_heavy_dependencies.sh
RUN rm /cache_heavy_dependencies.sh

COPY generators/typescript/asIs/ /assets/asIs
COPY generators/typescript/utils/core-utilities/zurg/src/ /assets/zurg
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!generators/typescript/express/cli/docker/cache_heavy_dependencies.sh
!generators/typescript/asIs/
!generators/typescript/utils/core-utilities/zurg/src/
!generators/typescript/utils/core-utilities/base/src/
!generators/typescript/express/cli/docker/dist/cli.cjs
8 changes: 4 additions & 4 deletions generators/typescript/sdk/cli/browser-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM node:20.18-alpine3.20

RUN apk --no-cache add git zip \
&& git config --global user.name "fern" \
&& git config --global user.email "hey@buildwithfern.com"
RUN apk --no-cache add git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

ENV YARN_CACHE_FOLDER=/.yarn

COPY generators/typescript/sdk/cli/browser-docker/cache_heavy_dependencies.sh /
RUN /cache_heavy_dependencies.sh && rm /cache_heavy_dependencies.sh
RUN /cache_heavy_dependencies.sh
RUN rm /cache_heavy_dependencies.sh

COPY generators/typescript/asIs/ /assets/asIs
COPY generators/typescript/utils/core-utilities/fetcher/src/ /assets/fetcher
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*
!generators/typescript/sdk/cli/browser-docker/cache_heavy_dependencies.sh
!generators/typescript/asIs/
!generators/typescript/utils/core-utilities/fetcher/src/
!generators/typescript/utils/core-utilities/callback-queue/src/
!generators/typescript/utils/core-utilities/auth/src/
!generators/typescript/utils/core-utilities/zurg/src/
!generators/typescript/utils/core-utilities/base/src/
!generators/typescript/utils/core-utilities/utils/src/
!generators/typescript/utils/scripts/
!generators/typescript/sdk/cli/browser-docker/dist/browserCli.cjs
5 changes: 2 additions & 3 deletions generators/typescript/sdk/cli/node-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM node:20.18-alpine3.20

RUN apk --no-cache add git zip \
&& git config --global user.name "fern" \
&& git config --global user.email "hey@buildwithfern.com"
RUN apk --no-cache add git zip
RUN git config --global user.name "fern" && git config --global user.email "hey@buildwithfern.com"

RUN yarn init --yes

Expand Down
Loading
Loading