Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 4 additions & 47 deletions event-gateway/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,8 @@ help: ## Show this help message
build: build-event-gateway-controller build-gateway-runtime build-webhook-listener ## Build all event gateway components

.PHONY: build-event-gateway-controller
# TODO: drop the manual `policies` build-context (and event-gateway/default-policies/)
# once gateway-builder is integrated into the event-gateway build pipeline.
build-event-gateway-controller: ## Build event-gateway-controller Docker image
@echo "Building event-gateway-controller Docker image ($(VERSION))..."
@mkdir -p ../gateway/gateway-controller/target
@cp ../LICENSE ../gateway/gateway-controller/target/
@cd ../gateway/gateway-controller && \
docker buildx build -f Dockerfile \
--build-context sdk=../../sdk \
--build-context sdk-core=../../sdk/core \
--build-context common=../../common \
--build-context build-manifest=.. \
--build-context policies=../../event-gateway/default-policies \
--build-context target=target \
--build-arg VERSION=$(VERSION) \
--build-arg FUNCTIONALITY_TYPE=event \
--build-arg GIT_COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") \
--target production \
-t $(EVENT_GATEWAY_CONTROLLER_IMAGE):$(VERSION) \
-t $(EVENT_GATEWAY_CONTROLLER_IMAGE):latest \
--load \
.
@rm -rf ../gateway/gateway-controller/target
$(MAKE) -C gateway-controller build-docker VERSION=$(VERSION)

.PHONY: build-gateway-runtime
build-gateway-runtime: ## Build event-gateway-runtime Docker image
Expand All @@ -108,30 +87,8 @@ build-webhook-listener: ## Build webhook-listener Docker image
build-and-push-multiarch: build-and-push-multiarch-event-gateway-controller build-and-push-multiarch-gateway-runtime ## Build and push all event gateway components for multiple architectures

.PHONY: build-and-push-multiarch-event-gateway-controller
# TODO: drop the manual `policies` build-context (and event-gateway/default-policies/)
# once gateway-builder is integrated into the event-gateway build pipeline.
build-and-push-multiarch-event-gateway-controller: ## Build and push event-gateway-controller Docker image for multiple architectures
@echo "Building and pushing multi-arch event-gateway-controller Docker image ($(VERSION))..."
@mkdir -p ../gateway/gateway-controller/target
@cp ../LICENSE ../gateway/gateway-controller/target/
@cd ../gateway/gateway-controller && \
docker buildx build -f Dockerfile \
--build-context sdk=../../sdk \
--build-context sdk-core=../../sdk/core \
--build-context common=../../common \
--build-context build-manifest=.. \
--build-context policies=../../event-gateway/default-policies \
--build-context target=target \
--platform linux/amd64,linux/arm64 \
--build-arg VERSION=$(VERSION) \
--build-arg FUNCTIONALITY_TYPE=event \
--build-arg GIT_COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") \
--target production \
-t $(EVENT_GATEWAY_CONTROLLER_IMAGE):$(VERSION) \
-t $(EVENT_GATEWAY_CONTROLLER_IMAGE):latest \
--push \
.
@rm -rf ../gateway/gateway-controller/target
$(MAKE) -C gateway-controller build-and-push-multiarch VERSION=$(VERSION)

.PHONY: build-and-push-multiarch-gateway-runtime
build-and-push-multiarch-gateway-runtime: ## Build and push event-gateway-runtime Docker image for multiple architectures
Expand All @@ -149,7 +106,7 @@ test: test-event-gateway-controller test-gateway-runtime ## Run all tests

.PHONY: test-event-gateway-controller
test-event-gateway-controller: ## Test event-gateway-controller
$(MAKE) -C ../gateway/gateway-controller test
$(MAKE) -C gateway-controller test

.PHONY: test-gateway-runtime
test-gateway-runtime: ## Test event-gateway-runtime
Expand Down Expand Up @@ -200,6 +157,6 @@ version-get-release: ## Get release version (strips SNAPSHOT suffix)
# Clean Targets
.PHONY: clean
clean: ## Clean all build artifacts
$(MAKE) -C ../gateway/gateway-controller clean
$(MAKE) -C gateway-controller clean
$(MAKE) -C gateway-runtime clean
$(MAKE) -C webhook-listener clean
137 changes: 137 additions & 0 deletions event-gateway/gateway-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Stage 1: Build the Go application
FROM --platform=$BUILDPLATFORM golang:1.26.2-bookworm AS builder
ARG TARGETARCH
ARG VERSION=0.0.1-SNAPSHOT
ARG GIT_COMMIT=unknown

