Skip to content

Commit

Permalink
Merge pull request #36 from VinozzZ/main
Browse files Browse the repository at this point in the history
update to porter v1.0.0-rc.2
  • Loading branch information
VinozzZ committed Sep 21, 2022
2 parents ade55d2 + 3cf400d commit 47f195f
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 49 deletions.
61 changes: 43 additions & 18 deletions cmd/aws/main.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,69 @@
package main

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

"get.porter.sh/mixin/aws/pkg/aws"
"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 := aws.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, "aws")
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, err := aws.New()
if err != nil {
return nil, err
}
m.Config.In = in
func buildRootCommand(m *aws.Mixin, in io.Reader) *cobra.Command {
cmd := &cobra.Command{
Use: "aws",
Long: "A skeleton mixin to use for building other mixins for porter 👩🏽‍✈️",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Enable swapping out stdout/stderr for testing
m.Config.Out = cmd.OutOrStdout()
m.Config.Err = cmd.OutOrStderr()
m.In = in
m.Out = cmd.OutOrStdout()
m.Err = cmd.OutOrStderr()
},
SilenceUsage: true,
}

cmd.PersistentFlags().BoolVar(&m.Config.DebugMode, "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 @@ -48,5 +73,5 @@ func buildRootCommand(in io.Reader) (*cobra.Command, error) {
cmd.AddCommand(buildUpgradeCommand(m))
cmd.AddCommand(buildUninstallCommand(m))

return cmd, nil
return cmd
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ replace github.com/spf13/viper => github.com/getporter/viper v1.7.1-porter.2.0.2

require (
get.porter.sh/magefiles v0.3.2
get.porter.sh/porter v1.0.0-rc.1
get.porter.sh/porter v1.0.0-rc.2
github.com/ghodss/yaml v1.0.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.9.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -112,7 +113,6 @@ require (
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.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.9.0 // indirect
Expand All @@ -124,12 +124,12 @@ require (
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-20220907135653-1e95f45603a7 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/sync v0.0.0-20220907140024-f12130a52804 // indirect
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // 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-20220908141613-51c1cc9bc6d0 // indirect
google.golang.org/genproto v0.0.0-20220915135415-7fd63a7952de // 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
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ contrib.go.opencensus.io/exporter/stackdriver v0.13.4/go.mod h1:aXENhDJ1Y4lIg4EU
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
get.porter.sh/magefiles v0.3.2 h1:RDJini5LBQ8pYnc0r8M6cX2Pk+CPsCtyFwO3fy8Jb5g=
get.porter.sh/magefiles v0.3.2/go.mod h1:w8ikniAFHO7AVvWayyWF7ViHoh4tNKwTxtKpO1FyGkU=
get.porter.sh/porter v1.0.0-rc.1 h1:8sYXXW2dwp5V5Llk19f4o/KAkj7xwZo1HNRl49m0r4w=
get.porter.sh/porter v1.0.0-rc.1/go.mod h1:ZDh+OB2lJJL5aA7zBLhWRE9m9DhRxH0iVW88OoifL0c=
get.porter.sh/porter v1.0.0-rc.2 h1:xclJNxXqlGaozFnSb82JM+B5I7cnJHY3q/W7w+FDONE=
get.porter.sh/porter v1.0.0-rc.2/go.mod h1:EGPOxhMu44dRnwKdcedUtbMaFBrFrYzG1ybnHVYTrDs=
github.com/Antonboom/errname v0.1.5/go.mod h1:DugbBstvPFQbv/5uLcRRzfrNqKE9tVdVCqWCLp6Cifo=
github.com/Antonboom/nilnil v0.1.0/go.mod h1:PhHLvRPSghY5Y7mX4TW+BHZQYo1A8flE5H20D3IPZBo=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
Expand Down Expand Up @@ -1060,8 +1060,8 @@ golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 h1:1WGATo9HAhkWMbfyuVU0tEFP88OIkUvwaHFveQPvzCQ=
golang.org/x/net v0.0.0-20220907135653-1e95f45603a7/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1373,8 +1373,8 @@ google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220908141613-51c1cc9bc6d0 h1:bMz0aY2wd9TwUp9M7QfjBWuQqaFD/ZaTtvDpPDCo2Ow=
google.golang.org/genproto v0.0.0-20220908141613-51c1cc9bc6d0/go.mod h1:rQWNQYp1kbHR3+n5cARSTCF5rlJOttUn8yIhRklGAWQ=
google.golang.org/genproto v0.0.0-20220915135415-7fd63a7952de h1:5ANeKFmGdtiputJJYeUVg8nTGA/1bEirx4CgzcnPSx8=
google.golang.org/genproto v0.0.0-20220915135415-7fd63a7952de/go.mod h1:0Nb8Qy+Sk5eDzHnzlStwW3itdNaWoZA5XeSG+R3JHSo=
google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down
8 changes: 4 additions & 4 deletions pkg/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (

type Mixin struct {
// Config is a specialized context with additional runtime settings.
Config runtime.RuntimeConfig
runtime.RuntimeConfig
}

// New aws mixin client, initialized with useful defaults.
func New() (*Mixin, error) {
func New() *Mixin {
m := &Mixin{
Config: runtime.NewConfig(),
RuntimeConfig: runtime.NewConfig(),
}
m.SetUserAgent()

return m, nil
return m
}
10 changes: 5 additions & 5 deletions pkg/aws/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import "fmt"
// for an invocation image using this mixin
func (m *Mixin) Build() error {
// TODO: This gets whatever the latest version of the cli is, there isn't a way for us to say what version we are using
fmt.Fprintln(m.Config.Out, `RUN apt-get update && apt-get install -y --no-install-recommends curl unzip libc6 less groff`)
fmt.Fprintln(m.Config.Out, `RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip"`)
fmt.Fprintln(m.Config.Out, `RUN unzip awscliv2.zip`)
fmt.Fprintln(m.Config.Out, `RUN ./aws/install`)
fmt.Fprintln(m.Config.Out, `RUN rm -fr awscliv2.zip ./aws`)
fmt.Fprintln(m.Out, `RUN apt-get update && apt-get install -y --no-install-recommends curl unzip libc6 less groff`)
fmt.Fprintln(m.Out, `RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip"`)
fmt.Fprintln(m.Out, `RUN unzip awscliv2.zip`)
fmt.Fprintln(m.Out, `RUN ./aws/install`)
fmt.Fprintln(m.Out, `RUN rm -fr awscliv2.zip ./aws`)
return nil
}
4 changes: 2 additions & 2 deletions pkg/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const AWS_EXECUTION_ENV = "AWS_EXECUTION_ENV"
func (m *Mixin) SetUserAgent() {
value := []string{pkg.UserAgent(), m.UserAgent()}

if agentStr, ok := m.Config.LookupEnv(AWS_EXECUTION_ENV); ok {
if agentStr, ok := m.LookupEnv(AWS_EXECUTION_ENV); ok {
value = append(value, agentStr)
}

m.Config.Setenv(AWS_EXECUTION_ENV, strings.Join(value, " "))
m.Setenv(AWS_EXECUTION_ENV, strings.Join(value, " "))
}

func (m *Mixin) UserAgent() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/aws/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func TestSetUserAgent(t *testing.T) {
m.SetUserAgent()

expected := "getporter/aws/" + pkg.Version
require.Contains(t, m.Config.Getenv(AWS_EXECUTION_ENV), expected)
require.Contains(t, m.Getenv(AWS_EXECUTION_ENV), expected)
}
4 changes: 2 additions & 2 deletions pkg/aws/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func (m *Mixin) loadAction(ctx context.Context) (*Action, error) {
var action Action
err := builder.LoadAction(ctx, m.Config, "", func(contents []byte) (interface{}, error) {
err := builder.LoadAction(ctx, m.RuntimeConfig, "", func(contents []byte) (interface{}, error) {
err := yaml.Unmarshal(contents, &action)
return &action, err
})
Expand All @@ -22,6 +22,6 @@ func (m *Mixin) Execute(ctx context.Context) error {
return err
}

_, err = builder.ExecuteSingleStepAction(ctx, m.Config, action)
_, err = builder.ExecuteSingleStepAction(ctx, m.RuntimeConfig, action)
return err
}
8 changes: 4 additions & 4 deletions pkg/aws/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ func TestMixin_Execute(t *testing.T) {
ctx := context.Background()
m := NewTestMixin(t)

m.Config.Setenv(test.ExpectedCommandEnv, tc.wantCommand)
m.Setenv(test.ExpectedCommandEnv, tc.wantCommand)
mixinInputB, err := ioutil.ReadFile(tc.file)
require.NoError(t, err)

m.Config.In = bytes.NewBuffer(mixinInputB)
m.In = bytes.NewBuffer(mixinInputB)

err = m.Execute(ctx)
require.NoError(t, err, "execute failed")

if tc.wantOutput == "" {
outputs, _ := m.Config.FileSystem.ReadDir("/cnab/app/porter/outputs")
outputs, _ := m.FileSystem.ReadDir("/cnab/app/porter/outputs")
assert.Empty(t, outputs, "expected no outputs to be created")
} else {
wantPath := path.Join("/cnab/app/porter/outputs", tc.wantOutput)
exists, _ := m.Config.FileSystem.Exists(wantPath)
exists, _ := m.FileSystem.Exists(wantPath)
assert.True(t, exists, "output file was not created %s", wantPath)
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/aws/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewTestMixin(t *testing.T) *TestMixin {
c := portercontext.NewTestContext(t)
m := &TestMixin{
Mixin: &Mixin{
Config: runtime.NewConfigFor(c.Context),
RuntimeConfig: runtime.NewConfigFor(c.Context),
},
TestContext: c,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/aws/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (
var schema string

func (m *Mixin) PrintSchema() {
fmt.Fprintf(m.Config.Out, schema)
fmt.Fprintf(m.Out, schema)
}
2 changes: 1 addition & 1 deletion pkg/aws/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (m *Mixin) PrintVersion(opts version.Options) error {
return version.PrintVersion(m.Config.Context, opts, m.Version())
return version.PrintVersion(m.Context, opts, m.Version())
}

func (m *Mixin) Version() mixin.Metadata {
Expand Down

0 comments on commit 47f195f

Please sign in to comment.