Skip to content

Commit

Permalink
Merge branch 'main' into mappedDependencyOutputs
Browse files Browse the repository at this point in the history
  • Loading branch information
schristoff committed Apr 29, 2024
2 parents ad3d58c + 7422f37 commit 75dc2c2
Show file tree
Hide file tree
Showing 27 changed files with 510 additions and 253 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_pipelinesrelease_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4.1.0
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: "${{ inputs.GOVERSION }}"
Expand Down
19 changes: 2 additions & 17 deletions .github/workflows/porter-canary.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
name: porter/porter-canary
on:
workflow_dispatch:
inputs:
shouldPublish:
description: Should Publish
default: true
type: boolean
required: false
skipTests:
description: Skip Tests
default: false
type: boolean
required: false
push:
branches:
- main
- release/*
pull_request:
branches:
- split-builds
jobs:
build_pipelinesrelease_template:
name: build_pipelinesrelease_template
uses: ./.github/workflows/build_pipelinesrelease_template.yml
with:
registry: ghcr.io/getporter
shouldPublish: "${{inputs.shouldPublish}}"
skipTests: "${{inputs.skipTests}}"
shouldPublish: true
skipTests: false
21 changes: 21 additions & 0 deletions .github/workflows/porter-integration-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,107 +12,128 @@ env:

jobs:
archive_integration_test:
name: Archive Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: archive_test
registry: ${{inputs.registry}}
build_integration_test:
name: Build Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: build_test
registry: ${{inputs.registry}}
cli_integration_test:
name: CLI Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: cli_test
registry: ${{inputs.registry}}
connection_nix_integration_test:
name: Connection Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: connection_nix_test
registry: ${{inputs.registry}}
copy_integration_test:
name: Copy Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: copy_test
registry: ${{inputs.registry}}
dependenciesv1_integration_test:
name: Dependencies V1 Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: dependenciesv1_test
registry: ${{inputs.registry}}
dependenciesv2_integration_test:
name: Dependencies V2 Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: dependenciesv2_test
registry: ${{inputs.registry}}
driver_integration_test:
name: Driver Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: driver_test
registry: ${{inputs.registry}}
install_integration_test:
name: Install Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: install_test
registry: ${{inputs.registry}}
invoke_integration_test:
name: Invoke Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: invoke_test
registry: ${{inputs.registry}}
lint_integration_test:
name: Lint Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: lint_test
registry: ${{inputs.registry}}
migration_integration_test:
name: Migration Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: migration_test
registry: ${{inputs.registry}}
outputs_integration_test:
name: Outputs Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: outputs_test
registry: ${{inputs.registry}}
publish_integration_test:
name: Publish Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: publish_test
registry: ${{inputs.registry}}
pull_integration_test:
name: Pull Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: pull_test
registry: ${{inputs.registry}}
registry_integration_test:
name: Registry Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: registry_integration_test
registry: ${{inputs.registry}}
schema_integration_test:
name: Schema Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: schema_test
registry: ${{inputs.registry}}
sensitive_data_integration_test:
name: Sensitive data Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: sensitive_data_test
registry: ${{inputs.registry}}
suppress_output_integration_test:
name: Suppress output Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: suppress_output_test
registry: ${{inputs.registry}}
telemetry_test:
name: Telemetry Integration Test
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
with:
test_name: telemetry_test
registry: ${{inputs.registry}}
# Reusable workflows only supports 20 jobs
uninstall_test_integ:
name: Uninstall Integration Test
runs-on: ubuntu-latest
steps:
- name: checkout
Expand Down
80 changes: 27 additions & 53 deletions pkg/cnab/provider/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"

"get.porter.sh/porter/pkg/cnab"
"get.porter.sh/porter/pkg/config"
Expand All @@ -24,14 +23,14 @@ type HostVolumeMountSpec struct {
ReadOnly bool
}

// Shared arguments for all CNAB actions
// ActionArguments are the shared arguments for all bundle runs.
type ActionArguments struct {
// Action to execute, e.g. install, upgrade.
Action string

// Name of the installation.
Installation storage.Installation

// Run defines how to execute the bundle.
Run storage.Run

// BundleReference is the set of information necessary to execute a bundle.
BundleReference cnab.BundleReference

Expand All @@ -40,6 +39,7 @@ type ActionArguments struct {
Files map[string]string

// Params is the fully resolved set of parameters.
// TODO(PEP003): This should be removed in https://github.com/getporter/porter/issues/2699
Params map[string]interface{}

// Driver is the CNAB-compliant driver used to run bundle actions.
Expand Down Expand Up @@ -145,56 +145,57 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
case <-ctx.Done():
return ctx.Err()
default:
currentRun := args.Run
ctx, log := tracing.StartSpan(ctx,
attribute.String("action", args.Action),
attribute.String("action", currentRun.Action),
attribute.Bool("allowDockerHostAccess", args.AllowDockerHostAccess),
attribute.String("driver", args.Driver))
defer log.EndSpan()
args.BundleReference.AddToTrace(ctx)
args.Installation.AddToTrace(ctx)

if args.Action == "" {
if currentRun.Action == "" {
return log.Error(errors.New("action is required"))
}

b, err := r.ProcessBundle(ctx, args.BundleReference.Definition)
if err != nil {
return log.Error(err)
}

currentRun, err := r.CreateRun(ctx, args, b)
if err != nil {
return log.Error(err)
return err
}

// Validate the action
if _, err := b.GetAction(currentRun.Action); err != nil {
return log.Error(fmt.Errorf("invalid action '%s' specified for bundle %s: %w", currentRun.Action, b.Name, err))
}

creds, err := r.loadCredentials(ctx, b, args)
if err != nil {
return log.Error(fmt.Errorf("not load credentials: %w", err))
return log.Errorf("invalid action '%s' specified for bundle %s: %w", currentRun.Action, b.Name, err)
}

log.Debugf("Using runtime driver %s\n", args.Driver)
driver, err := r.newDriver(args.Driver, args)
if err != nil {
return log.Error(fmt.Errorf("unable to instantiate driver: %w", err))
return log.Errorf("unable to instantiate driver: %w", err)
}

a := cnabaction.New(driver)
a.SaveLogs = args.PersistLogs

// Resolve parameters and credentials just-in-time (JIT) before running the bundle, do this at the *LAST* possible moment
log.Info("Just-in-time resolving credentials...")
if err = r.loadCredentials(ctx, b, &currentRun); err != nil {
return log.Errorf("could not resolve credentials before running the bundle: %w", err)
}
log.Info("Just-in-time resolving parameters...")
if err = r.loadParameters(ctx, b, &currentRun); err != nil {
return log.Errorf("could not resolve parameters before running the bundle: %w", err)
}

if currentRun.ShouldRecord() {
err = r.SaveRun(ctx, args.Installation, currentRun, cnab.StatusRunning)
if err != nil {
return log.Error(fmt.Errorf("could not save the pending action's status, the bundle was not executed: %w", err))
return log.Errorf("could not save the pending action's status, the bundle was not executed: %w", err)
}
}

cnabClaim := currentRun.ToCNAB()
cnabCreds := creds.ToCNAB()
cnabCreds := currentRun.Credentials.ToCNAB()
// The claim and credentials contain sensitive values. Only trace it in special dev builds (nothing is traced for release builds)
log.SetSensitiveAttributes(
tracing.ObjectAttribute("cnab-claim", cnabClaim),
Expand All @@ -204,46 +205,19 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
if currentRun.ShouldRecord() {
if err != nil {
err = r.appendFailedResult(ctx, err, currentRun)
return log.Error(fmt.Errorf("failed to record that %s for installation %s failed: %w", args.Action, args.Installation.Name, err))
return log.Errorf("failed to record that %s for installation %s failed: %w", currentRun.Action, args.Installation.Name, err)
}
return r.SaveOperationResult(ctx, opResult, args.Installation, currentRun, currentRun.NewResultFrom(result))
}

if err != nil {
return log.Error(fmt.Errorf("execution of %s for installation %s failed: %w", args.Action, args.Installation.Name, err))
return log.Errorf("execution of %s for installation %s failed: %w", currentRun.Action, args.Installation.Name, err)
}

return nil
}
}

func (r *Runtime) CreateRun(ctx context.Context, args ActionArguments, b cnab.ExtendedBundle) (storage.Run, error) {
ctx, span := tracing.StartSpan(ctx)
defer span.EndSpan()

// Create a record for the run we are about to execute
var currentRun = args.Installation.NewRun(args.Action, b)
currentRun.Bundle = b.Bundle
currentRun.BundleReference = args.BundleReference.Reference.String()
currentRun.BundleDigest = args.BundleReference.Digest.String()

var err error
extb := cnab.NewBundle(b.Bundle)
currentRun.Parameters.Parameters, err = r.sanitizer.CleanRawParameters(ctx, args.Params, extb, currentRun.ID)
if err != nil {
return storage.Run{}, span.Error(err)
}

// TODO: Do not save secrets when the run isn't recorded
currentRun.ParameterOverrides = storage.LinkSensitiveParametersToSecrets(currentRun.ParameterOverrides, extb, currentRun.ID)
currentRun.CredentialSets = args.Installation.CredentialSets
sort.Strings(currentRun.CredentialSets)

currentRun.ParameterSets = args.Installation.ParameterSets
sort.Strings(currentRun.ParameterSets)
return currentRun, nil
}

// SaveRun with the specified status.
func (r *Runtime) SaveRun(ctx context.Context, installation storage.Installation, run storage.Run, status string) error {
ctx, span := tracing.StartSpan(ctx)
Expand All @@ -259,12 +233,12 @@ func (r *Runtime) SaveRun(ctx context.Context, installation storage.Installation
return span.Error(fmt.Errorf("error saving the installation record before executing the bundle: %w", err))
}

result := run.NewResult(status)
err = r.installations.InsertRun(ctx, run)
err = r.installations.UpsertRun(ctx, run)
if err != nil {
return span.Error(fmt.Errorf("error saving the installation run record before executing the bundle: %w", err))
}

result := run.NewResult(status)
err = r.installations.InsertResult(ctx, result)
if err != nil {
return span.Error(fmt.Errorf("error saving the installation status record before executing the bundle: %w", err))
Expand Down
Loading

0 comments on commit 75dc2c2

Please sign in to comment.