# Coverage build argument - set to "true" for coverage-instrumented builds
ARG ENABLE_COVERAGE=false

# Debug build argument - set to "true" for debug builds with dlv support
ARG ENABLE_DEBUG=false

WORKDIR /build

# Install build dependencies for SQLite (CGO) and cross-compilation toolchains
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
apt-get update && apt-get install -y --no-install-recommends \
gcc \
libc6-dev \
libsqlite3-dev \
&& if [ "$TARGETARCH" = "amd64" ]; then \
apt-get install -y --no-install-recommends gcc-x86-64-linux-gnu libc6-dev-amd64-cross; \
elif [ "$TARGETARCH" = "arm64" ]; then \
apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross; \
fi

# Copy go mod files for dependencies (needed for go.mod replace directives)
COPY --from=sdk-core go.mod /sdk/core/
COPY --from=common go.mod go.sum /common/
COPY --from=gateway-controller go.mod go.sum /gateway/gateway-controller/

COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

# Copy full source trees needed by replace directives
COPY --from=sdk-core . /sdk/core
COPY --from=common . /common
COPY --from=gateway-controller . /gateway/gateway-controller
COPY . ./

# Build with CGO (required for SQLite), set CC for cross-compilation
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
if [ "$TARGETARCH" = "amd64" ]; then \
export CC=x86_64-linux-gnu-gcc; \
elif [ "$TARGETARCH" = "arm64" ]; then \
export CC=aarch64-linux-gnu-gcc; \
else \
export CC=gcc; \
fi && \
if [ "$ENABLE_COVERAGE" = "true" ]; then \
COVER_FLAG="-cover"; \
else \
COVER_FLAG=""; \
fi && \
export CGO_ENABLED=1 && \
export GOOS=linux && \
export GOARCH=${TARGETARCH} && \
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) && \
VERSION_PKG=github.com/wso2/api-platform/gateway/gateway-controller/pkg/version && \
LDFLAGS="-X ${VERSION_PKG}.Version=${VERSION} -X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} -X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" && \
if [ "$ENABLE_DEBUG" = "true" ]; then \
go build $COVER_FLAG \
-gcflags "all=-N -l" \
-ldflags "$LDFLAGS" \
-o event-gateway-controller ./cmd/main; \
else \
go build $COVER_FLAG \
-ldflags "$LDFLAGS" \
-o event-gateway-controller ./cmd/main; \
fi

# Stage: debug (select with --target debug; NOT part of the default build)
FROM golang:1.26.2-bookworm AS debug
WORKDIR /app

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go install github.com/go-delve/delve/cmd/dlv@v1.26.0

COPY --from=builder /build/event-gateway-controller .
COPY --from=target LICENSE /app/LICENSE

RUN mkdir -p /app/data

EXPOSE 2345 9090 18000

ENTRYPOINT ["/go/bin/dlv", "exec", "/app/event-gateway-controller", \
"--listen=:2345", "--headless=true", \
"--api-version=2", "--accept-multiclient", "--"]

# Stage 2: Runtime image
FROM ubuntu:24.04 AS production

ARG VERSION=0.0.1-SNAPSHOT
ARG ENABLE_COVERAGE=false

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
ca-certificates \
wget && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=builder /build/event-gateway-controller .
COPY --from=target LICENSE /app/LICENSE

RUN mkdir -p /app/data && \
if [ "$ENABLE_COVERAGE" = "true" ]; then mkdir -p /coverage; fi

RUN groupadd -r -g 10001 wso2 && \
useradd -r -u 10001 -g wso2 -s /usr/sbin/nologin -c "WSO2 Application User" wso2 && \
chown -R wso2:wso2 /app/data && \
chmod -R 755 /app/data && \
if [ "$ENABLE_COVERAGE" = "true" ]; then \
chown -R wso2:wso2 /coverage && \
chmod -R 755 /coverage; \
fi

ENV GOCOVERDIR=/coverage

USER wso2

EXPOSE 9090 18000

LABEL org.opencontainers.image.title="API Platform Event Gateway Controller"
LABEL org.opencontainers.image.description="Event Gateway Controller with WebSub/WebBroker support and xDS control plane"
LABEL org.opencontainers.image.vendor="WSO2"
LABEL org.opencontainers.image.version="${VERSION}"

ENTRYPOINT ["/app/event-gateway-controller"]
124 changes: 124 additions & 0 deletions event-gateway/gateway-controller/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# --------------------------------------------------------------------
# Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
#
# WSO2 LLC. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# --------------------------------------------------------------------

# Makefile for Event-Gateway Controller

VERSION ?= $(shell cat ../VERSION 2>/dev/null || echo "0.0.1-SNAPSHOT")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION_PKG := github.com/wso2/api-platform/gateway/gateway-controller/pkg/version
LDFLAGS := -X $(VERSION_PKG).Version=$(VERSION) -X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) -X $(VERSION_PKG).BuildDate=$(BUILD_DATE)

DOCKER_REGISTRY ?= ghcr.io/wso2/api-platform
IMAGE_NAME := $(DOCKER_REGISTRY)/event-gateway-controller

.PHONY: help build build-local build-docker build-debug build-and-push-multiarch test clean

help: ## Show this help message
@echo 'Event Gateway Controller Build System (Version: $(VERSION))'
@echo ''
@echo 'Build Targets:'
@echo ' make build - Build Docker image'
@echo ' make build-local - Build event-gateway-controller binary locally'
@echo ' make build-docker - Build Docker image'
@echo ' make build-debug - Build Docker image with Delve remote debugger (port 2345)'
@echo ' make build-and-push-multiarch - Build and push multi-arch Docker image'
@echo ''
@echo 'Test Targets:'
@echo ' make test - Run all tests'
@echo ''
@echo 'Clean Targets:'
@echo ' make clean - Clean build artifacts'

.PHONY: build
build: build-docker ## Build Docker image

.PHONY: build-local
build-local: ## Build event-gateway-controller binary locally
@echo "Building event-gateway-controller binary..."
@mkdir -p target
CGO_ENABLED=1 go build \
-ldflags "$(LDFLAGS)" \
-o target/event-gateway-controller \
./cmd/main
@echo "Binary: target/event-gateway-controller"

.PHONY: build-docker
build-docker: ## Build Docker image using buildx
@echo "Building Docker image ($(IMAGE_NAME):$(VERSION))..."
@mkdir -p ../../target
@cp ../../LICENSE ../../target/
docker buildx build -f Dockerfile \
--build-context sdk-core=../../sdk/core \
--build-context common=../../common \
--build-context gateway-controller=../../gateway/gateway-controller \
--build-context target=../../target \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--target production \
-t $(IMAGE_NAME):$(VERSION) \
--load \
.
@echo "Image built: $(IMAGE_NAME):$(VERSION)"

.PHONY: build-debug
build-debug: ## Build Docker image with Delve debugger (port 2345)
@echo "Building debug Docker image ($(IMAGE_NAME):$(VERSION)-debug)..."
@mkdir -p ../../target
@cp ../../LICENSE ../../target/
docker buildx build -f Dockerfile \
--build-context sdk-core=../../sdk/core \
--build-context common=../../common \
--build-context gateway-controller=../../gateway/gateway-controller \
--build-context target=../../target \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg ENABLE_DEBUG=true \
--target debug \
-t $(IMAGE_NAME):$(VERSION)-debug \
--load \
.

.PHONY: build-and-push-multiarch
build-and-push-multiarch: ## Build and push multi-arch Docker image to registry
@echo "Building and pushing multi-arch image ($(IMAGE_NAME):$(VERSION))..."
@mkdir -p ../../target
@cp ../../LICENSE ../../target/
docker buildx build -f Dockerfile \
--build-context sdk-core=../../sdk/core \
--build-context common=../../common \
--build-context gateway-controller=../../gateway/gateway-controller \
--build-context target=../../target \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--target production \
--platform linux/amd64,linux/arm64 \
-t $(IMAGE_NAME):$(VERSION) \
--push \
.

.PHONY: test
test: ## Run all tests
@echo "Running tests..."
@go test -v ./... -cover -coverprofile=unit-test-coverage.txt

.PHONY: clean
clean: ## Clean build artifacts
@rm -rf target/
@rm -f unit-test-coverage.txt
@echo "Cleaned."
41 changes: 41 additions & 0 deletions event-gateway/gateway-controller/cmd/main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package main

import (
"flag"
"fmt"
"os"

"github.com/wso2/api-platform/event-gateway/gateway-controller/pkg/eventgateway"
"github.com/wso2/api-platform/gateway/gateway-controller/pkg/bootstrap"
)

func main() {
configPath := flag.String("config", "", "Path to configuration file (required)")
flag.Parse()

if *configPath == "" {
fmt.Fprintf(os.Stderr, "Error: -config flag is required\n")
fmt.Fprintf(os.Stderr, "Usage: %s -config <path-to-config.toml>\n", os.Args[0])
os.Exit(1)
}

bootstrap.Run(*configPath, eventgateway.NewExtension())
}
Loading
Loading