Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Add ability for render steps to specify specific assets #855

Merged
merged 4 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
assets:
v1:
- inline:
dest: ./install.sh
contents: |
#!/bin/sh
echo installing...
config: {}
lifecycle:
v1:
- render:
root: do
- render:
root: undo
assets:
v1:
- inline:
dest: ./uninstall.sh
contents: |
#!/bin/sh
echo uninstalling...

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"v1": {
"config": {},
"contentSHA": "8ce189bc6b0c8992933394cc4a15b17aa51e6a3bc70e2238785ae84581c86699",
"metadata": {
"applicationType": "replicated.app",
"releaseNotes": "",
"version": ""
},
"releaseName": "ship",
"upstream": "/Users/dex/go/src/github.com/replicatedhq/ship/integration/base/direct-render-with-root-2/input/.ship/ship.yml?customer_id=\u0026installation_id=\u0026release_semver="
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo installing...
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo uninstalling...
23 changes: 23 additions & 0 deletions integration/base/direct-render-with-root-2/input/.ship/ship.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
assets:
v1:
- inline:
dest: ./install.sh
contents: |
#!/bin/sh
echo installing...
config: {}
lifecycle:
v1:
- render:
root: do
- render:
root: undo
assets:
v1:
- inline:
dest: ./uninstall.sh
contents: |
#!/bin/sh
echo uninstalling...

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 2 additions & 0 deletions integration/base/direct-render-with-root-2/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
skip_cleanup: false
disable_online: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
assets:
v1:
- inline:
dest: ./install.sh
contents: |
#!/bin/sh
echo installing...
config: {}
lifecycle:
v1:
- render: {}
- render:
root: ./
assets:
v1:
- inline:
dest: ./uninstall.sh
contents: |
#!/bin/sh
echo uninstalling...

13 changes: 13 additions & 0 deletions integration/base/direct-render-with-root/expected/.ship/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"v1": {
"config": {},
"contentSHA": "3a28dfd4ef900b7fc0ba9ce90626d3acc8b52d25afb6cf3a9464788343feb0c7",
"metadata": {
"applicationType": "replicated.app",
"releaseNotes": "",
"version": ""
},
"releaseName": "ship",
"upstream": "/Users/dex/go/src/github.com/replicatedhq/ship/integration/base/direct-render-with-root/input/.ship/ship.yml?customer_id=\u0026installation_id=\u0026release_semver="
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo installing...
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo uninstalling...
22 changes: 22 additions & 0 deletions integration/base/direct-render-with-root/input/.ship/ship.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
assets:
v1:
- inline:
dest: ./install.sh
contents: |
#!/bin/sh
echo installing...
config: {}
lifecycle:
v1:
- render: {}
- render:
root: ./
assets:
v1:
- inline:
dest: ./uninstall.sh
contents: |
#!/bin/sh
echo uninstalling...

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 2 additions & 0 deletions integration/base/direct-render-with-root/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
skip_cleanup: false
disable_online: true
23 changes: 23 additions & 0 deletions integration/base/direct-render/expected/.ship/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
assets:
v1:
- inline:
dest: ./install.sh
contents: |
#!/bin/sh
echo installing...
config: {}
lifecycle:
v1:
- render:
root: ./
- render:
root: ./
assets:
v1:
- inline:
dest: ./uninstall.sh
contents: |
#!/bin/sh
echo uninstalling...

13 changes: 13 additions & 0 deletions integration/base/direct-render/expected/.ship/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"v1": {
"config": {},
"contentSHA": "d04ecc9031dc7f8670e54f5881c77fa3623910abdca3d54344939e6e3d4a3167",
"metadata": {
"applicationType": "replicated.app",
"releaseNotes": "",
"version": ""
},
"releaseName": "ship",
"upstream": "/Users/dex/go/src/github.com/replicatedhq/ship/integration/base/direct-render/input/.ship/ship.yml?customer_id=\u0026installation_id=\u0026release_semver="
}
}
2 changes: 2 additions & 0 deletions integration/base/direct-render/expected/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo installing...
2 changes: 2 additions & 0 deletions integration/base/direct-render/expected/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo uninstalling...
23 changes: 23 additions & 0 deletions integration/base/direct-render/input/.ship/ship.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
assets:
v1:
- inline:
dest: ./install.sh
contents: |
#!/bin/sh
echo installing...
config: {}
lifecycle:
v1:
- render:
root: ./
- render:
root: ./
assets:
v1:
- inline:
dest: ./uninstall.sh
contents: |
#!/bin/sh
echo uninstalling...

2 changes: 2 additions & 0 deletions integration/base/direct-render/input/.ship/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 2 additions & 0 deletions integration/base/direct-render/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
skip_cleanup: false
disable_online: true
41 changes: 1 addition & 40 deletions integration/init_app/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"path"
"strings"
Expand All @@ -17,11 +16,7 @@ import (
"github.com/onsi/gomega/format"
"github.com/replicatedhq/ship/integration"
"github.com/replicatedhq/ship/pkg/cli"
"github.com/replicatedhq/ship/pkg/e2e"
"github.com/replicatedhq/ship/pkg/logger"
"github.com/spf13/afero"
"github.com/spf13/viper"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
)

type TestMetadata struct {
Expand Down Expand Up @@ -158,40 +153,6 @@ var _ = Describe("ship init replicated.app/...", func() {
}
})

func createRelease(
vendorEndpoint string,
vendorToken string,
testInputPath string,
testMetadata TestMetadata,
channelName string,
customerID string,
) string {
endpointURL, err := url.Parse(vendorEndpoint)
Expect(err).NotTo(HaveOccurred())
vendorClient := &e2e.GraphQLClient{
GQLServer: endpointURL,
Token: vendorToken,
Logger: logger.New(
viper.GetViper(),
afero.Afero{Fs: afero.NewMemMapFs()},
),
}
releaseContents, err := ioutil.ReadFile(path.Join(testInputPath, ".ship/release.yml"))
Expect(err).NotTo(HaveOccurred())
channel, err := vendorClient.GetOrCreateChannel(channelName)
Expect(err).NotTo(HaveOccurred())
_, err = vendorClient.PromoteRelease(
string(releaseContents),
channel.ID,
testMetadata.ReleaseVersion,
"integration tests",
)
Expect(err).NotTo(HaveOccurred())
installationID, err := vendorClient.EnsureCustomerOnChannel(customerID, channel.ID)
Expect(err).NotTo(HaveOccurred())
return installationID
}

func readMetadata(testPath string) TestMetadata {
var testMetadata TestMetadata
metadataBytes, err := ioutil.ReadFile(path.Join(testPath, "metadata.yaml"))
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (m *Message) ShortName() string { return "message" }
// Render is a lifeycle step to collect config and render assets
type Render struct {
StepShared `json:",inline" yaml:",inline" hcl:",inline"`
Root string `json:"root,omitempty" yaml:"root,omitempty" hcl:"root,omitempty"`
Root string `json:"root,omitempty" yaml:"root,omitempty" hcl:"root,omitempty"`
Assets *Assets `json:"assets,omitempty" yaml:"assets,omitempty" hcl:"assets,omitempty"`
}

func (r *Render) Shared() *StepShared { return &r.StepShared }
Expand Down
27 changes: 27 additions & 0 deletions pkg/api/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ lifecycle:
Render: &Render{},
},
},
{
name: "render with override assets",
yaml: `
---
lifecycle:
v1:
- render:
root: ./bigapp
assets:
v1:
- inline: { contents: fake }`,

expect: Step{
Render: &Render{
Root: "./bigapp",
Assets: &Assets{
V1: []Asset{
{
Inline: &InlineAsset{
Contents: "fake",
},
},
},
},
},
},
},
{
name: "terraform",
yaml: `
Expand Down
1 change: 0 additions & 1 deletion pkg/lifecycle/kustomize/kustomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/replicatedhq/ship/pkg/lifecycle/daemon/daemontypes"
"github.com/replicatedhq/ship/pkg/state"
"github.com/replicatedhq/ship/pkg/util"

"github.com/spf13/afero"
yaml "gopkg.in/yaml.v2"
"sigs.k8s.io/kustomize/pkg/patch"
Expand Down
1 change: 0 additions & 1 deletion pkg/lifecycle/render/docker/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/replicatedhq/ship/pkg/lifecycle/render/root"
"github.com/replicatedhq/ship/pkg/templates"
"github.com/replicatedhq/ship/pkg/util"

"github.com/spf13/viper"
)

Expand Down
1 change: 0 additions & 1 deletion pkg/lifecycle/render/dockerlayer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/replicatedhq/ship/pkg/lifecycle/render/docker"
"github.com/replicatedhq/ship/pkg/lifecycle/render/root"
"github.com/replicatedhq/ship/pkg/util"

"github.com/spf13/afero"
"github.com/spf13/viper"
)
Expand Down
1 change: 0 additions & 1 deletion pkg/lifecycle/render/github/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/replicatedhq/ship/pkg/state"
"github.com/replicatedhq/ship/pkg/templates"
"github.com/replicatedhq/ship/pkg/util"

"github.com/spf13/afero"
"github.com/spf13/viper"
)
Expand Down
1 change: 0 additions & 1 deletion pkg/lifecycle/render/inline/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/replicatedhq/ship/pkg/lifecycle/render/root"
"github.com/replicatedhq/ship/pkg/templates"
"github.com/replicatedhq/ship/pkg/util"

"github.com/spf13/viper"
)

Expand Down
1 change: 0 additions & 1 deletion pkg/lifecycle/render/local/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/replicatedhq/libyaml"
"github.com/replicatedhq/ship/pkg/api"
"github.com/replicatedhq/ship/pkg/util"

"github.com/spf13/afero"
)

Expand Down
7 changes: 6 additions & 1 deletion pkg/lifecycle/render/noconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ func (r *noconfigrenderer) Execute(ctx context.Context, release *api.Release, st
step.Root = constants.InstallerPrefixPath
}

assets := release.Spec.Assets.V1
if step.Assets != nil && step.Assets.V1 != nil {
assets = step.Assets.V1
}

debug.Log("event", "render.plan")
pln, err := r.Planner.Build(step.Root, release.Spec.Assets.V1, release.Spec.Config.V1, release.Metadata, templateContext)
pln, err := r.Planner.Build(step.Root, assets, release.Spec.Config.V1, release.Metadata, templateContext)
if err != nil {
return errors.Wrap(err, "build plan")
}
Expand Down
Loading