Skip to content

Commit 706ebd9

Browse files
authored
Fix generating files with docker (#829)
# Description Fixes an issue in generating files in Docker. There has been an incompatibility of `buf` (version `29.5`) and `protoc-gen-es` (version `2.2.2`). I updated `protoc-gen-es@` to `2.6.2` Also refactored the code a little so it's easier to read Added a CI pipeline job to check all files are properly generated
1 parent c28f471 commit 706ebd9

21 files changed

Lines changed: 1997 additions & 88 deletions
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Generated files
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check-generated:
8+
name: Generated files
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Install pnpm
15+
uses: pnpm/action-setup@v3
16+
id: pnpm-install
17+
with:
18+
version: 9.5
19+
20+
- name: Setup Node
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20.x'
24+
registry-url: 'https://registry.npmjs.org'
25+
cache: pnpm
26+
cache-dependency-path: pnpm-lock.yaml
27+
28+
- name: Configure pnpm
29+
run: |
30+
pnpm config set auto-install-peers true
31+
pnpm config set exclude-links-from-lockfile true
32+
33+
- name: Install dependencies
34+
run: pnpm install --frozen-lockfile
35+
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Build codegen image with caching
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
file: codegen.Dockerfile
45+
tags: codegen-env:latest
46+
load: true # makes the image available for `docker run`
47+
cache-from: type=gha
48+
cache-to: type=gha,mode=max
49+
50+
- name: Run codegen
51+
run: make codegen
52+
53+
- name: Check for uncommitted changes
54+
run: |
55+
if [[ -n $(git status --porcelain) ]]; then
56+
echo "❌ Generated files are not up to date:"
57+
git status --short
58+
git diff
59+
exit 1
60+
else
61+
echo "✅ No changes detected."
62+
fi

Makefile

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
update-api-spec:
2-
@echo "Updating API spec"
3-
@./scripts/update-api-spec.sh
4-
@echo "Done"
5-
61
.PHONY: codegen
72
codegen:
83
@echo "Generating SDK code from openapi and envd spec"
9-
@./scripts/codegen.sh
10-
4+
@docker run -v "$$(pwd):/workspace" $$(docker build -q -t codegen-env . -f codegen.Dockerfile)
115
generate: generate-js generate-python
126

137
generate-js:
148
cd packages/js-sdk && pnpm generate
15-
cd packages/js-sdk && pnpm generate-envd-api
16-
cd spec/envd && buf generate --template buf-js.gen.yaml
179

1810
generate-python:
19-
if [ ! -f "/go/bin/protoc-gen-connect-python" ]; then \
20-
$(MAKE) -C packages/connect-python build; \
21-
fi
22-
cd packages/python-sdk && make generate-api
23-
cd spec/envd && buf generate --template buf-python.gen.yaml
24-
cd packages/python-sdk && ./scripts/fix-python-pb.sh && black .
11+
cd packages/python-sdk && make generate
2512

2613
.PHONY: init-styles
2714
init-styles:
2815
vale sync
16+

codegen.Dockerfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM golang:1.23
44
RUN go install github.com/bufbuild/buf/cmd/buf@v1.50.1 && \
55
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1 && \
66
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@v1.18.1
7-
7+
88
# Install our custom protoc plugin, connect-python
99
COPY ./packages/connect-python /packages/connect-python
1010
RUN cd /packages/connect-python && make bin/protoc-gen-connect-python
@@ -15,10 +15,16 @@ FROM python:3.9
1515
# Set working directory
1616
WORKDIR /workspace
1717

18-
ENV PROTOC_ZIP=protoc-29.3-linux-aarch_64.zip
19-
20-
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v29.3/$PROTOC_ZIP
21-
RUN unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
18+
ENV PROTOC_VERSION=29.3
19+
RUN ARCH=$(uname -m) && \
20+
case "$ARCH" in \
21+
x86_64) PROTOC_ARCH="x86_64" ;; \
22+
arm64|aarch64) PROTOC_ARCH="aarch_64" ;; \
23+
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
24+
esac && \
25+
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip && \
26+
unzip -o protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip -d /usr/local && \
27+
rm protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip
2228

2329
# Copy installed Go deps from previous build step
2430
COPY --from=0 /go /go
@@ -38,7 +44,9 @@ RUN apt-get update && \
3844
rm -rf /var/lib/apt/lists/*
3945

4046
# Install Node.js deps
41-
RUN npm install -g pnpm @connectrpc/protoc-gen-connect-es@1.6.1 @bufbuild/protoc-gen-es@2.2.2
47+
RUN npm install -g \
48+
pnpm \
49+
@connectrpc/protoc-gen-connect-es@1.6.1 \
50+
@bufbuild/protoc-gen-es@2.6.2
4251

43-
# Generate when container starts
4452
CMD ["make", "generate"]

packages/js-sdk/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"dev": "tsup --watch",
2929
"example": "tsx example.mts",
3030
"test": "vitest run",
31-
"generate": "python ./../../spec/remove_extra_tags.py sandboxes templates auth && openapi-typescript ../../spec/openapi_generated.yml -x api_key --array-length --alphabetize --output src/api/schema.gen.ts",
32-
"generate-envd-api": "openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts",
31+
"generate":"npm-run-all generate:*",
32+
"generate:api": "python ./../../spec/remove_extra_tags.py sandboxes templates auth && openapi-typescript ../../spec/openapi_generated.yml -x api_key --array-length --alphabetize --output src/api/schema.gen.ts",
33+
"generate:envd-api": "openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts",
3334
"generate-ref": "./scripts/generate_sdk_ref.sh",
3435
"check-deps": "knip",
3536
"update-deps": "ncu -u && pnpm i",
@@ -52,6 +53,7 @@
5253
"eslint": "^8.57.1",
5354
"knip": "^5.43.6",
5455
"npm-check-updates": "^16.14.20",
56+
"npm-run-all": "^4.1.5",
5557
"openapi-typescript": "^7.6.1",
5658
"playwright": "^1.48.0",
5759
"react": "^18.3.1",
@@ -82,7 +84,7 @@
8284
"typescript"
8385
],
8486
"dependencies": {
85-
"@bufbuild/protobuf": "^2.2.2",
87+
"@bufbuild/protobuf": "^2.6.2",
8688
"@connectrpc/connect": "2.0.0-rc.3",
8789
"@connectrpc/connect-web": "2.0.0-rc.3",
8890
"compare-versions": "^6.1.0",

0 commit comments

Comments
 (0)