Skip to content

Commit

Permalink
Update docker mixin to porter rc.2 (#40)
Browse files Browse the repository at this point in the history
* Update docker mixin to porter rc.2

* Bump Go to 1.18.6
* Bump Porter to 1.0.0-rc.2
* Update code to compile against rc.2
* Update mixin to support tracing. This doesn't instrument the mixin. It just updates the entrypoint so that it starts a root span and saves the resulting TraceLogger on the context so that later, we can use tracing.StartSpan or tracing.LoggerFromContext and get back an initialized logger.

Signed-off-by: Carolyn Van Slyck <[email protected]>

* Update example for porter rc2

Signed-off-by: Carolyn Van Slyck <[email protected]>

* Final bump to rc.2

Signed-off-by: Carolyn Van Slyck <[email protected]>

Signed-off-by: Carolyn Van Slyck <[email protected]>
  • Loading branch information
carolynvs authored Sep 21, 2022
1 parent 8b08238 commit c12d7c8
Show file tree
Hide file tree
Showing 17 changed files with 1,263 additions and 280 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pool:
steps:
- task: GoTool@0
inputs:
version: '1.17.8'
version: '1.18.6'
displayName: 'Install Go'

- script: go run mage.go ConfigureAgent
Expand Down
2 changes: 1 addition & 1 deletion cmd/docker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func buildBuildCommand(m *docker.Mixin) *cobra.Command {
Use: "build",
Short: "Generate Dockerfile lines for the bundle invocation image",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Build()
return m.Build(cmd.Context())
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/docker/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func buildInstallCommand(m *docker.Mixin) *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return m.Execute()
return m.Execute(cmd.Context())
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/docker/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func buildInvokeCommand(m *docker.Mixin) *cobra.Command {
Use: "invoke",
Short: "Execute the invoke functionality of this mixin",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Execute()
return m.Execute(cmd.Context())
},
}

Expand Down
54 changes: 41 additions & 13 deletions cmd/docker/main.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,69 @@
package main

import (
"context"
"fmt"
"io"
"os"
"runtime/debug"

"get.porter.sh/mixin/docker/pkg/docker"
"get.porter.sh/porter/pkg/cli"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel/attribute"
)

func main() {
cmd, err := buildRootCommand(os.Stdin)
if err != nil {
fmt.Printf("err: %s\n", err)
os.Exit(1)
}
if err := cmd.Execute(); err != nil {
fmt.Printf("err: %s\n", err)
os.Exit(1)
run := func() int {
ctx := context.Background()
m := docker.New()
if err := m.ConfigureLogging(ctx); err != nil {
fmt.Println(err)
os.Exit(cli.ExitCodeErr)
}
cmd := buildRootCommand(m, os.Stdin)

// We don't have tracing working inside a bundle working currently.
// We are using StartRootSpan anyway because it creates a TraceLogger and sets it
// on the context, so we can grab it later
ctx, log := m.StartRootSpan(ctx, "docker")
defer func() {
// Capture panics and trace them
if panicErr := recover(); panicErr != nil {
log.Error(fmt.Errorf("%s", panicErr),
attribute.Bool("panic", true),
attribute.String("stackTrace", string(debug.Stack())))
log.EndSpan()
m.Close()
os.Exit(cli.ExitCodeErr)
} else {
log.Close()
m.Close()
}
}()

if err := cmd.ExecuteContext(ctx); err != nil {
return cli.ExitCodeErr
}
return cli.ExitCodeSuccess
}
os.Exit(run())
}

func buildRootCommand(in io.Reader) (*cobra.Command, error) {
m := docker.New()
m.In = in
func buildRootCommand(m *docker.Mixin, in io.Reader) *cobra.Command {
cmd := &cobra.Command{
Use: "docker",
Long: "Use the docker CLI with Porter",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Enable swapping out stdout/stderr for testing
m.In = in
m.Out = cmd.OutOrStdout()
m.Err = cmd.OutOrStderr()
},
SilenceUsage: true,
}

cmd.PersistentFlags().BoolVar(&m.Debug, "debug", false, "Enable debug logging")
cmd.PersistentFlags().BoolVar(&m.DebugMode, "debug", false, "Enable debug logging")

cmd.AddCommand(buildVersionCommand(m))
cmd.AddCommand(buildSchemaCommand(m))
Expand All @@ -45,5 +73,5 @@ func buildRootCommand(in io.Reader) (*cobra.Command, error) {
cmd.AddCommand(buildUpgradeCommand(m))
cmd.AddCommand(buildUninstallCommand(m))

return cmd, nil
return cmd
}
2 changes: 1 addition & 1 deletion cmd/docker/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func buildUninstallCommand(m *docker.Mixin) *cobra.Command {
Use: "uninstall",
Short: "Execute the uninstall functionality of this mixin",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Execute()
return m.Execute(cmd.Context())
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/docker/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func buildUpgradeCommand(m *docker.Mixin) *cobra.Command {
Use: "upgrade",
Short: "Execute the invoke functionality of this mixin",
RunE: func(cmd *cobra.Command, args []string) error {
return m.Execute()
return m.Execute(cmd.Context())
},
}
return cmd
Expand Down
5 changes: 3 additions & 2 deletions examples/docker-mixin-test/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
schemaVersion: 1.0.0
name: whalesay
version: 0.1.1
version: 0.2.0
description: "An example bundle that uses docker through the magic of whalespeak"
tag: gmadhok/porter-hello/whalesay-mixin:v0.1.1
registry: localhost:5000/docker-mixin-test

required:
- docker
Expand Down
173 changes: 99 additions & 74 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,113 +12,138 @@ replace (
)

require (
get.porter.sh/porter v1.0.0-alpha.12
get.porter.sh/magefiles v0.3.2
get.porter.sh/porter v1.0.0-rc.2
github.com/ghodss/yaml v1.0.0
github.com/gobuffalo/packr/v2 v2.8.1
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
github.com/xeipuuv/gojsonschema v1.2.0
go.opentelemetry.io/otel v1.10.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/PaesslerAG/gval v1.0.0 // indirect
github.com/PaesslerAG/gval v1.2.0 // indirect
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
github.com/PuerkitoBio/goquery v1.5.0 // indirect
github.com/andybalholm/brotli v1.0.0 // indirect
github.com/andybalholm/cascadia v1.0.0 // indirect
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/carolynvs/aferox v0.3.0 // indirect
github.com/carolynvs/magex v0.6.0 // indirect
github.com/cbroglie/mustache v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cnabio/cnab-go v0.23.0 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20210303052042-6bc126869bf4 // indirect
github.com/carolynvs/magex v0.9.0 // indirect
github.com/cbroglie/mustache v1.4.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cnabio/cnab-go v0.24.1 // indirect
github.com/cnabio/cnab-to-oci v0.3.7 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.12.0 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20220623050100-57a0ce2678a7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/docker/cli v20.10.18+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.18+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobuffalo/logger v1.0.4 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/goccy/go-yaml v1.8.1 // indirect
github.com/goccy/go-yaml v1.9.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4-0.20210608040537-544b4180ac70 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-containerregistry v0.11.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.3.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jeremywohl/flatten v1.0.1 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/klauspost/pgzip v1.2.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magefile/mage v1.11.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/klauspost/compress v1.15.10 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/magefile/mage v1.14.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/markbates/errx v1.1.0 // indirect
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/mholt/archiver/v3 v3.5.0 // indirect
github.com/mikefarah/yq/v3 v3.0.0-20201020025845-ccb718cd0f59 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/mmcdole/gofeed v1.0.0-beta2 // indirect
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mholt/archiver/v3 v3.5.1 // indirect
github.com/mikefarah/yq/v3 v3.0.0-20201202084205-8846255d1c37 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcdole/gofeed v1.1.3 // indirect
github.com/mmcdole/goxpp v0.0.0-20200921145534-2f3784f67354 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/tablewriter v0.0.4 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
github.com/osteele/liquid v1.3.0 // indirect
github.com/osteele/tuesday v1.0.3 // indirect
github.com/pelletier/go-toml v1.9.1 // indirect
github.com/pierrec/lz4/v4 v4.0.3 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pierrec/lz4/v4 v4.1.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/qri-io/jsonpointer v0.1.1 // indirect
github.com/qri-io/jsonschema v0.2.2-0.20210723092138-2eb22ee8115f // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/smartystreets/assertions v1.0.0 // indirect
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/qri-io/jsonschema v0.2.2-0.20210831022256-780655b2ba0e // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
go.opentelemetry.io/otel v1.1.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.1.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.1.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.1.0 // indirect
go.opentelemetry.io/otel/sdk v1.1.0 // indirect
go.opentelemetry.io/otel/trace v1.1.0 // indirect
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
go.uber.org/atomic v1.5.0 // indirect
go.uber.org/multierr v1.3.0 // indirect
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee // indirect
go.uber.org/zap v1.13.0 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/ini.v1 v1.56.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.10.0 // indirect
go.opentelemetry.io/otel/sdk v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/net v0.0.0-20220919232410-f2f64ebce3c1 // indirect
golang.org/x/sync v0.0.0-20220907140024-f12130a52804 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20220919141832-68c03719ef51 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
honnef.co/go/tools v0.0.1-2020.1.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit c12d7c8

Please sign in to comment.