Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to de-zarfed Maru #636

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ toolchain go1.22.3
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/defenseunicorns/maru-runner v0.1.1
github.com/defenseunicorns/maru-runner v0.2.0
github.com/defenseunicorns/pkg/exec v0.0.1
github.com/defenseunicorns/pkg/helpers v1.1.2
github.com/defenseunicorns/pkg/oci v0.0.2
github.com/defenseunicorns/zarf v0.33.0
Expand Down Expand Up @@ -169,6 +170,7 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/daviddengcn/go-colortext v1.0.0 // indirect
github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 // indirect
github.com/deitch/magic v0.0.0-20230404182410-1ff89d7342da // indirect
github.com/derailed/k9s v0.31.7 // indirect
github.com/derailed/popeye v0.11.2 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,14 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
github.com/defenseunicorns/maru-runner v0.1.1 h1:1q77tBdyhfCLWRbkXZm36ZpFlK9Jxf2/KYTxVRrRAQ4=
github.com/defenseunicorns/maru-runner v0.1.1/go.mod h1:B0mrTjz/ylNuyZ4tTl1sTHS/hNfFS01kh6QsO09pFqk=
github.com/defenseunicorns/maru-runner v0.2.0 h1:y49cPZSydBVlTwcH+JaSuBtW0BxL19sBsioyea31j9M=
github.com/defenseunicorns/maru-runner v0.2.0/go.mod h1:MOVxUUSTNINepwiqkq8jrqVSASK47Pk2+ziZKPR8Uxw=
github.com/defenseunicorns/pkg/exec v0.0.1 h1:mZtkZvwvOgInZOi+hvEjT0JAtjOgbeIo4RkpqMzU85g=
github.com/defenseunicorns/pkg/exec v0.0.1/go.mod h1:F/OPhrZuoXM6e2RgeDUlaSYFFW8I3rsErJnytLSkLFo=
github.com/defenseunicorns/pkg/helpers v1.1.2 h1:2t8ntF2Lijc8GqigAe6ZpYfC2BZd5Kk6rAUqrKNASt4=
github.com/defenseunicorns/pkg/helpers v1.1.2/go.mod h1:F4S5VZLDrlNWQKklzv4v9tFWjjZNhxJ1gT79j4XiLwk=
github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 h1:j08rz9vhyD9Bs+yKiyQMY2tSSejXRMxTqEObZ5M1Wbk=
github.com/defenseunicorns/pkg/helpers/v2 v2.0.1/go.mod h1:u1PAqOICZyiGIVA2v28g55bQH1GiAt0Bc4U9/rnWQvQ=
github.com/defenseunicorns/pkg/oci v0.0.2 h1:Lewwtl/D1Z55npRCkK1DS4Sd7pdrwyUs4+1RGpYajSQ=
github.com/defenseunicorns/pkg/oci v0.0.2/go.mod h1:fMevWu1lBUmk7Q0dHWjR5RVHE2jTV7X0mlroxdkIqDE=
github.com/defenseunicorns/zarf v0.33.0 h1:6Lrb8ZExt3afATyoGDENSw3pD/0BauH5VfVhxNHfWKY=
Expand Down Expand Up @@ -813,8 +817,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U=
github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/go-restruct/restruct v1.2.0-alpha h1:2Lp474S/9660+SJjpVxoKuWX09JsXHSrdV7Nv3/gkvc=
Expand Down Expand Up @@ -1496,8 +1500,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c h1:fPpdjePK1atuOg28PXfNSqgwf9I/qD1Hlo39JFwKBXk=
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
Expand Down
38 changes: 29 additions & 9 deletions src/cmd/vendored.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package cmd

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

runnerCLI "github.com/defenseunicorns/maru-runner/src/cmd"
runnerConfig "github.com/defenseunicorns/maru-runner/src/config"
"github.com/defenseunicorns/pkg/exec"

