From 4f28e12b100d1551a624ae51c312cde078adbf4e Mon Sep 17 00:00:00 2001 From: Matt Titmus Date: Fri, 19 Nov 2021 13:45:13 -0500 Subject: [PATCH] Simplify bundle docker value as image string (#168) * Simplify bundle docker value as image string * Extra line --- README.md | 4 +- bundles/bundle_test.go | 3 +- bundles/default.yml | 5 +- data/bundle.go | 137 ++++++++++++++----- data/bundle_test.go | 139 ++++++++++++++++++++ dataaccess/memory/bundle-access.go | 2 + dataaccess/postgres/bundle-access.go | 22 +++- dataaccess/postgres/postgres-data-access.go | 4 +- dataaccess/tests/bundle-access.go | 28 +++- dataaccess/tests/token-access.go | 2 +- testing/config/complete.yml | 34 ----- testing/config/no-database-password.yml | 34 ----- testing/config/no-database.yml | 34 ----- testing/test-bundle-entrypoint.yml | 4 +- testing/test-bundle-foo.yml | 4 +- testing/test-bundle.yml | 5 +- testing/test-default.yml | 4 +- worker/docker/worker.go | 8 +- worker/kubernetes/worker.go | 8 +- 19 files changed, 304 insertions(+), 177 deletions(-) create mode 100644 data/bundle_test.go diff --git a/README.md b/README.md index b43f242..e0dcd04 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,7 @@ long_description: |- permissions: - can_echo -docker: - image: ubuntu - tag: 20.04 +image: ubuntu:20.04 commands: foo: diff --git a/bundles/bundle_test.go b/bundles/bundle_test.go index f78ad24..9e792ac 100644 --- a/bundles/bundle_test.go +++ b/bundles/bundle_test.go @@ -35,8 +35,7 @@ func TestLoadBundleFromFile(t *testing.T) { assert.Equal(t, "A test bundle.", b.Description) assert.Equal(t, "This is test bundle.\nThere are many like it, but this one is mine.", b.LongDescription) assert.Len(t, b.Permissions, 1) - assert.Equal(t, "ubuntu", b.Docker.Image) - assert.Equal(t, "20.04", b.Docker.Tag) + assert.Equal(t, "ubuntu:20.04", b.Image) assert.Len(t, b.Commands, 4) // Bundle templates diff --git a/bundles/default.yml b/bundles/default.yml index ca0f802..4ddc991 100644 --- a/bundles/default.yml +++ b/bundles/default.yml @@ -3,6 +3,7 @@ gort_bundle_version: 1 name: gort version: 0.0.1 + author: Matt Titmus homepage: https://guide.getgort.io description: The default command bundle. @@ -17,9 +18,7 @@ permissions: - manage_roles - manage_users -docker: - image: getgort/gort - tag: {{.Version}} +image: getgort/gort:{{.Version}} commands: bundle: diff --git a/data/bundle.go b/data/bundle.go index 7da2f84..02dd357 100644 --- a/data/bundle.go +++ b/data/bundle.go @@ -34,41 +34,61 @@ type BundleInfo struct { // Bundle represents a bundle as defined in the "bundles" section of the // config. type Bundle struct { - GortBundleVersion int `yaml:"gort_bundle_version,omitempty" json:"gort_bundle_version,omitempty"` - Name string `yaml:",omitempty" json:"name,omitempty"` - Version string `yaml:",omitempty" json:"version,omitempty"` - Enabled bool `yaml:",omitempty" json:"enabled"` - Author string `yaml:",omitempty" json:"author,omitempty"` - Homepage string `yaml:",omitempty" json:"homepage,omitempty"` - Description string `yaml:",omitempty" json:"description,omitempty"` - InstalledOn time.Time `yaml:"-" json:"installed_on,omitempty"` - InstalledBy string `yaml:",omitempty" json:"installed_by,omitempty"` - LongDescription string `yaml:"long_description,omitempty" json:"long_description,omitempty"` - Docker BundleDocker `yaml:",omitempty" json:"docker,omitempty"` - Kubernetes BundleKubernetes `yaml:",omitempty" json:"kubernetes,omitempty"` - Permissions []string `yaml:",omitempty" json:"permissions,omitempty"` - Commands map[string]*BundleCommand `yaml:",omitempty" json:"commands,omitempty"` - Default bool `yaml:"-" json:"default,omitempty"` - Templates Templates `yaml:",omitempty" json:"templates,omitempty"` + GortBundleVersion int `yaml:"gort_bundle_version,omitempty" json:",omitempty"` + Name string `yaml:",omitempty" json:",omitempty"` + Version string `yaml:",omitempty" json:",omitempty"` + Enabled bool `yaml:",omitempty" json:",omitempty"` + Author string `yaml:",omitempty" json:",omitempty"` + Homepage string `yaml:",omitempty" json:",omitempty"` + Description string `yaml:",omitempty" json:",omitempty"` + Image string `yaml:",omitempty" json:",omitempty"` + InstalledOn time.Time `yaml:"-" json:",omitempty"` + InstalledBy string `yaml:",omitempty" json:",omitempty"` + LongDescription string `yaml:"long_description,omitempty" json:",omitempty"` + Kubernetes BundleKubernetes `yaml:",omitempty" json:",omitempty"` + Permissions []string `yaml:",omitempty" json:",omitempty"` + Commands map[string]*BundleCommand `yaml:",omitempty" json:",omitempty"` + Default bool `yaml:"-" json:",omitempty"` + Templates Templates `yaml:",omitempty" json:",omitempty"` } -// BundleKubernetes represents the "bundles/kubernetes" subsection of the config doc -type BundleKubernetes struct { - ServiceAccountName string `yaml:"serviceAccountName,omitempty" json:"serviceAccountName,omitempty"` -} +// ImageFull returns the full image name, consisting of a repository and tag. +func (b Bundle) ImageFull() string { + if repo, tag := b.ImageFullParts(); repo != "" { + return repo + ":" + tag + } -func (b Bundle) Semver() semver.Version { - var version = b.Version + return "" +} - if version == "" { - return semver.Version{} +// ImageFullParts returns the image repository and tag. If the tag isn't +// specified in b.Image, the returned tag will be "latest". +func (b Bundle) ImageFullParts() (repository, tag string) { + if b.Image == "" { + return } - if strings.ToLower(version)[0] == 'v' { - version = version[1:] + ss := strings.SplitN(b.Image, ":", 2) + + repository = ss[0] + + if len(ss) > 1 { + tag = ss[1] + } else { + tag = "latest" } - if v, err := semver.NewVersion(version); err != nil { + return +} + +// Semver returns b.Version as a semver.Version value, which makes it easier +// to compare and sort version numbers. If b.Version == "", a zero-value +// Version{} is returned. If b.Version isn't valid per Semantic Versioning +// 2.0.0 (https://semver.org), it will attempt to coerce it into a correct +// semantic version (since users be crazy). If it fails, a zero-value +// Version{} is returned. +func (b Bundle) Semver() semver.Version { + if v, err := semver.NewVersion(CoerceVersionToSemver(b.Version)); err != nil { return semver.Version{} } else { return *v @@ -86,8 +106,63 @@ type BundleCommand struct { Templates Templates `yaml:",omitempty" json:"templates,omitempty"` } -// BundleDocker represents the "bundles/docker" subsection of the config doc -type BundleDocker struct { - Image string `yaml:",omitempty" json:"image,omitempty"` - Tag string `yaml:",omitempty" json:"tag,omitempty"` +// BundleKubernetes represents the "bundles/kubernetes" subsection of the config doc +type BundleKubernetes struct { + ServiceAccountName string `yaml:"serviceAccountName,omitempty" json:"serviceAccountName,omitempty"` +} + +// CoerceVersionToSemver takes a version number and attempts to coerce it +// into a semver-compliant dotted-tri format. It also understands semver +// pre-release and metadata decorations. +func CoerceVersionToSemver(version string) string { + version = strings.TrimSpace(version) + + if version == "" { + return "0.0.0" + } + + if strings.ToLower(version)[0] == 'v' { + version = version[1:] + } + + v := version + + var metadata, preRelease string + var ss []string + var dotParts = make([]string, 3) + + ss = strings.SplitN(v, "+", 2) + if len(ss) > 1 { + v = ss[0] + metadata = ss[1] + } + + ss = strings.SplitN(v, "-", 2) + if len(ss) > 1 { + v = ss[0] + preRelease = ss[1] + } + + // If it turns out to be in dotted-tri format, return the original + ss = strings.SplitN(v, ".", 4) + for i := 0; i < len(ss) && i < 3; i++ { + dotParts[i] = ss[i] + } + for i := 0; i < len(dotParts); i++ { + if dotParts[i] == "" { + dotParts[i] = "0" + } + } + + v = strings.Join(dotParts, ".") + + if preRelease != "" { + v += "-" + preRelease + } + + if metadata != "" { + v += "+" + metadata + } + + return v } diff --git a/data/bundle_test.go b/data/bundle_test.go new file mode 100644 index 0000000..4082607 --- /dev/null +++ b/data/bundle_test.go @@ -0,0 +1,139 @@ +/* + * Copyright 2021 The Gort Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package data + +import ( + "testing" + + "github.com/coreos/go-semver/semver" + "github.com/stretchr/testify/assert" +) + +func TestBundleImageFullParts(t *testing.T) { + tests := []struct { + Image string + ExpectedRepo string + ExpectedTag string + }{ + {"", "", ""}, + {"ubuntu", "ubuntu", "latest"}, + {"ubuntu:20.04", "ubuntu", "20.04"}, + {"linux:ubuntu:20.04", "linux", "ubuntu:20.04"}, + } + + for _, test := range tests { + b := Bundle{Image: test.Image} + repo, tag := b.ImageFullParts() + + assert.Equal(t, test.ExpectedRepo, repo) + assert.Equal(t, test.ExpectedTag, tag) + } +} + +func TestCoerceVersionToSemver(t *testing.T) { + tests := []struct { + Version string + Expected string + }{ + // Zero value + {"", "0.0.0"}, + + // Malicious? edge cases + {"v", "0.0.0"}, + {" v1 ", "1.0.0"}, + + // Examples from semver.org + {"1.0.0-alpha", "1.0.0-alpha"}, + {"v1.0.0-alpha", "1.0.0-alpha"}, + {"1.0.0-alpha.1", "1.0.0-alpha.1"}, + {"v1.0.0-alpha.1", "1.0.0-alpha.1"}, + {"1.0.0-0.3.7", "1.0.0-0.3.7"}, + {"v1.0.0-0.3.7", "1.0.0-0.3.7"}, + {"1.0.0-x.7.z.92", "1.0.0-x.7.z.92"}, + {"v1.0.0-x.7.z.92", "1.0.0-x.7.z.92"}, + {"1.0.0-alpha+001", "1.0.0-alpha+001"}, + {"v1.0.0-alpha+001", "1.0.0-alpha+001"}, + {"1.0.0+20130313144700", "1.0.0+20130313144700"}, + {"v1.0.0+20130313144700", "1.0.0+20130313144700"}, + {"1.0.0-beta+exp.sha.5114f85", "1.0.0-beta+exp.sha.5114f85"}, + {"v1.0.0-beta+exp.sha.5114f85", "1.0.0-beta+exp.sha.5114f85"}, + + // Version coercion + {"1", "1.0.0"}, + {"v1", "1.0.0"}, + {"1.2", "1.2.0"}, + {"v1.2", "1.2.0"}, + {"1.2.3", "1.2.3"}, + {"v1.2.3", "1.2.3"}, + {"1.2.3.4", "1.2.3"}, // Truncate to 3 parts. + {"v1.2.3.4", "1.2.3"}, + } + + for _, test := range tests { + result := CoerceVersionToSemver(test.Version) + assert.Equal(t, test.Expected, result, "Test case: %q", test.Version) + + _, err := semver.NewVersion(result) + assert.NoError(t, err, "Test case: %q", test.Version) + } +} + +func TestSemver(t *testing.T) { + tests := []struct { + Version string + Expected semver.Version + }{ + // Zero value + {"", semver.Version{}}, + + // Malicious? edge cases + {"v", semver.Version{}}, + {" v1 ", *semver.New("1.0.0")}, + + // Examples from *semver.org + {"1.0.0-alpha", *semver.New("1.0.0-alpha")}, + {"v1.0.0-alpha", *semver.New("1.0.0-alpha")}, + {"1.0.0-alpha.1", *semver.New("1.0.0-alpha.1")}, + {"v1.0.0-alpha.1", *semver.New("1.0.0-alpha.1")}, + {"1.0.0-0.3.7", *semver.New("1.0.0-0.3.7")}, + {"v1.0.0-0.3.7", *semver.New("1.0.0-0.3.7")}, + {"1.0.0-x.7.z.92", *semver.New("1.0.0-x.7.z.92")}, + {"v1.0.0-x.7.z.92", *semver.New("1.0.0-x.7.z.92")}, + {"1.0.0-alpha+001", *semver.New("1.0.0-alpha+001")}, + {"v1.0.0-alpha+001", *semver.New("1.0.0-alpha+001")}, + {"1.0.0+20130313144700", *semver.New("1.0.0+20130313144700")}, + {"v1.0.0+20130313144700", *semver.New("1.0.0+20130313144700")}, + {"1.0.0-beta+exp.sha.5114f85", *semver.New("1.0.0-beta+exp.sha.5114f85")}, + {"v1.0.0-beta+exp.sha.5114f85", *semver.New("1.0.0-beta+exp.sha.5114f85")}, + + // Version coercion + {"1", *semver.New("1.0.0")}, + {"v1", *semver.New("1.0.0")}, + {"1.2", *semver.New("1.2.0")}, + {"v1.2", *semver.New("1.2.0")}, + {"1.2.3", *semver.New("1.2.3")}, + {"v1.2.3", *semver.New("1.2.3")}, + {"1.2.3.4", *semver.New("1.2.3")}, + {"v1.2.3.4", *semver.New("1.2.3")}, + } + + for _, test := range tests { + b := Bundle{Version: test.Version} + result := b.Semver() + assert.Equal(t, test.Expected, result, "Test case: %q", test.Version) + } +} diff --git a/dataaccess/memory/bundle-access.go b/dataaccess/memory/bundle-access.go index fe3b67e..989f0cc 100644 --- a/dataaccess/memory/bundle-access.go +++ b/dataaccess/memory/bundle-access.go @@ -42,6 +42,8 @@ func (da *InMemoryDataAccess) BundleCreate(ctx context.Context, bundle data.Bund return errs.ErrBundleExists } + bundle.Image = bundle.ImageFull() + da.bundles[bundleKey(bundle.Name, bundle.Version)] = &bundle return nil diff --git a/dataaccess/postgres/bundle-access.go b/dataaccess/postgres/bundle-access.go index 175f833..6f138f7 100644 --- a/dataaccess/postgres/bundle-access.go +++ b/dataaccess/postgres/bundle-access.go @@ -647,21 +647,31 @@ func (da PostgresDataAccess) doFindCommandEntry(ctx context.Context, tx *sql.Tx, func (da PostgresDataAccess) doBundleGet(ctx context.Context, tx *sql.Tx, name string, version string) (data.Bundle, error) { query := `SELECT gort_bundle_version, name, version, author, homepage, - description, long_description, docker_image, docker_tag, + description, long_description, image_repository, image_tag, install_timestamp, install_user FROM bundles WHERE name=$1 AND version=$2` + var repository, tag string + bundle := data.Bundle{} row := tx.QueryRowContext(ctx, query, name, version) err := row.Scan(&bundle.GortBundleVersion, &bundle.Name, &bundle.Version, &bundle.Author, &bundle.Homepage, &bundle.Description, - &bundle.LongDescription, &bundle.Docker.Image, &bundle.Docker.Tag, + &bundle.LongDescription, &repository, &tag, &bundle.InstalledOn, &bundle.InstalledBy) if err != nil { return bundle, gerr.Wrap(errs.ErrNoSuchBundle, err) } + if repository != "" { + if tag == "" { + tag = "latest" + } + + bundle.Image = repository + ":" + tag + } + enabledVersion, err := da.doBundleEnabledVersion(ctx, tx, name) if err != nil { return bundle, gerr.Wrap(fmt.Errorf("failed to get bundle enabled version"), err) @@ -893,13 +903,15 @@ func (da PostgresDataAccess) doBundleGetTemplates(ctx context.Context, tx *sql.T func (da PostgresDataAccess) doBundleInsert(ctx context.Context, tx *sql.Tx, bundle data.Bundle) error { query := `INSERT INTO bundles (gort_bundle_version, name, version, author, - homepage, description, long_description, docker_image, - docker_tag, install_user) + homepage, description, long_description, image_repository, image_tag, + install_user) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);` + repository, tag := bundle.ImageFullParts() + _, err := tx.ExecContext(ctx, query, bundle.GortBundleVersion, bundle.Name, bundle.Version, bundle.Author, bundle.Homepage, bundle.Description, bundle.LongDescription, - bundle.Docker.Image, bundle.Docker.Tag, bundle.InstalledBy) + repository, tag, bundle.InstalledBy) if err != nil { if strings.Contains(err.Error(), "violates") { diff --git a/dataaccess/postgres/postgres-data-access.go b/dataaccess/postgres/postgres-data-access.go index 53db71a..9978d44 100644 --- a/dataaccess/postgres/postgres-data-access.go +++ b/dataaccess/postgres/postgres-data-access.go @@ -266,8 +266,8 @@ func (da PostgresDataAccess) createBundlesTables(ctx context.Context, db *sql.DB homepage TEXT, description TEXT NOT NULL CHECK(description <> ''), long_description TEXT, - docker_image TEXT, - docker_tag TEXT, + image_repository TEXT, + image_tag TEXT, install_timestamp TIMESTAMP WITH TIME ZONE, install_user TEXT, CONSTRAINT unq_bundle UNIQUE(name, version), diff --git a/dataaccess/tests/bundle-access.go b/dataaccess/tests/bundle-access.go index 3db6269..3a036ea 100644 --- a/dataaccess/tests/bundle-access.go +++ b/dataaccess/tests/bundle-access.go @@ -37,6 +37,7 @@ func (da DataAccessTester) testBundleAccess(t *testing.T) { t.Run("testBundleDelete", da.testBundleDelete) t.Run("testBundleDeleteDoesntDisable", da.testBundleDeleteDoesntDisable) t.Run("testBundleGet", da.testBundleGet) + t.Run("testBundleImageConsistency", da.testBundleImageConsistency) t.Run("testBundleList", da.testBundleList) t.Run("testBundleVersionList", da.testBundleVersionList) t.Run("testFindCommandEntry", da.testFindCommandEntry) @@ -311,7 +312,7 @@ func (da DataAccessTester) testBundleGet(t *testing.T) { // This is set automatically on save, so we copy it here for the sake of the tests. bundleCreate.InstalledOn = bundleGet.InstalledOn - assert.Equal(t, bundleCreate.Docker, bundleGet.Docker) + assert.Equal(t, bundleCreate.Image, bundleGet.Image) assert.ElementsMatch(t, bundleCreate.Permissions, bundleGet.Permissions) assert.Equal(t, bundleCreate.Commands, bundleGet.Commands) assert.Equal(t, bundleCreate.Kubernetes, bundleGet.Kubernetes) @@ -320,6 +321,31 @@ func (da DataAccessTester) testBundleGet(t *testing.T) { assert.Equal(t, bundleCreate, bundleGet) } +func (da DataAccessTester) testBundleImageConsistency(t *testing.T) { + tests := []struct { + B data.Bundle + ExpectedImage string + }{ + {data.Bundle{GortBundleVersion: 1, Name: "test-image-0", Version: "0.0.0", Description: "Foo"}, ""}, + {data.Bundle{GortBundleVersion: 1, Name: "test-image-1", Version: "0.0.1", Description: "Foo", Image: "ubuntu:20.04"}, "ubuntu:20.04"}, + {data.Bundle{GortBundleVersion: 1, Name: "test-image-2", Version: "0.0.2", Description: "Foo", Image: "ubuntu:latest"}, "ubuntu:latest"}, + {data.Bundle{GortBundleVersion: 1, Name: "test-image-3", Version: "0.0.3", Description: "Foo", Image: "ubuntu"}, "ubuntu:latest"}, + } + + const msg = "Test case %d: Name:%q Image:%q" + + for i, test := range tests { + err := da.BundleCreate(da.ctx, test.B) + require.NoError(t, err, msg, i, test.B.Name, test.B.Image) + defer da.BundleDelete(da.ctx, test.B.Name, test.B.Version) + + b, err := da.BundleGet(da.ctx, test.B.Name, test.B.Version) + require.NoError(t, err, msg, i, test.B.Name, test.B.Image) + + assert.Equal(t, test.ExpectedImage, b.Image) + } +} + func (da DataAccessTester) testBundleList(t *testing.T) { da.BundleCreate(da.ctx, data.Bundle{GortBundleVersion: 5, Name: "test-list-0", Version: "0.0", Description: "foo"}) defer da.BundleDelete(da.ctx, "test-list-0", "0.0") diff --git a/dataaccess/tests/token-access.go b/dataaccess/tests/token-access.go index afe258d..427a732 100644 --- a/dataaccess/tests/token-access.go +++ b/dataaccess/tests/token-access.go @@ -87,7 +87,7 @@ func (da DataAccessTester) testTokenExpiry(t *testing.T) { defer da.UserDelete(da.ctx, "test_expires") assert.NoError(t, err) - token, err := da.TokenGenerate(da.ctx, "test_expires", 1*time.Second) + token, err := da.TokenGenerate(da.ctx, "test_expires", time.Second/2) defer da.TokenInvalidate(da.ctx, token.Token) assert.NoError(t, err) require.False(t, token.IsExpired()) diff --git a/testing/config/complete.yml b/testing/config/complete.yml index f3a29ca..0a0f9c0 100644 --- a/testing/config/complete.yml +++ b/testing/config/complete.yml @@ -113,37 +113,3 @@ slack: # The name of the bot, as it appears in Slack. Defaults to the name used # when the bot was added to the account. bot_name: Gort - -bundles: -- name: echo - description: A default bundle with echo commands. - - permissions: - - echo - - docker: - image: getgort/relaytest - tag: latest - - commands: - echo: - description: "Echos back anything sent to it, all at once." - executable: ["/bin/echo"] - splitecho: - description: "Echos back anything sent to it, one parameter at a time." - executable: ["/opt/app/splitecho.sh"] - -- name: curl - description: A default bundle that provides curl. - - permissions: - - echo - - docker: - image: getgort/relaytest - tag: latest - - commands: - curl: - description: "The official curl command." - executable: ["/usr/bin/curl"] diff --git a/testing/config/no-database-password.yml b/testing/config/no-database-password.yml index d434d0f..43fe2a9 100644 --- a/testing/config/no-database-password.yml +++ b/testing/config/no-database-password.yml @@ -110,37 +110,3 @@ slack: # The name of the bot, as it appears in Slack. Defaults to the name used # when the bot was added to the account. bot_name: Gort - -bundles: -- name: echo - description: A default bundle with echo commands. - - permissions: - - echo - - docker: - image: getgort/relaytest - tag: latest - - commands: - echo: - description: "Echos back anything sent to it, all at once." - executable: ["/bin/echo"] - splitecho: - description: "Echos back anything sent to it, one parameter at a time." - executable: ["/opt/app/splitecho.sh"] - -- name: curl - description: A default bundle that provides curl. - - permissions: - - echo - - docker: - image: getgort/relaytest - tag: latest - - commands: - curl: - description: "The official curl command." - executable: ["/usr/bin/curl"] diff --git a/testing/config/no-database.yml b/testing/config/no-database.yml index 50464e4..45dab34 100644 --- a/testing/config/no-database.yml +++ b/testing/config/no-database.yml @@ -68,37 +68,3 @@ slack: # The name of the bot, as it appears in Slack. Defaults to the name used # when the bot was added to the account. bot_name: Gort - -bundles: -- name: echo - description: A default bundle with echo commands. - - permissions: - - echo - - docker: - image: getgort/relaytest - tag: latest - - commands: - echo: - description: "Echos back anything sent to it, all at once." - executable: ["/bin/echo"] - splitecho: - description: "Echos back anything sent to it, one parameter at a time." - executable: ["/opt/app/splitecho.sh"] - -- name: curl - description: A default bundle that provides curl. - - permissions: - - echo - - docker: - image: getgort/relaytest - tag: latest - - commands: - curl: - description: "The official curl command." - executable: ["/usr/bin/curl"] diff --git a/testing/test-bundle-entrypoint.yml b/testing/test-bundle-entrypoint.yml index fbfbf03..b7cb8e8 100644 --- a/testing/test-bundle-entrypoint.yml +++ b/testing/test-bundle-entrypoint.yml @@ -13,9 +13,7 @@ long_description: |- permissions: - bar -docker: - image: ubuntu - tag: 20.04 +image: ubuntu:20.04 commands: bar: diff --git a/testing/test-bundle-foo.yml b/testing/test-bundle-foo.yml index 4e20d16..db3d9cf 100644 --- a/testing/test-bundle-foo.yml +++ b/testing/test-bundle-foo.yml @@ -13,9 +13,7 @@ long_description: |- permissions: - foo -docker: - image: ubuntu - tag: 20.04 +image: ubuntu:20.04 commands: foo: diff --git a/testing/test-bundle.yml b/testing/test-bundle.yml index 4cfb5f5..6a77f25 100644 --- a/testing/test-bundle.yml +++ b/testing/test-bundle.yml @@ -13,9 +13,7 @@ long_description: |- permissions: - echox -docker: - image: ubuntu - tag: 20.04 +image: ubuntu:20.04 templates: command_error: 'Template:Bundle:CommandError' @@ -77,4 +75,3 @@ commands: command_error: 'Template:Command:CommandError' message: 'Template:Command:Message' message_error: 'Template:Command:MessageError' - diff --git a/testing/test-default.yml b/testing/test-default.yml index dec8fcb..11fe693 100644 --- a/testing/test-default.yml +++ b/testing/test-default.yml @@ -17,9 +17,7 @@ permissions: - manage_roles - manage_users -docker: - image: getgort/gort - tag: latest +image: getgort/gort:latest commands: bundle: diff --git a/worker/docker/worker.go b/worker/docker/worker.go index 8a926a5..efdb2d0 100644 --- a/worker/docker/worker.go +++ b/worker/docker/worker.go @@ -50,8 +50,6 @@ type ContainerWorker struct { // New will build and returns a new Worker for a single command execution. func New(command data.CommandRequest, token rest.Token) (*ContainerWorker, error) { - image := command.Bundle.Docker.Image - tag := command.Bundle.Docker.Tag entrypoint := command.Command.Executable params := command.Parameters @@ -66,10 +64,6 @@ func New(command data.CommandRequest, token rest.Token) (*ContainerWorker, error return nil, err } - if tag == "" { - tag = "latest" - } - return &ContainerWorker{ command: command, commandParameters: params, @@ -77,7 +71,7 @@ func New(command data.CommandRequest, token rest.Token) (*ContainerWorker, error dockerHost: config.GetDockerConfigs().DockerHost, entryPoint: entrypoint, exitStatus: make(chan int64), - imageName: image + ":" + tag, + imageName: command.Bundle.ImageFull(), token: token, }, nil } diff --git a/worker/kubernetes/worker.go b/worker/kubernetes/worker.go index c418289..df9488e 100644 --- a/worker/kubernetes/worker.go +++ b/worker/kubernetes/worker.go @@ -53,15 +53,9 @@ type KubernetesWorker struct { // New will build and returns a new Worker for a single command execution. func New(command data.CommandRequest, token rest.Token) (*KubernetesWorker, error) { - image := command.Bundle.Docker.Image - tag := command.Bundle.Docker.Tag entrypoint := command.Command.Executable params := command.Parameters - if tag == "" { - tag = "latest" - } - // creates the in-cluster config kconfig, err := k8srest.InClusterConfig() if err != nil { @@ -80,7 +74,7 @@ func New(command data.CommandRequest, token rest.Token) (*KubernetesWorker, erro commandParameters: params, entryPoint: entrypoint, exitStatus: make(chan int64, 1), - imageName: image + ":" + tag, + imageName: command.Bundle.ImageFull(), token: token, }