feat: implement proto-gen platform
- Config loader with env var expansion and validation - SQLite database with tasks and toolchain_versions tables - Gitea REST API client for repository and branch operations - K8s client for Job lifecycle management (with noop fallback for local dev) - REST API: tasks CRUD, retry, plugins, version management - Worker/scheduler with polling, concurrency control, and job tracking - Static frontend: generate, tasks, settings pages - Toolchain images: Go and Node.js Dockerfiles with entrypoint scripts - Helm chart with deployment, service, configmap, ingress, PVC - Multi-stage Dockerfile for service - Unit tests for config, database, gitclient, k8s, api, worker - E2E tests for idempotency, version switch, failure recovery
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
FROM alpine:3.19
|
||||
|
||||
ARG PROTOC_VERSION=25.1
|
||||
ARG PROTOC_GEN_GO_VERSION=v1.34.2
|
||||
ARG PROTOC_GEN_GO_GRPC_VERSION=v1.5.0
|
||||
|
||||
RUN apk add --no-cache git curl unzip
|
||||
|
||||
RUN curl -sLO https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \
|
||||
unzip -o protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local && \
|
||||
rm protoc-${PROTOC_VERSION}-linux-x86_64.zip
|
||||
|
||||
RUN curl -sLO https://go.dev/dl/go1.22.5.linux-amd64.tar.gz && \
|
||||
tar -C /usr/local -xzf go1.22.5.linux-amd64.tar.gz && \
|
||||
rm go1.22.5.linux-amd64.tar.gz
|
||||
|
||||
ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}"
|
||||
ENV GOPATH="/root/go"
|
||||
|
||||
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION} && \
|
||||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "=== Proto-Gen Go Toolchain ==="
|
||||
echo "PROTO_REPO: ${PROTO_REPO}"
|
||||
echo "PROTO_BRANCH: ${PROTO_BRANCH}"
|
||||
echo "TARGET_REPO: ${TARGET_REPO}"
|
||||
|
||||
REPO_DIR=$(mktemp -d)
|
||||
OUT_DIR=${OUT_DIR:-/out}
|
||||
mkdir -p "${OUT_DIR}"
|
||||
|
||||
echo "--- Cloning proto repository ---"
|
||||
git clone --branch "${PROTO_BRANCH}" --depth 1 \
|
||||
"https://${GIT_TOKEN}@${GIT_BASE_URL}/${PROTO_REPO}.git" "${REPO_DIR}/proto"
|
||||
|
||||
PROTO_SHA=$(cd "${REPO_DIR}/proto" && git rev-parse HEAD)
|
||||
echo "Proto commit: ${PROTO_SHA}"
|
||||
|
||||
echo "--- Running protoc ---"
|
||||
PROTO_FILES=$(find "${REPO_DIR}/proto" -name "*.proto" -type f)
|
||||
for proto_file in ${PROTO_FILES}; do
|
||||
protoc \
|
||||
--proto_path="${REPO_DIR}/proto" \
|
||||
--go_out="${OUT_DIR}" --go_opt=paths=source_relative \
|
||||
--go-grpc_out="${OUT_DIR}" --go-grpc_opt=paths=source_relative \
|
||||
"${proto_file#${REPO_DIR}/proto/}"
|
||||
done
|
||||
|
||||
echo "--- Cloning target repository ---"
|
||||
TARGET_DIR=$(mktemp -d)
|
||||
if git clone "https://${GIT_TOKEN}@${GIT_BASE_URL}/${TARGET_REPO}.git" "${TARGET_DIR}/target" 2>/dev/null; then
|
||||
echo "Target repo exists"
|
||||
else
|
||||
echo "Creating target repository..."
|
||||
curl -s -X POST \
|
||||
-H "Authorization: token ${GIT_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"name\": \"${TARGET_REPO}\", \"auto_init\": false}" \
|
||||
"${GIT_BASE_URL}/api/v1/user/repos"
|
||||
git clone "https://${GIT_TOKEN}@${GIT_BASE_URL}/${TARGET_REPO}.git" "${TARGET_DIR}/target"
|
||||
fi
|
||||
|
||||
echo "--- Checking for changes ---"
|
||||
cd "${TARGET_DIR}/target"
|
||||
cp -r "${OUT_DIR}"/* . 2>/dev/null || true
|
||||
git add -A
|
||||
|
||||
if git diff --cached --quiet; then
|
||||
echo "No changes detected, idempotent exit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "--- Committing and pushing ---"
|
||||
git config user.email "proto-gen@bot"
|
||||
git config user.name "Proto-Gen Bot"
|
||||
git commit -m "gen(go): from ${PROTO_REPO}@${PROTO_SHA}"
|
||||
git push origin "${PROTO_BRANCH}"
|
||||
|
||||
echo "=== Done ==="
|
||||
@@ -0,0 +1,17 @@
|
||||
FROM node:20-alpine
|
||||
|
||||
ARG PROTOC_VERSION=25.1
|
||||
ARG PROTOC_GEN_TS_VERSION=1.8.2
|
||||
|
||||
RUN apk add --no-cache git curl unzip
|
||||
|
||||
RUN curl -sLO https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \
|
||||
unzip -o protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local && \
|
||||
rm protoc-${PROTOC_VERSION}-linux-x86_64.zip
|
||||
|
||||
RUN npm install -g protoc-gen-ts@${PROTOC_GEN_TS_VERSION}
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "=== Proto-Gen Node.js Toolchain ==="
|
||||
echo "PROTO_REPO: ${PROTO_REPO}"
|
||||
echo "PROTO_BRANCH: ${PROTO_BRANCH}"
|
||||
echo "TARGET_REPO: ${TARGET_REPO}"
|
||||
|
||||
REPO_DIR=$(mktemp -d)
|
||||
OUT_DIR=${OUT_DIR:-/out}
|
||||
mkdir -p "${OUT_DIR}"
|
||||
|
||||
echo "--- Cloning proto repository ---"
|
||||
git clone --branch "${PROTO_BRANCH}" --depth 1 \
|
||||
"https://${GIT_TOKEN}@${GIT_BASE_URL}/${PROTO_REPO}.git" "${REPO_DIR}/proto"
|
||||
|
||||
PROTO_SHA=$(cd "${REPO_DIR}/proto" && git rev-parse HEAD)
|
||||
echo "Proto commit: ${PROTO_SHA}"
|
||||
|
||||
echo "--- Running protoc ---"
|
||||
PROTO_FILES=$(find "${REPO_DIR}/proto" -name "*.proto" -type f)
|
||||
for proto_file in ${PROTO_FILES}; do
|
||||
protoc \
|
||||
--proto_path="${REPO_DIR}/proto" \
|
||||
--ts_out="${OUT_DIR}" --ts_opt=long_type_string
|
||||
"${proto_file#${REPO_DIR}/proto/}"
|
||||
done
|
||||
|
||||
echo "--- Cloning target repository ---"
|
||||
TARGET_DIR=$(mktemp -d)
|
||||
if git clone "https://${GIT_TOKEN}@${GIT_BASE_URL}/${TARGET_REPO}.git" "${TARGET_DIR}/target" 2>/dev/null; then
|
||||
echo "Target repo exists"
|
||||
else
|
||||
echo "Creating target repository..."
|
||||
curl -s -X POST \
|
||||
-H "Authorization: token ${GIT_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"name\": \"${TARGET_REPO}\", \"auto_init\": false}" \
|
||||
"${GIT_BASE_URL}/api/v1/user/repos"
|
||||
git clone "https://${GIT_TOKEN}@${GIT_BASE_URL}/${TARGET_REPO}.git" "${TARGET_DIR}/target"
|
||||
fi
|
||||
|
||||
echo "--- Checking for changes ---"
|
||||
cd "${TARGET_DIR}/target"
|
||||
cp -r "${OUT_DIR}"/* . 2>/dev/null || true
|
||||
git add -A
|
||||
|
||||
if git diff --cached --quiet; then
|
||||
echo "No changes detected, idempotent exit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "--- Committing and pushing ---"
|
||||
git config user.email "proto-gen@bot"
|
||||
git config user.name "Proto-Gen Bot"
|
||||
git commit -m "gen(nodejs): from ${PROTO_REPO}@${PROTO_SHA}"
|
||||
git push origin "${PROTO_BRANCH}"
|
||||
|
||||
echo "=== Done ==="
|
||||
Reference in New Issue
Block a user