"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/config/lang"
Expand All @@ -21,18 +23,36 @@ var runnerCmd = &cobra.Command{
Use: "run",
Aliases: []string{"r"},
Short: lang.CmdRunShort,
Run: func(_ *cobra.Command, _ []string) {
os.Args = os.Args[1:] // grab 'run' and onward from the CLI args
runnerConfig.CmdPrefix = "uds" // use vendored Zarf inside the runner
runnerConfig.EnvPrefix = "uds"
// The maru runner init gets called before the uds-cli init, which looks for RUN_ARCHITECTURE because the EnvPrefix
// that we set above is not called yet. So in order to set the architecture if passing in UDS_ARCHITECTURE we must set it here.
archValue := os.Getenv("UDS_ARCHITECTURE")
if archValue != "" {
runnerConfig.CLIArch = archValue
RunE: func(_ *cobra.Command, _ []string) error {
os.Args = os.Args[1:] // grab 'run' and onward from the CLI args

runnerConfig.CmdPrefix = "uds"
runnerConfig.VendorPrefix = "UDS"

// Maru by default uses the MARU_ env var prefix - to add any UDS_ env vars we have to add them here
archValue := config.GetArch(v.GetString(V_ARCHITECTURE))
runnerConfig.AddExtraEnv("UDS", "true")
runnerConfig.AddExtraEnv("UDS_ARCH", archValue)

executablePath, err := exec.GetFinalExecutablePath()
if err != nil {
return err
}

if err = exec.RegisterCmdMutation("uds", executablePath); err != nil {
return err
}
if err = exec.RegisterCmdMutation("zarf", fmt.Sprintf("%s zarf", executablePath)); err != nil {
return err
}
if err = exec.RegisterCmdMutation("kubectl", fmt.Sprintf("%s zarf tools kubectl", executablePath)); err != nil {
return err
}

runnerCLI.RootCmd().SetArgs(os.Args)
runnerCLI.Execute()

return nil
},
DisableFlagParsing: true,
ValidArgsFunction: func(cmd *cobra.Command, tasks []string, task string) ([]string, cobra.ShellCompDirective) {
Expand Down
137 changes: 4 additions & 133 deletions src/test/e2e/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,135 +15,6 @@ import (
func TestTaskRunner(t *testing.T) {
t.Log("E2E: Task Runner")

t.Run("run copy", func(t *testing.T) {
t.Parallel()

baseFilePath := "base"
copiedFilePath := "copy"

e2e.CleanFiles(baseFilePath, copiedFilePath)
t.Cleanup(func() {
e2e.CleanFiles(baseFilePath, copiedFilePath)
})

err := os.WriteFile(baseFilePath, []byte{}, 0600)
require.NoError(t, err)

stdOut, stdErr, err := e2e.UDS("run", "copy", "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)

require.FileExists(t, copiedFilePath)
})

t.Run("run copy-exec", func(t *testing.T) {
t.Parallel()

baseFilePath := "exectest"
copiedFilePath := "exec"

e2e.CleanFiles(baseFilePath, copiedFilePath)
t.Cleanup(func() {
e2e.CleanFiles(baseFilePath, copiedFilePath)
})

err := os.WriteFile(baseFilePath, []byte{}, 0600)
require.NoError(t, err)

stdOut, stdErr, err := e2e.UDS("run", "copy-exec", "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)

require.FileExists(t, copiedFilePath)
execFileInfo, err := os.Stat(copiedFilePath)
require.NoError(t, err)
require.True(t, execFileInfo.Mode()&0111 != 0)
})

t.Run("run copy-verify", func(t *testing.T) {
t.Parallel()

baseFilePath := "data"
copiedFilePath := "verify"

e2e.CleanFiles(baseFilePath, copiedFilePath)
t.Cleanup(func() {
e2e.CleanFiles(baseFilePath, copiedFilePath)
})

err := os.WriteFile(baseFilePath, []byte("test"), 0600)
require.NoError(t, err)

stdOut, stdErr, err := e2e.UDS("run", "copy-verify", "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)

require.FileExists(t, copiedFilePath)
})

t.Run("run copy-symlink", func(t *testing.T) {
t.Parallel()

baseFilePath := "symtest"
copiedFilePath := "symcopy"
symlinkName := "testlink"

e2e.CleanFiles(baseFilePath, copiedFilePath, symlinkName)
t.Cleanup(func() {
e2e.CleanFiles(baseFilePath, copiedFilePath, symlinkName)
})

err := os.WriteFile(baseFilePath, []byte{}, 0600)
require.NoError(t, err)

stdOut, stdErr, err := e2e.UDS("run", "copy-symlink", "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)

require.FileExists(t, symlinkName)
})

t.Run("run local-import-with-curl", func(t *testing.T) {
t.Parallel()

downloadedFile := "checksums.txt"

e2e.CleanFiles(downloadedFile)
t.Cleanup(func() {
e2e.CleanFiles(downloadedFile)
})
// get current git revision
gitRev, err := e2e.GetGitRevision()
if err != nil {
return
}
setVar := fmt.Sprintf("GIT_REVISION=%s", gitRev)
stdOut, stdErr, err := e2e.UDS("run", "local-import-with-curl", "--set", setVar, "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)

require.FileExists(t, downloadedFile)
})

t.Run("run template-file", func(t *testing.T) {
t.Parallel()

baseFilePath := "raw"
copiedFilePath := "templated"

e2e.CleanFiles(baseFilePath, copiedFilePath)
t.Cleanup(func() {
e2e.CleanFiles(baseFilePath, copiedFilePath)
})

err := os.WriteFile(baseFilePath, []byte("${REPLACE_ME}"), 0600)
require.NoError(t, err)

stdOut, stdErr, err := e2e.UDS("run", "template-file", "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)

require.FileExists(t, copiedFilePath)

templatedContentsBytes, err := os.ReadFile(copiedFilePath)
require.NoError(t, err)
require.Equal(t, "replaced\n", string(templatedContentsBytes))
})

t.Run("run action", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -302,10 +173,10 @@ func TestTaskRunner(t *testing.T) {

stdOut, stdErr, err := e2e.UDS("run", "--list", setVar, "--file", "src/test/tasks/tasks.yaml")
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "copy")
require.Contains(t, stdErr, "This is a copy task")
require.Contains(t, stdErr, "copy-exec")
require.Contains(t, stdErr, "copy-verify")
require.Contains(t, stdErr, "echo-env-var")
require.Contains(t, stdErr, "Test that env vars take precedence")
require.Contains(t, stdErr, "remote-import")
require.Contains(t, stdErr, "action")
})

t.Run("test bad call to zarf tools wait-for", func(t *testing.T) {
Expand Down
16 changes: 0 additions & 16 deletions src/test/tasks/tasks-to-import.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions src/test/tasks/tasks.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
includes:
- local: ./tasks-to-import.yaml
- foo: ./more-tasks/foo.yaml
- infinite: ./loop-task.yaml
- remote: https://raw.githubusercontent.com/defenseunicorns/uds-cli/${GIT_REVISION}/src/test/tasks/remote-import-tasks.yaml
Expand All @@ -26,37 +25,9 @@ tasks:
description: Test that env vars take precedence over var defaults
actions:
- cmd: echo "${TO_BE_OVERWRITTEN}"
- name: copy
description: "This is a copy task"
files:
- source: base
target: copy
- name: copy-exec
files:
- source: exectest
target: exec
executable: true
- name: copy-verify
files:
- source: data
target: verify
shasum: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
- name: copy-symlink
files:
- source: symtest
target: symcopy
symlinks:
- "testlink"
- name: remote-import
actions:
- task: remote:echo-var
- name: local-import-with-curl
actions:
- task: local:fetch-checksums
- name: template-file
files:
- source: raw
target: templated
- name: action
actions:
- cmd: echo "specific test string"
Expand Down
Loading