From 8e3d1ecf33a3b903251d2c411363402a4a043225 Mon Sep 17 00:00:00 2001 From: Scot Wells Date: Fri, 13 Dec 2024 20:34:47 +0000 Subject: [PATCH] restructure repo --- .github/workflows/build.yaml | 23 +++++++++++++++---- .../datum-authorization-webhook/Dockerfile | 6 ++--- .../iam/core_control_plane_authorizer.go | 0 .../iam/project_control_plane_authorizer.go | 0 .../app}/internal/webhook/http.go | 0 .../app}/internal/webhook/response.go | 0 .../app}/internal/webhook/webhook.go | 0 .../datum-authorization-webhook/app}/serve.go | 6 ++--- .../app}/webhook.go | 4 ++-- cmd/datum-authorization-webhook/webhook.go | 15 ++++++++++++ internal/cmd/root.go | 19 --------------- main.go | 15 ------------ 12 files changed, 42 insertions(+), 46 deletions(-) rename Dockerfile => cmd/datum-authorization-webhook/Dockerfile (74%) rename {internal/authorization-webhook => cmd/datum-authorization-webhook/app}/internal/iam/core_control_plane_authorizer.go (100%) rename {internal/authorization-webhook => cmd/datum-authorization-webhook/app}/internal/iam/project_control_plane_authorizer.go (100%) rename {internal/authorization-webhook => cmd/datum-authorization-webhook/app}/internal/webhook/http.go (100%) rename {internal/authorization-webhook => cmd/datum-authorization-webhook/app}/internal/webhook/response.go (100%) rename {internal/authorization-webhook => cmd/datum-authorization-webhook/app}/internal/webhook/webhook.go (100%) rename {internal/authorization-webhook/cmd => cmd/datum-authorization-webhook/app}/serve.go (96%) rename {internal/authorization-webhook/cmd => cmd/datum-authorization-webhook/app}/webhook.go (82%) create mode 100644 cmd/datum-authorization-webhook/webhook.go delete mode 100644 internal/cmd/root.go delete mode 100644 main.go diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 53c91aa..648dbf9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,8 +2,8 @@ name: Build and Publish Docker Image on: push: - branches: - - main + # branches: + # - main pull_request: jobs: @@ -15,6 +15,13 @@ jobs: id-token: write runs-on: ubuntu-latest + + # Define the services that should be built. + strategy: + matrix: + service: + - datum-authorization-webhook + steps: - name: Checkout repository uses: actions/checkout@v3 @@ -30,7 +37,7 @@ jobs: id: meta uses: docker/metadata-action@v5.5.1 with: - images: ghcr.io/datum-cloud/datum + images: ghcr.io/datum-cloud/${{ matrix.service }} tags: | type=schedule type=ref,event=branch @@ -40,11 +47,19 @@ jobs: type=semver,pattern={{major}} type=sha - - name: Build and push Docker image + - name: Build ${{ matrix.service }} id: push uses: docker/build-push-action@v6.7.0 with: context: . + file: cmd/${{ matrix.service }}/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ghcr.io/datum-cloud/${{ matrix.service }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/Dockerfile b/cmd/datum-authorization-webhook/Dockerfile similarity index 74% rename from Dockerfile rename to cmd/datum-authorization-webhook/Dockerfile index e592d1d..d0227cb 100644 --- a/Dockerfile +++ b/cmd/datum-authorization-webhook/Dockerfile @@ -12,10 +12,10 @@ RUN go mod download COPY . . # Build the application -RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o datum . +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o datum-authorization-webhook ./cmd/datum-authorization-webhook # Use a minimal image for the final container FROM gcr.io/distroless/static WORKDIR /app -COPY --from=builder /app/datum . -ENTRYPOINT ["/app/datum"] +COPY --from=builder /app/datum-authorization-webhook . +ENTRYPOINT ["/app/datum-authorization-webhook"] diff --git a/internal/authorization-webhook/internal/iam/core_control_plane_authorizer.go b/cmd/datum-authorization-webhook/app/internal/iam/core_control_plane_authorizer.go similarity index 100% rename from internal/authorization-webhook/internal/iam/core_control_plane_authorizer.go rename to cmd/datum-authorization-webhook/app/internal/iam/core_control_plane_authorizer.go diff --git a/internal/authorization-webhook/internal/iam/project_control_plane_authorizer.go b/cmd/datum-authorization-webhook/app/internal/iam/project_control_plane_authorizer.go similarity index 100% rename from internal/authorization-webhook/internal/iam/project_control_plane_authorizer.go rename to cmd/datum-authorization-webhook/app/internal/iam/project_control_plane_authorizer.go diff --git a/internal/authorization-webhook/internal/webhook/http.go b/cmd/datum-authorization-webhook/app/internal/webhook/http.go similarity index 100% rename from internal/authorization-webhook/internal/webhook/http.go rename to cmd/datum-authorization-webhook/app/internal/webhook/http.go diff --git a/internal/authorization-webhook/internal/webhook/response.go b/cmd/datum-authorization-webhook/app/internal/webhook/response.go similarity index 100% rename from internal/authorization-webhook/internal/webhook/response.go rename to cmd/datum-authorization-webhook/app/internal/webhook/response.go diff --git a/internal/authorization-webhook/internal/webhook/webhook.go b/cmd/datum-authorization-webhook/app/internal/webhook/webhook.go similarity index 100% rename from internal/authorization-webhook/internal/webhook/webhook.go rename to cmd/datum-authorization-webhook/app/internal/webhook/webhook.go diff --git a/internal/authorization-webhook/cmd/serve.go b/cmd/datum-authorization-webhook/app/serve.go similarity index 96% rename from internal/authorization-webhook/cmd/serve.go rename to cmd/datum-authorization-webhook/app/serve.go index 3e950ed..66a2b60 100644 --- a/internal/authorization-webhook/cmd/serve.go +++ b/cmd/datum-authorization-webhook/app/serve.go @@ -1,12 +1,12 @@ -package cmd +package app import ( "context" "fmt" "buf.build/gen/go/datum-cloud/iam/grpc/go/datum/iam/v1alpha/iamv1alphagrpc" - "go.datumapis.com/datum/internal/authorization-webhook/internal/iam" - authwebhook "go.datumapis.com/datum/internal/authorization-webhook/internal/webhook" + "go.datumapis.com/datum/cmd/datum-authorization-webhook/app/internal/iam" + authwebhook "go.datumapis.com/datum/cmd/datum-authorization-webhook/app/internal/webhook" "github.com/spf13/cobra" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" diff --git a/internal/authorization-webhook/cmd/webhook.go b/cmd/datum-authorization-webhook/app/webhook.go similarity index 82% rename from internal/authorization-webhook/cmd/webhook.go rename to cmd/datum-authorization-webhook/app/webhook.go index 4031c6a..cbadacd 100644 --- a/internal/authorization-webhook/cmd/webhook.go +++ b/cmd/datum-authorization-webhook/app/webhook.go @@ -1,8 +1,8 @@ -package cmd +package app import "github.com/spf13/cobra" -func Webhook() *cobra.Command { +func NewWebhook() *cobra.Command { cmd := &cobra.Command{ Use: "authorization-webhook", Short: "An authorization webhook backed by the Datum IAM service", diff --git a/cmd/datum-authorization-webhook/webhook.go b/cmd/datum-authorization-webhook/webhook.go new file mode 100644 index 0000000..4f068b0 --- /dev/null +++ b/cmd/datum-authorization-webhook/webhook.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "os" + + "go.datumapis.com/datum/cmd/datum-authorization-webhook/app" +) + +func main() { + if err := app.NewWebhook().Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/internal/cmd/root.go b/internal/cmd/root.go deleted file mode 100644 index bdf53ce..0000000 --- a/internal/cmd/root.go +++ /dev/null @@ -1,19 +0,0 @@ -package cmd - -import ( - "github.com/spf13/cobra" - "go.datumapis.com/datum/internal/authorization-webhook/cmd" -) - -var webhook = &cobra.Command{ - Use: "datum", - Short: "Datum Cloud", -} - -func init() { - webhook.AddCommand(cmd.Webhook()) -} - -func Execute() error { - return webhook.Execute() -} diff --git a/main.go b/main.go deleted file mode 100644 index e7ac067..0000000 --- a/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "go.datumapis.com/datum/internal/cmd" -) - -func main() { - if err := cmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) - } -}