E2B/codegen.Dockerfile

57 lines
2.0 KiB
Docker
Raw Permalink Normal View History

Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/openapi_generated.yml โ†’ src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/envd/envd.yaml โ†’ src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! โœจ ๐Ÿฐ โœจ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
FROM golang:1.23
# Install Golang deps
RUN go install github.com/bufbuild/buf/cmd/buf@v1.50.1 && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1 && \
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@v1.18.1
Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/openapi_generated.yml โ†’ src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/envd/envd.yaml โ†’ src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! โœจ ๐Ÿฐ โœจ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
# Install our custom protoc plugin, connect-python
COPY ./packages/connect-python /packages/connect-python
RUN cd /packages/connect-python && make bin/protoc-gen-connect-python
FROM python:3.10
Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/openapi_generated.yml โ†’ src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/envd/envd.yaml โ†’ src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! โœจ ๐Ÿฐ โœจ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
# Set working directory
WORKDIR /workspace
ENV PROTOC_VERSION=26.1
RUN ARCH=$(uname -m) && \
case "$ARCH" in \
x86_64) PROTOC_ARCH="x86_64" ;; \
arm64|aarch64) PROTOC_ARCH="aarch_64" ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac && \
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip && \
unzip -o protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip -d /usr/local && \
rm protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip
Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/openapi_generated.yml โ†’ src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/envd/envd.yaml โ†’ src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! โœจ ๐Ÿฐ โœจ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
# Copy installed Go deps from previous build step
COPY --from=0 /go /go
# Add Go binary to PATH
ENV PATH="/go/bin:${PATH}"
# Install Python deps (e2b-openapi-python-client is patched version to fix issue with explode)
# https://github.com/openapi-generators/openapi-python-client/pull/1296
RUN pip install black==23.7.0 pyyaml==6.0.2 e2b-openapi-python-client==0.26.2 datamodel-code-generator==0.34.0
Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/openapi_generated.yml โ†’ src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/envd/envd.yaml โ†’ src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! โœจ ๐Ÿฐ โœจ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
# Install Node.js (pinned to match .tool-versions)
ENV NODE_VERSION=20.19.5
RUN ARCH=$(uname -m) && \
case "$ARCH" in \
x86_64) NODE_ARCH="x64" ;; \
arm64|aarch64) NODE_ARCH="arm64" ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac && \
curl -fsSL https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz | tar -xJ -C /usr/local --strip-components=1
Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/openapi_generated.yml โ†’ src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/envd/envd.yaml โ†’ src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! โœจ ๐Ÿฐ โœจ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
# Install Node.js deps
ENV PNPM_VERSION=9.15.5
RUN npm install -g \
pnpm@${PNPM_VERSION} \
@connectrpc/protoc-gen-connect-es@1.6.1 \
@bufbuild/protoc-gen-es@2.6.2
Make codegen robust and deterministic for js and python SDKs (#664) # Description This PR allows to codegen without worrying about your environment and dependencies for consistent outcomes in what code is generated from openapi and envd protobuf spec. Will generate files for `js-sdk` and `python-sdk` - [x] create Docker image with all the pinned deps needed to codegen - [x] create codegen script using this container with mapped volumes - [x] adapt Makefiles to this new approach - [x] adapt where we install the connect-python protobuf binary for this to work # Test ```sh make codegen # this command is similar to `make generate` but w/o the hassle Generating SDK code from openapi and envd spec cd packages/js-sdk && pnpm generate > e2b@1.2.1 generate /workspace/packages/js-sdk > python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --arr ay-length --alphabetize --output src/api/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/openapi_generated.yml โ†’ src/api/schema.gen.ts [44.2ms] cd packages/js-sdk && pnpm generate-envd-api > e2b@1.2.1 generate-envd-api /workspace/packages/js-sdk > openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts โœจ openapi-typescript 7.6.1 ๐Ÿš€ ../../spec/envd/envd.yaml โ†’ src/envd/schema.gen.ts [22.7ms] [...] cd packages/python-sdk && make generate-api All done! โœจ ๐Ÿฐ โœจ ``` --------- Co-authored-by: Jiri Sveceny <jiri.sveceny@icloud.com>
2025-04-07 17:00:31 +02:00
CMD ["make", "generate"]