From eb4366c2960cb5f2edb81d797635575be55de5bc Mon Sep 17 00:00:00 2001 From: chrisghill Date: Thu, 9 Oct 2025 17:42:05 -0600 Subject: [PATCH 1/6] fully swap over to bundle versioning --- .devcontainer/Dockerfile | 17 ---------- .github/workflows/local-prov.yaml | 37 --------------------- cmd/bundle.go | 46 +++----------------------- go.mod | 1 - go.sum | 2 -- src/bundle/pull.go | 37 +-------------------- src/bundle/pull_test.go | 54 ++----------------------------- 7 files changed, 8 insertions(+), 186 deletions(-) delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .github/workflows/local-prov.yaml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 3c82a62..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/go/.devcontainer/base.Dockerfile - -# [Choice] Go version: 1, 1.16, 1.15 -ARG VARIANT="1.17" -FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT} - -ENV GOPRIVATE=github.com/massdriver-cloud - -# [Optional] Uncomment this section to install additional OS packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends - -# [Optional] Uncomment the next line to use go get to install anything else you need -# RUN go get -x - -# [Optional] Uncomment this line to install global node packages. -# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.github/workflows/local-prov.yaml b/.github/workflows/local-prov.yaml deleted file mode 100644 index 3208beb..0000000 --- a/.github/workflows/local-prov.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name: Build and Push Local Provisioner -on: - push: - # Pattern matched against refs/tags - tags: - - "*" - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - with: - platforms: arm64 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.PUBLIC_DOCKER_HUB_USERNAME }} - password: ${{ secrets.PUBLIC_DOCKER_HUB_ACCESS_TOKEN }} - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: | - ${{ secrets.PUBLIC_DOCKER_HUB_USERNAME }}/local-terraform-provisioner - tags: | - type=semver,pattern={{version}} - - name: Build and push - uses: docker/build-push-action@v5 - with: - file: Dockerfile.Prov - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} diff --git a/cmd/bundle.go b/cmd/bundle.go index 7d88747..d466324 100644 --- a/cmd/bundle.go +++ b/cmd/bundle.go @@ -2,9 +2,7 @@ package cmd import ( "fmt" - "os" "xo/src/bundle" - "xo/src/massdriver" "xo/src/telemetry" "github.com/massdriver-cloud/massdriver-sdk-go/massdriver/client" @@ -22,12 +20,6 @@ var bundleCmd = &cobra.Command{ Long: ``, } -var bundlePullv0Cmd = &cobra.Command{ - Use: "pullv0", - Short: "Pulls a bundle from Massdriver", - RunE: runBundlePullv0, -} - var bundlePullCmd = &cobra.Command{ Use: "pull", Short: "Pulls a bundle from Massdriver", @@ -37,41 +29,13 @@ var bundlePullCmd = &cobra.Command{ func init() { rootCmd.AddCommand(bundleCmd) - bundleCmd.AddCommand(bundlePullv0Cmd) - bundleCmd.AddCommand(bundlePullCmd) - bundlePullCmd.Flags().StringP("tag", "t", "latest", "Bundle tag (defaults to 'latest')") + bundlePullCmd.Flags().StringP("version", "v", "latest", "Bundle version (defaults to 'latest')") bundlePullCmd.Flags().StringP("name", "n", "", "Bundle name") - viper.BindPFlag("bundle.tag", bundlePullCmd.Flags().Lookup("tag")) + viper.BindPFlag("bundle.version", bundlePullCmd.Flags().Lookup("version")) viper.BindPFlag("bundle.name", bundlePullCmd.Flags().Lookup("name")) } -func runBundlePullv0(cmd *cobra.Command, args []string) error { - ctx, span := otel.Tracer("xo").Start(telemetry.GetContextWithTraceParentFromEnv(), "runBundlePull") - telemetry.SetSpanAttributes(span) - defer span.End() - - client, initErr := massdriver.InitializeMassdriverClient() - if initErr != nil { - return telemetry.LogError(span, initErr, "an error occurred while initializing massdriver client") - } - - outFile, openErr := os.OpenFile("bundle.tar.gz", os.O_CREATE|os.O_WRONLY, 0644) - if openErr != nil { - return telemetry.LogError(span, openErr, "unable to open bundle.tar.gz file") - } - defer outFile.Close() - - log.Info().Msg("pulling bundle...") - pullErr := bundle.PullV0(ctx, client, outFile) - if pullErr != nil { - return telemetry.LogError(span, pullErr, "an error occurred while pulling bundle") - } - log.Info().Msg("bundle pulled") - - return nil -} - func runBundlePull(cmd *cobra.Command, args []string) error { ctx, span := otel.Tracer("xo").Start(telemetry.GetContextWithTraceParentFromEnv(), "runBundlePull") telemetry.SetSpanAttributes(span) @@ -81,7 +45,7 @@ func runBundlePull(cmd *cobra.Command, args []string) error { if bundleName == "" { return fmt.Errorf("required flag bundleName must be set via flag or environment variable") } - tag := viper.GetString("bundle.tag") + bundleVersion := viper.GetString("bundle.version") mdClient, clientErr := client.New() if clientErr != nil { @@ -99,8 +63,8 @@ func runBundlePull(cmd *cobra.Command, args []string) error { } defer fileStore.Close() - log.Info().Msg("pulling bundle...") - desc, pullErr := bundle.PullV1(ctx, repo, fileStore, tag) + log.Info().Msgf("pulling bundle %s:%s...", bundleName, bundleVersion) + desc, pullErr := bundle.Pull(ctx, repo, fileStore, bundleVersion) if pullErr != nil { return telemetry.LogError(span, pullErr, "an error occurred while pulling bundle") } diff --git a/go.mod b/go.mod index 21eb8e7..0a3a02c 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/honeycombio/honeycomb-opentelemetry-go v0.11.0 github.com/honeycombio/otel-config-go v1.17.0 github.com/kelseyhightower/envconfig v1.4.0 - github.com/massdriver-cloud/mass v0.0.0-20240819225958-4ef28e971211 github.com/massdriver-cloud/massdriver-sdk-go v0.0.8 github.com/massdriver-cloud/terraform-config-inspect v0.0.0-20240906041648-e5461c213cea github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index b1a8d8e..77da6b2 100644 --- a/go.sum +++ b/go.sum @@ -57,8 +57,6 @@ github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMD github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/massdriver-cloud/mass v0.0.0-20240819225958-4ef28e971211 h1:AipPe343bMha9B5x3xlMUCiKZkyyIRD6D4FXBvbbTbg= -github.com/massdriver-cloud/mass v0.0.0-20240819225958-4ef28e971211/go.mod h1:VJMa3gsc/wmGE61ZicpBQv1xv8JjIPzHpJK2gZYEgqI= github.com/massdriver-cloud/massdriver-sdk-go v0.0.8 h1:YMrUjVmJrl8dy5jpV3r/cm2MVSPCi9vpescKsHNrcxc= github.com/massdriver-cloud/massdriver-sdk-go v0.0.8/go.mod h1:6bXMPQmfeKHD3Tm/cwnrkqiZaDEgRUUq0+uZckKRsbM= github.com/massdriver-cloud/terraform-config-inspect v0.0.0-20240906041648-e5461c213cea h1:+fS2DYjasqMDMzVeKJTiBLbqYJjv93MTf1yZV2nxjf8= diff --git a/src/bundle/pull.go b/src/bundle/pull.go index 134273e..84475c9 100644 --- a/src/bundle/pull.go +++ b/src/bundle/pull.go @@ -2,50 +2,15 @@ package bundle import ( "context" - "encoding/base64" - "fmt" - "io" - "xo/src/api" - "xo/src/massdriver" "xo/src/telemetry" v1 "github.com/opencontainers/image-spec/specs-go/v1" "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/codes" oras "oras.land/oras-go/v2" ) -func PullV0(ctx context.Context, client *massdriver.MassdriverClient, outFile io.Writer) error { - _, span := otel.Tracer("xo").Start(ctx, "BundlePull") - telemetry.SetSpanAttributes(span) - defer span.End() - - bundleBytes, getErr := api.GetBundleSourceCode(client.GQLCLient, client.Specification.BundleID, client.Specification.OrganizationUUID) - if getErr != nil { - span.RecordError(getErr) - span.SetStatus(codes.Error, getErr.Error()) - return fmt.Errorf("an error occurred while getting bundle source code: %w", getErr) - } - - decodedBundleBytes, decodeErr := base64.StdEncoding.DecodeString(string(bundleBytes)) - if decodeErr != nil { - span.RecordError(decodeErr) - span.SetStatus(codes.Error, decodeErr.Error()) - return fmt.Errorf("an error occurred while decoding bundle source code: %w", decodeErr) - } - - _, writeErr := outFile.Write(decodedBundleBytes) - if writeErr != nil { - span.RecordError(writeErr) - span.SetStatus(codes.Error, writeErr.Error()) - return fmt.Errorf("an error occurred while writing bundle source code: %w", writeErr) - } - - return nil -} - -func PullV1(ctx context.Context, repo oras.Target, target oras.Target, tag string) (v1.Descriptor, error) { +func Pull(ctx context.Context, repo oras.Target, target oras.Target, tag string) (v1.Descriptor, error) { _, span := otel.Tracer("xo").Start(ctx, "BundlePullV1") telemetry.SetSpanAttributes(span) defer span.End() diff --git a/src/bundle/pull_test.go b/src/bundle/pull_test.go index dd8fd73..653213f 100644 --- a/src/bundle/pull_test.go +++ b/src/bundle/pull_test.go @@ -3,67 +3,17 @@ package bundle_test import ( "bytes" "context" - "encoding/base64" "encoding/json" "testing" "xo/src/bundle" - "xo/src/massdriver" - "github.com/massdriver-cloud/mass/pkg/gqlmock" ocispec "github.com/opencontainers/image-spec/specs-go/v1" oras "oras.land/oras-go/v2" "oras.land/oras-go/v2/content" "oras.land/oras-go/v2/content/memory" ) -func TestPullV0(t *testing.T) { - type testData struct { - name string - data []byte - } - tests := []testData{ - { - name: "basic", - data: []byte(`data`), - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - gqlClient := gqlmock.NewClientWithSingleJSONResponse(map[string]interface{}{ - "data": map[string]interface{}{ - "bundleSourceCode": map[string]interface{}{ - "source": base64.StdEncoding.EncodeToString(tc.data), - }, - }, - }) - - client := massdriver.MassdriverClient{ - GQLCLient: gqlClient, - Specification: &massdriver.Specification{ - BundleID: "bundleuuid1", - OrganizationUUID: "orguuid1", - }, - } - - buf := new(bytes.Buffer) - - pullErr := bundle.PullV0(context.Background(), &client, buf) - if pullErr != nil { - t.Errorf("pull failed: %v", pullErr) - } - - got := buf.String() - want := string(tc.data) - if got != want { - t.Errorf("got %v, want %v", got, want) - } - }) - } - -} - -func TestPullV1(t *testing.T) { +func TestPull(t *testing.T) { ctx := context.Background() // Pre-populate source store with fake files @@ -130,7 +80,7 @@ func TestPullV1(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - desc, pullErr := bundle.PullV1(ctx, tc.sourceRepo, tc.target, tc.tag) + desc, pullErr := bundle.Pull(ctx, tc.sourceRepo, tc.target, tc.tag) if (pullErr != nil) != tc.wantErr { t.Fatalf("PullV1WithRepo() error = %v, wantErr %v", pullErr, tc.wantErr) } From 2d6866773ce3b5d35a7b1685d3b5b3dfb03f32be Mon Sep 17 00:00:00 2001 From: chrisghill Date: Thu, 9 Oct 2025 17:43:17 -0600 Subject: [PATCH 2/6] default to 0.0.0 --- cmd/bundle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/bundle.go b/cmd/bundle.go index d466324..91112ff 100644 --- a/cmd/bundle.go +++ b/cmd/bundle.go @@ -30,7 +30,7 @@ func init() { rootCmd.AddCommand(bundleCmd) bundleCmd.AddCommand(bundlePullCmd) - bundlePullCmd.Flags().StringP("version", "v", "latest", "Bundle version (defaults to 'latest')") + bundlePullCmd.Flags().StringP("version", "v", "0.0.0", "Bundle version (defaults to '0.0.0')") bundlePullCmd.Flags().StringP("name", "n", "", "Bundle name") viper.BindPFlag("bundle.version", bundlePullCmd.Flags().Lookup("version")) viper.BindPFlag("bundle.name", bundlePullCmd.Flags().Lookup("name")) From 6dbca75a4d7d4080551a4c64af049a894601e3ac Mon Sep 17 00:00:00 2001 From: chrisghill Date: Thu, 9 Oct 2025 17:44:23 -0600 Subject: [PATCH 3/6] remove v1 references --- src/bundle/pull.go | 2 +- src/bundle/pull_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bundle/pull.go b/src/bundle/pull.go index 84475c9..5ee8643 100644 --- a/src/bundle/pull.go +++ b/src/bundle/pull.go @@ -11,7 +11,7 @@ import ( ) func Pull(ctx context.Context, repo oras.Target, target oras.Target, tag string) (v1.Descriptor, error) { - _, span := otel.Tracer("xo").Start(ctx, "BundlePullV1") + _, span := otel.Tracer("xo").Start(ctx, "BundlePull") telemetry.SetSpanAttributes(span) defer span.End() diff --git a/src/bundle/pull_test.go b/src/bundle/pull_test.go index 653213f..7502fd5 100644 --- a/src/bundle/pull_test.go +++ b/src/bundle/pull_test.go @@ -82,7 +82,7 @@ func TestPull(t *testing.T) { t.Run(tc.name, func(t *testing.T) { desc, pullErr := bundle.Pull(ctx, tc.sourceRepo, tc.target, tc.tag) if (pullErr != nil) != tc.wantErr { - t.Fatalf("PullV1WithRepo() error = %v, wantErr %v", pullErr, tc.wantErr) + t.Fatalf("Pull error = %v, wantErr %v", pullErr, tc.wantErr) } if tc.wantErr { return From 112341e221fc149526960be9ac7353b0e850a812 Mon Sep 17 00:00:00 2001 From: chrisghill Date: Thu, 9 Oct 2025 17:53:33 -0600 Subject: [PATCH 4/6] remove deprecated envs --- src/massdriver/main.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/massdriver/main.go b/src/massdriver/main.go index 19aa3e7..bcaf086 100644 --- a/src/massdriver/main.go +++ b/src/massdriver/main.go @@ -18,19 +18,13 @@ type MassdriverClient struct { } type Specification struct { - Action string `envconfig:"ACTION"` - BundleID string `envconfig:"BUNDLE_ID" required:"true"` - BundleName string `envconfig:"BUNDLE_NAME"` - BundleType string `envconfig:"BUNDLE_TYPE"` - DeploymentID string `envconfig:"DEPLOYMENT_ID" required:"true"` - ManifestID string `envconfig:"MANIFEST_ID"` - OrganizationUUID string `envconfig:"ORGANIZATION_UUID" required:"true"` - OrganizationID string `envconfig:"ORGANIZATION_ID" required:"true"` - PackageID string `envconfig:"PACKAGE_ID" required:"true"` - PackageName string `envconfig:"PACKAGE_NAME" required:"true"` - TargetMode string `envconfig:"TARGET_MODE"` - Token string `envconfig:"TOKEN" required:"true"` - URL string `envconfig:"URL"` + Action string `envconfig:"ACTION"` + BundleName string `envconfig:"BUNDLE_NAME"` + DeploymentID string `envconfig:"DEPLOYMENT_ID" required:"true"` + OrganizationID string `envconfig:"ORGANIZATION_ID" required:"true"` + PackageName string `envconfig:"PACKAGE_NAME" required:"true"` + Token string `envconfig:"TOKEN" required:"true"` + URL string `envconfig:"URL"` } func InitializeMassdriverClient() (*MassdriverClient, error) { From bfae92a1deb88f0fd42a6ea03d5b0b4e7f0d149f Mon Sep 17 00:00:00 2001 From: chrisghill Date: Thu, 9 Oct 2025 18:08:36 -0600 Subject: [PATCH 5/6] remove timestamp and level on logs --- cmd/root.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index f55d3ca..15e7668 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -83,5 +83,13 @@ func initLogging() { default: zerolog.SetGlobalLevel(zerolog.InfoLevel) } - log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout}) + log.Logger = log.Output(zerolog.ConsoleWriter{ + Out: os.Stdout, + FormatTimestamp: func(i interface{}) string { + return "" + }, + FormatLevel: func(i interface{}) string { + return "" + }, + }) } From 7b4d018612dd2d3986fa9dc464b8059c581d7d5a Mon Sep 17 00:00:00 2001 From: chrisghill Date: Thu, 9 Oct 2025 18:14:24 -0600 Subject: [PATCH 6/6] add proper errors --- cmd/bundle.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/bundle.go b/cmd/bundle.go index 91112ff..e04464d 100644 --- a/cmd/bundle.go +++ b/cmd/bundle.go @@ -30,7 +30,7 @@ func init() { rootCmd.AddCommand(bundleCmd) bundleCmd.AddCommand(bundlePullCmd) - bundlePullCmd.Flags().StringP("version", "v", "0.0.0", "Bundle version (defaults to '0.0.0')") + bundlePullCmd.Flags().StringP("version", "v", "", "Bundle version") bundlePullCmd.Flags().StringP("name", "n", "", "Bundle name") viper.BindPFlag("bundle.version", bundlePullCmd.Flags().Lookup("version")) viper.BindPFlag("bundle.name", bundlePullCmd.Flags().Lookup("name")) @@ -43,9 +43,12 @@ func runBundlePull(cmd *cobra.Command, args []string) error { bundleName := viper.GetString("bundle.name") if bundleName == "" { - return fmt.Errorf("required flag bundleName must be set via flag or environment variable") + return telemetry.LogError(span, fmt.Errorf("required flag bundleName must be set via flag or environment variable"), "an error occurred while pulling bundle") } bundleVersion := viper.GetString("bundle.version") + if bundleVersion == "" { + return telemetry.LogError(span, fmt.Errorf("required flag bundleVersion must be set via flag or environment variable"), "an error occurred while pulling bundle") + } mdClient, clientErr := client.New() if clientErr != nil { @@ -54,12 +57,12 @@ func runBundlePull(cmd *cobra.Command, args []string) error { repo, repoErr := sdkbundle.GetBundleRepository(mdClient, bundleName) if repoErr != nil { - return repoErr + return telemetry.LogError(span, repoErr, "an error occurred while getting bundle repository") } fileStore, fileErr := file.New("bundle") if fileErr != nil { - return fileErr + return telemetry.LogError(span, fileErr, "an error occurred while creating file store") } defer fileStore.Close()