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

(docker): Install node in every generator image #3778

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generators/csharp/model/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:18-alpine3.18 AS node
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine3.18

RUN apk --no-cache add bash curl git zip && git config --global user.name "fern" && git config --global user.email "[email protected]"
RUN apk --no-cache add bash curl git libstdc++6 libstdc++ zip && git config --global user.name "fern" && git config --global user.email "[email protected]"

RUN dotnet tool install -g csharpier
ENV PATH="$PATH:/root/.dotnet/tools"
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:18-alpine3.18 AS node
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine3.18

RUN apk --no-cache add bash curl git zip && git config --global user.name "fern" && git config --global user.email "[email protected]"
RUN apk --no-cache add bash curl git libstdc++6 libstdc++ zip && git config --global user.name "fern" && git config --global user.email "[email protected]"

RUN dotnet tool install -g csharpier
ENV PATH="$PATH:/root/.dotnet/tools"
Expand Down
9 changes: 8 additions & 1 deletion generators/go/docker/Dockerfile.fiber
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:18-alpine3.18 AS node
FROM golang:1.19-alpine3.17

WORKDIR /workspace

RUN apk add --no-cache ca-certificates git
RUN apk add --no-cache ca-certificates git libstdc++6 libstdc++ && git config --global user.name "fern" && git config --global user.email "[email protected]"

COPY go.mod go.sum /workspace/
RUN go mod download
Expand All @@ -13,4 +14,10 @@ COPY version.go /workspace/version.go

RUN CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -buildvcs=false -o /fern-go-fiber ./cmd/fern-go-fiber

# 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

ENTRYPOINT ["/fern-go-fiber"]
9 changes: 8 additions & 1 deletion generators/go/docker/Dockerfile.model
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:18-alpine3.18 AS node
FROM golang:1.19-alpine3.17

WORKDIR /workspace

RUN apk add --no-cache ca-certificates git
RUN apk add --no-cache ca-certificates git libstdc++6 libstdc++ && git config --global user.name "fern" && git config --global user.email "[email protected]"

COPY go.mod go.sum /workspace/
RUN go mod download
Expand All @@ -13,4 +14,10 @@ COPY version.go /workspace/version.go

RUN CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -buildvcs=false -o /fern-go-model ./cmd/fern-go-model

# 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

ENTRYPOINT ["/fern-go-model"]
9 changes: 8 additions & 1 deletion generators/go/docker/Dockerfile.sdk
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:18-alpine3.18 AS node
FROM golang:1.19-alpine3.17

WORKDIR /workspace

RUN apk add --no-cache ca-certificates git
RUN apk add --no-cache ca-certificates git libstdc++6 libstdc++ && git config --global user.name "fern" && git config --global user.email "[email protected]"

COPY go.mod go.sum /workspace/
RUN go mod download
Expand All @@ -13,4 +14,10 @@ COPY version.go /workspace/version.go

RUN CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -buildvcs=false -o /fern-go-sdk ./cmd/fern-go-sdk

# 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

ENTRYPOINT ["/fern-go-sdk"]
7 changes: 7 additions & 0 deletions generators/go/internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/fern-api/fern-go/internal/coordinator"
"github.com/fern-api/fern-go/internal/fern/ir"
fernir "github.com/fern-api/fern-go/internal/fern/ir"
"github.com/fern-api/fern-go/internal/generatorcli"
generatorexec "github.com/fern-api/generator-exec-go"
)

