Skip to content

Commit 7e8a7eb

Browse files
Merge pull request #1926 from renuka-fernando/python-custom
feat(cli): copy python-executor into gateway-runtime image
2 parents 8bbf5a9 + b532ca8 commit 7e8a7eb

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

cli/src/internal/gateway/docker_build.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ func BuildGatewayImages(config DockerBuildConfig) error {
7474
return err
7575
}
7676

77+
if err := ensurePythonExecutorInRuntimeContext(config.TempDir); err != nil {
78+
return err
79+
}
80+
7781
fmt.Println(" ✓ Gateway-builder completed")
7882

7983
// Step 2: Build the two images
@@ -121,6 +125,30 @@ func ensureBuildLockInControllerContext(tempDir string) error {
121125
return nil
122126
}
123127

128+
// ensurePythonExecutorInRuntimeContext stages the python-executor directory
129+
// produced by gateway-builder into the gateway-runtime Docker build context
130+
// so the Dockerfile's `COPY python-executor/ ...` can resolve it.
131+
func ensurePythonExecutorInRuntimeContext(tempDir string) error {
132+
pythonExecutorSrc := filepath.Join(tempDir, "output", "python-executor")
133+
if _, err := os.Stat(pythonExecutorSrc); err != nil {
134+
if errors.Is(err, os.ErrNotExist) {
135+
return nil
136+
}
137+
return fmt.Errorf("failed to access python-executor output: %w", err)
138+
}
139+
140+
pythonExecutorDst := filepath.Join(tempDir, "output", "gateway-runtime", "python-executor")
141+
if err := os.RemoveAll(pythonExecutorDst); err != nil {
142+
return fmt.Errorf("failed to clear existing python-executor in gateway-runtime build context: %w", err)
143+
}
144+
145+
if err := utils.CopyDir(pythonExecutorSrc, pythonExecutorDst); err != nil {
146+
return fmt.Errorf("failed to copy python-executor into gateway-runtime build context: %w", err)
147+
}
148+
149+
return nil
150+
}
151+
124152
// runGatewayBuilder runs the gateway-builder container
125153
func runGatewayBuilder(config DockerBuildConfig, logFile *os.File) error {
126154
args := []string{"run", "--rm", "-v", config.TempDir + ":/workspace", config.GatewayBuilder,

gateway/gateway-builder/internal/policyengine/generator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,16 @@ func copyDir(src, dst string) error {
373373
dstPath := filepath.Join(dst, relPath)
374374

375375
if info.IsDir() {
376+
if info.Name() == ".venv" || info.Name() == "__pycache__" || info.Name() == ".git" {
377+
return filepath.SkipDir
378+
}
376379
return os.MkdirAll(dstPath, info.Mode())
377380
}
378381

382+
if !info.Mode().IsRegular() {
383+
return nil
384+
}
385+
379386
// Copy file
380387
data, err := os.ReadFile(path)
381388
if err != nil {

gateway/gateway-builder/templates/Dockerfile.gateway-runtime.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ USER root
2424
COPY policy-engine /app/policy-engine
2525
RUN chmod +x /app/policy-engine
2626

27+
# Replace python-executor with custom-compiled version containing user Python policies
28+
RUN rm -rf /app/python-executor
29+
COPY python-executor/ /app/python-executor/
30+
31+
# Install python dependencies for custom policies
32+
RUN apt-get update && apt-get install -y --no-install-recommends python3-pip && \
33+
pip3 install --no-cache-dir --upgrade pip setuptools wheel && \
34+
pip3 install --no-cache-dir --target /app/python-libs -r /app/python-executor/requirements.txt && \
35+
apt-get purge -y python3-pip && \
36+
apt-get autoremove -y && \
37+
rm -rf /var/lib/apt/lists/*
2738
USER wso2
2839
2940
# Metadata labels

0 commit comments

Comments
 (0)