diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ff8479e..4aa1f1c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,9 +12,7 @@ metadata: report_sizes: true builds: - - dir: ./cmd - main: . - binary: caddy-gateway + - binary: caddy-gateway env: - CGO_ENABLED=0 goos: diff --git a/Containerfile b/Containerfile index 35c0022..9fbf69e 100644 --- a/Containerfile +++ b/Containerfile @@ -12,22 +12,21 @@ COPY go.sum go.sum RUN go mod download # Copy the go source -COPY cmd/main.go cmd/main.go +COPY main.go main.go COPY internal/ internal/ -COPY gateway.go gateway.go # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -v -trimpath -a -o manager github.com/caddyserver/gateway/cmd +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -v -trimpath -a -o caddy-gateway github.com/caddyserver/gateway -# Use distroless as minimal base image to package the manager binary +# Use distroless as minimal base image to package the caddy-gateway binary # Refer to https://github.com/GoogleContainerTools/distroless for more details FROM gcr.io/distroless/static:nonroot WORKDIR / -COPY --from=builder /workspace/manager . +COPY --from=builder /workspace/caddy-gateway . USER 65532:65532 -ENTRYPOINT ["/manager"] +ENTRYPOINT ["/caddy-gateway"] diff --git a/Makefile b/Makefile index a4fb94d..3456ed5 100644 --- a/Makefile +++ b/Makefile @@ -134,11 +134,11 @@ lint-fix: ## Run golangci-lint linter and perform fixes .PHONY: build build: manifests generate fmt vet ## Build manager binary. - go build -o bin/manager cmd/main.go + go build -o bin/manager ./main.go .PHONY: run run: manifests generate fmt vet ## Run a controller from your host. - go run -v -trimpath ./cmd/main.go + go run -v -trimpath ./main.go # If you wish to build the manager image targeting other platforms you can use the --platform flag. # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. diff --git a/internal/caddy/caddy.go b/internal/caddy/caddy.go index da609d2..47d5d92 100644 --- a/internal/caddy/caddy.go +++ b/internal/caddy/caddy.go @@ -15,7 +15,7 @@ import ( gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" caddyv2 "github.com/caddyserver/gateway/internal/caddyv2" "github.com/caddyserver/gateway/internal/caddyv2/caddyhttp" "github.com/caddyserver/gateway/internal/caddyv2/caddytls" diff --git a/internal/caddy/http.go b/internal/caddy/http.go index dc0fe61..c6281b6 100644 --- a/internal/caddy/http.go +++ b/internal/caddy/http.go @@ -18,7 +18,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" caddy "github.com/caddyserver/gateway/internal/caddyv2" "github.com/caddyserver/gateway/internal/caddyv2/caddyhttp" "github.com/caddyserver/gateway/internal/caddyv2/caddyhttp/headers" diff --git a/internal/caddy/tls.go b/internal/caddy/tls.go index 850992c..0139b1e 100644 --- a/internal/caddy/tls.go +++ b/internal/caddy/tls.go @@ -11,7 +11,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" "github.com/caddyserver/gateway/internal/caddyv2/caddytls" ) diff --git a/internal/controller/controller.go b/internal/controller/controller.go index c93f632..43475f7 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -18,7 +18,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" ) // Add RBAC permissions to get CRDs, so we can verify that the gateway-api CRDs diff --git a/internal/controller/gateway.go b/internal/controller/gateway.go index bf1e8a7..e62433c 100644 --- a/internal/controller/gateway.go +++ b/internal/controller/gateway.go @@ -37,7 +37,7 @@ import ( gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" "github.com/caddyserver/gateway/internal/caddy" ) diff --git a/internal/controller/gateway_class.go b/internal/controller/gateway_class.go index 3c9e2fa..07f94c7 100644 --- a/internal/controller/gateway_class.go +++ b/internal/controller/gateway_class.go @@ -20,7 +20,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" ) // +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses,verbs=get;list;watch diff --git a/internal/controller/route.go b/internal/controller/route.go index c1844d1..699668e 100644 --- a/internal/controller/route.go +++ b/internal/controller/route.go @@ -13,7 +13,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" ) func isAttachable(_ context.Context, gw *gatewayv1.Gateway, route metav1.Object, parents []gatewayv1.RouteParentStatus) bool { diff --git a/internal/controller/route_http.go b/internal/controller/route_http.go index 2529e0a..bc1f3a9 100644 --- a/internal/controller/route_http.go +++ b/internal/controller/route_http.go @@ -26,7 +26,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" "github.com/caddyserver/gateway/internal/routechecks" ) diff --git a/gateway.go b/internal/gateway.go similarity index 100% rename from gateway.go rename to internal/gateway.go diff --git a/internal/routechecks/hostnames.go b/internal/routechecks/hostnames.go index 516f63c..36648fa 100644 --- a/internal/routechecks/hostnames.go +++ b/internal/routechecks/hostnames.go @@ -6,7 +6,7 @@ package routechecks import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" ) func computeHosts[T ~string](gw *gatewayv1.Gateway, hostnames []T) []string { diff --git a/internal/routechecks/route_http.go b/internal/routechecks/route_http.go index 55c0b19..b52e9f2 100644 --- a/internal/routechecks/route_http.go +++ b/internal/routechecks/route_http.go @@ -16,7 +16,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" ) type HTTPRouteInput struct { diff --git a/internal/routechecks/routes.go b/internal/routechecks/routes.go index b8d602f..9d24510 100644 --- a/internal/routechecks/routes.go +++ b/internal/routechecks/routes.go @@ -11,7 +11,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - "github.com/caddyserver/gateway" + gateway "github.com/caddyserver/gateway/internal" ) func CheckAgainstCrossNamespaceBackendReferences(input Input) (bool, error) { diff --git a/cmd/main.go b/main.go similarity index 100% rename from cmd/main.go rename to main.go