Expand All @@ -32,6 +33,7 @@ const (

// Generator represents the Go code generator.
type Generator struct {
cli *generatorcli.Client
config *Config
coordinator *coordinator.Client
}
Expand Down Expand Up @@ -106,7 +108,12 @@ func NewFile(coordinator *coordinator.Client, filename string, content []byte) *

// New returns a new *Generator.
func New(config *Config, coordinator *coordinator.Client) (*Generator, error) {
cli, err := generatorcli.New(coordinator)
if err != nil {
return nil, err
}
return &Generator{
cli: cli,
config: config,
coordinator: coordinator,
}, nil
Expand Down
2 changes: 2 additions & 0 deletions generators/go/internal/generatorcli/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Pacakge generatorcli provides utilities for executing the generator-cli command.
package generatorcli
101 changes: 101 additions & 0 deletions generators/go/internal/generatorcli/generatorcli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package generatorcli

import (
"bytes"
"errors"
"fmt"
"os/exec"

"github.com/fern-api/fern-go/internal/coordinator"
generatorexec "github.com/fern-api/generator-exec-go"
)

// module represents the name of the NPM package.
const npmPackage = "@fern-api/generator-cli"

// Client represents the generator-cli command, installing it as needed.
type Client struct {
coordinator *coordinator.Client
}

// ClientOption adapts the behavior of the Client.
type ClientOption func(*clientOptions)

// WithSkipInstall skips the automatic installation, which is useful when the host
// already has the generator-cli command installed.
func WithSkipInstall() ClientOption {
return func(opts *clientOptions) {
opts.skipInstall = true
}
}

// New returns a new *GeneratorCLI.
func New(coordinator *coordinator.Client, opts ...ClientOption) (*Client, error) {
options := new(clientOptions)
for _, opt := range opts {
opt(options)
}
cli := &Client{
coordinator: coordinator,
}
if options.skipInstall {
return cli, nil
}
if err := cli.install(); err != nil {
return nil, err
}
return cli, nil
}

// GenerateReadmeOption adapts the behavior of the GenerateReadme method.
type GenerateReadmeOption func(*generateReadmeOptions)

// WithOriginalReadme sets the original README.md filepath, which is used to
// preserve the original content in the generated README.md
func WithOriginalReadme(originalReadmeFilepath string) GenerateReadmeOption {
return func(opts *generateReadmeOptions) {
opts.originalReadmeFilepath = originalReadmeFilepath
}
}

func (c *Client) GenerateReadme(opts ...GenerateReadmeOption) error {
// TODO: Implement me!
return nil
}

// install installs the generator-cli command.
func (c *Client) install() error {
c.coordinator.Log(
generatorexec.LogLevelDebug,
"Installing generator-cli...",
)

stderr := bytes.NewBuffer(nil)
install := exec.Command("npm", "install", "-g", npmPackage)
install.Stderr = stderr
if err := install.Run(); err != nil {
return errors.New(stderr.String())
}

stdout := bytes.NewBuffer(nil)
cli := exec.Command("generator-cli", "--version")
cli.Stdout = stdout
cli.Stderr = stderr
if err := cli.Run(); err != nil {
return errors.New(stderr.String())
}

c.coordinator.Log(
generatorexec.LogLevelDebug,
fmt.Sprintf("Successfully installed generator-cli version %q", stdout.String()),
)
return nil
}

type clientOptions struct {
skipInstall bool
}

type generateReadmeOptions struct {
originalReadmeFilepath string
}
14 changes: 13 additions & 1 deletion generators/java/model/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Apple Silicon: FROM bitnami/gradle:latest
FROM bitnami/gradle:8.5.0
FROM gradle:jdk11-jammy

# Install node and npm.
ENV NODE_VERSION=18.20.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

COPY build/distributions/model.tar init.sh /
RUN cd / \
Expand Down
12 changes: 12 additions & 0 deletions generators/java/sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Apple Silicon: FROM bitnami/gradle:latest
FROM gradle:jdk11-jammy

# Install node and npm.
ENV NODE_VERSION=18.20.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

COPY build/distributions/sdk.tar init.sh /
RUN cd / \
&& tar -xvf sdk.tar \
Expand Down
14 changes: 13 additions & 1 deletion generators/java/spring/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Apple Silicon: FROM bitnami/gradle:latest
FROM bitnami/gradle:8.5.0
FROM gradle:jdk11-jammy

# Install node and npm.
ENV NODE_VERSION=18.20.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

COPY build/distributions/spring.tar init.sh /
RUN cd / \
Expand Down
12 changes: 12 additions & 0 deletions generators/python/fastapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
FROM python:3.9.14

# Install node and npm.
ENV NODE_VERSION=18.20.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

ENV PYTHONPATH=${PYTHONPATH}:${PWD}
ENV _TYPER_STANDARD_TRACEBACK=1

Expand Down
12 changes: 12 additions & 0 deletions generators/python/pydantic/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
FROM python:3.9.14

# Install node and npm.
ENV NODE_VERSION=18.20.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

ENV PYTHONPATH=${PYTHONPATH}:${PWD}
ENV _TYPER_STANDARD_TRACEBACK=1

Expand Down
13 changes: 12 additions & 1 deletion generators/python/sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
FROM python:3.9.14

# Install node and npm.
ENV NODE_VERSION=18.20.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

ENV PYTHONPATH=${PYTHONPATH}:${PWD}
ENV _TYPER_STANDARD_TRACEBACK=1
ENV HTTPX_LOG_LEVEL=trace
Expand All @@ -9,7 +21,6 @@ COPY poetry.lock ./poetry.lock
COPY ./core_utilities/sdk /assets/core_utilities
COPY ./src ./src


RUN pip3 install poetry &&\
poetry config virtualenvs.create false &&\
poetry install
Expand Down
9 changes: 7 additions & 2 deletions seed/go-fiber/examples/.mock/definition/health/service.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions seed/go-model/examples/.mock/definition/health/service.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading