diff --git a/Dockerfile b/Dockerfile index 6aefb5a..bd16a36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN CGO_ENABLED=0 go build -o /my_app FROM alpine:3.21 WORKDIR /plugin COPY --from=builder /my_app /my_app -COPY --from=builder /plugin/*.yaml . -COPY --from=builder /plugin/*.sql . +COPY --from=builder /plugin/*.yaml ./ +COPY --from=builder /plugin/*.sql ./ EXPOSE 8080 CMD ["/my_app"] diff --git a/Makefile b/Makefile index f05d2a3..28ffaca 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=0.0.2 +VERSION=0.0.7 LOCAL_REGISTRY=localhost:5000 .PHONY: docker-release diff --git a/main.go b/main.go index d3225c0..82aeeee 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,10 @@ import ( _ "embed" "encoding/json" "fmt" + "io" "log" "net/http" + "net/url" "os" "github.com/cycloidio/cy-go-plugin/sentry" @@ -43,6 +45,7 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("GET /_cy/ping", ping) + mux.HandleFunc("GET /_cy/test-proxy", testProxy) mux.HandleFunc("POST /_cy/events", events) mux.HandleFunc("DELETE /_cy/plugin", func(w http.ResponseWriter, r *http.Request) { if err := sentry.Clear(db); err != nil { @@ -78,6 +81,39 @@ func ping(w http.ResponseWriter, _ *http.Request) { respond(w, "ping") } +// testProxy calls the plugin manager's internal proxy endpoint using the injected +// PROXY_URL and PLUGIN_SECRET env vars, and forwards the response back to the caller. +func testProxy(w http.ResponseWriter, r *http.Request) { + proxyURL := os.Getenv("PROXY_URL") + if proxyURL == "" { + http.Error(w, "PROXY_URL not set", http.StatusServiceUnavailable) + return + } + + targetURL := proxyURL + if secret := os.Getenv("PLUGIN_SECRET"); secret != "" { + targetURL += "?secret=" + url.QueryEscape(secret) + } + + req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, targetURL, nil) + if err != nil { + http.Error(w, fmt.Sprintf("build request: %v", err), http.StatusInternalServerError) + return + } + + resp, err := http.DefaultClient.Do(req) + if err != nil { + http.Error(w, fmt.Sprintf("proxy call failed: %v", err), http.StatusBadGateway) + return + } + defer resp.Body.Close() + + body, _ := io.ReadAll(resp.Body) + w.Header().Set("Content-Type", resp.Header.Get("Content-Type")) + w.WriteHeader(resp.StatusCode) + w.Write(body) +} + func events(w http.ResponseWriter, _ *http.Request) { respond(w, "events") } diff --git a/manifest.yaml b/manifest.yaml index 4d3737b..e58af35 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -8,6 +8,13 @@ images: scope: - organization:project:* - organization:credential:* +setup: + can_replicate: true + readiness_path: /_cy/ping + min_cpu: "50m" + min_memory: "64Mi" + max_cpu: "200m" + max_memory: "256Mi" configuration: - name: "Message" description: "Message to display in the job"