Skip to content

Commit aeb9e6f

Browse files
authored
Merge pull request #49 from VinozzZ/update-porter-to-rc.2
update to porter v1.0.0-rc.2
2 parents b1991fa + 8c59348 commit aeb9e6f

16 files changed

+1035
-796
lines changed

Makefile

-90
This file was deleted.

azure-pipelines.yml

+8-14
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,24 @@ trigger:
1010
- refs/tags/v*
1111

1212
pool:
13-
vmImage: 'Ubuntu 16.04'
13+
vmImage: 'ubuntu-latest'
1414

1515
steps:
1616
- task: GoTool@0
1717
inputs:
18-
version: '1.13.10'
18+
version: '1.18.6'
1919
displayName: 'Install Go'
2020

21-
- script: |
22-
set -xeuo pipefail
23-
mkdir -p /home/vsts/go/bin/
24-
echo "##vso[task.prependpath]/home/vsts/go/bin/"
25-
displayName: 'Configure Go'
21+
- script: go run mage.go ConfigureAgent
22+
displayName: 'Configure Agent'
2623

27-
- script: |
28-
make build test
29-
displayName: 'Unit Test'
24+
- script: mage Test
25+
displayName: 'Test'
3026

31-
- script: |
32-
make xbuild-all
27+
- script: mage XBuildAll
3328
displayName: 'Cross Compile'
3429

35-
- script: |
36-
make publish
30+
- script: mage Publish
3731
env:
3832
GITHUB_TOKEN: $(GITHUB_TOKEN)
3933
displayName: 'Publish'

cmd/arm/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func buildBuildCommand(m *arm.Mixin) *cobra.Command {
1010
Use: "build",
1111
Short: "Generate Dockerfile lines for the bundle invocation image",
1212
RunE: func(cmd *cobra.Command, args []string) error {
13-
return m.Build()
13+
return m.Build(cmd.Context())
1414
},
1515
}
1616
return cmd

cmd/arm/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func buildInstallCommand(m *arm.Mixin) *cobra.Command {
1717
return m.LoadConfigFromEnvironment()
1818
},
1919
RunE: func(cmd *cobra.Command, args []string) error {
20-
return m.Install()
20+
return m.Install(cmd.Context())
2121
},
2222
}
2323
return cmd

cmd/arm/main.go

+41-16
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,75 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"os"
8+
"runtime/debug"
79

810
"get.porter.sh/mixin/arm/pkg/arm"
11+
"get.porter.sh/porter/pkg/cli"
912
"github.com/spf13/cobra"
13+
"go.opentelemetry.io/otel/attribute"
1014
)
1115

1216
func main() {
13-
cmd, err := buildRootCommand(os.Stdin)
14-
if err != nil {
15-
fmt.Printf("err: %s\n", err)
16-
os.Exit(1)
17-
}
18-
if err := cmd.Execute(); err != nil {
19-
fmt.Printf("err: %s\n", err)
20-
os.Exit(1)
17+
run := func() int {
18+
ctx := context.Background()
19+
m := arm.New()
20+
if err := m.ConfigureLogging(ctx); err != nil {
21+
fmt.Println(err)
22+
os.Exit(cli.ExitCodeErr)
23+
}
24+
cmd := buildRootCommand(m, os.Stdin)
25+
26+
// We don't have tracing working inside a bundle working currently.
27+
// We are using StartRootSpan anyway because it creates a TraceLogger and sets it
28+
// on the context, so we can grab it later
29+
ctx, log := m.StartRootSpan(ctx, "arm")
30+
defer func() {
31+
// Capture panics and trace them
32+
if panicErr := recover(); panicErr != nil {
33+
log.Error(fmt.Errorf("%s", panicErr),
34+
attribute.Bool("panic", true),
35+
attribute.String("stackTrace", string(debug.Stack())))
36+
log.EndSpan()
37+
m.Close()
38+
os.Exit(cli.ExitCodeErr)
39+
} else {
40+
log.Close()
41+
m.Close()
42+
}
43+
}()
44+
45+
if err := cmd.ExecuteContext(ctx); err != nil {
46+
return cli.ExitCodeErr
47+
}
48+
return cli.ExitCodeSuccess
2149
}
50+
os.Exit(run())
2251
}
2352

24-
func buildRootCommand(in io.Reader) (*cobra.Command, error) {
25-
m, err := arm.New()
26-
if err != nil {
27-
return nil, err
28-
}
29-
m.In = in
53+
func buildRootCommand(m *arm.Mixin, in io.Reader) *cobra.Command {
3054
cmd := &cobra.Command{
3155
Use: "arm",
3256
Long: "An ARM mixin for porter 👩🏽‍✈️",
3357
PersistentPreRun: func(cmd *cobra.Command, args []string) {
3458
// Enable swapping out stdout/stderr for testing
59+
m.In = in
3560
m.Out = cmd.OutOrStdout()
3661
m.Err = cmd.OutOrStderr()
3762
},
3863
SilenceUsage: true,
3964
}
4065

41-
cmd.PersistentFlags().BoolVar(&m.Debug, "debug", false, "Enable debug logging")
66+
cmd.PersistentFlags().BoolVar(&m.DebugMode, "debug", false, "Enable debug logging")
4267

4368
cmd.AddCommand(buildVersionCommand(m))
4469
cmd.AddCommand(buildSchemaCommand(m))
4570
cmd.AddCommand(buildBuildCommand(m))
4671
cmd.AddCommand(buildInstallCommand(m))
4772
cmd.AddCommand(buildUninstallCommand(m))
4873

49-
return cmd, nil
74+
return cmd
5075
}

cmd/arm/uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func buildUninstallCommand(m *arm.Mixin) *cobra.Command {
1010
Use: "uninstall",
1111
Short: "Execute the uninstall functionality of this mixin",
1212
RunE: func(cmd *cobra.Command, args []string) error {
13-
return m.Uninstall()
13+
return m.Uninstall(cmd.Context())
1414
},
1515
}
1616
return cmd

0 commit comments

Comments
 (0)