-
Notifications
You must be signed in to change notification settings - Fork 296
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
Add asset package creation #1085
Changes from 31 commits
37038bc
7e14c8e
91c3f79
d66afe7
9aac982
a697f8f
c3026b3
d9b34c9
9e43ddd
bd14cf1
32046be
95f7149
559f1b6
de288b6
b74783b
1ce7b7b
8cd64ab
50392ce
faa3452
0b7da6f
656bead
69c8770
ab47504
5600f80
5f12f2d
a17d448
62b995e
336fd97
d628689
8084466
89afd7a
30d9fda
ced5d7a
9208e55
46bba8f
d341285
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,25 @@ func (m PackFixtureManager) TemplateFixtureToFile(name string, destination *os.F | |
m.assert.Nil(err) | ||
} | ||
|
||
func (m PackFixtureManager) TemplateFile(file *os.File, data map[string]interface{}) { | ||
m.testObject.Helper() | ||
|
||
outputTemplate, err := ioutil.ReadAll(file) | ||
m.assert.Nil(err) | ||
|
||
_, err = file.Seek(0, 0) | ||
m.assert.Nil(err) | ||
|
||
err = file.Truncate(0) | ||
m.assert.Nil(err) | ||
Comment on lines
+88
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do these do, together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They delete all the files contents and reset the
Note this is only done on files that have been moved into a |
||
|
||
str := m.fillTemplate(outputTemplate, data) | ||
fmt.Printf("filled template for %s\n", file.Name()) | ||
fmt.Println(str) | ||
_, err = io.WriteString(file, m.fillTemplate(outputTemplate, data)) | ||
m.assert.Nil(err) | ||
} | ||
|
||
func (m PackFixtureManager) fillTemplate(templateContents []byte, data map[string]interface{}) string { | ||
tpl, err := template.New(""). | ||
Funcs(template.FuncMap{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A pretty cool asset Ayyyy. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Just another asset. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Just another-nother asset. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
api = "0.8" | ||
|
||
[buildpack] | ||
id = "all-assets/asset-buildpack" | ||
version = "all-assets-builapck-version" | ||
name = "All Assets Buildpack Buildpack" | ||
|
||
[[stacks]] | ||
id = "pack.test.stack" | ||
|
||
[[assets]] | ||
id = "asset A" | ||
sha256 = "797b3f6bf2b2c10a8299d51dfdbcfed329d3c133fdc7e695beddbe8f70b49da9" | ||
name = "A Asset" | ||
stacks = ["pack.test.stack"] | ||
uri = "{{ .assetAURI }}" | ||
version = "1.2.3" | ||
|
||
[[assets]] | ||
id = "asset C" | ||
sha256 = "339b5181dac7c2d01cbbd6fff90f541f0350864f03a02f05faf852baa2826064" | ||
name = "C Asset" | ||
stacks = ["pack.test.stack"] | ||
uri = "{{ .assetCURI }}" | ||
version = "1.3.5" | ||
|
||
[[assets]] | ||
id = "asset B" | ||
name = "B Asset" | ||
sha256 = "61eea2ec4053ca25b9bd5d7bebaba48ee5398569aa1da5bc3541cbab1d09b86b" | ||
stacks = ["pack.test.stack"] | ||
uri = "{{ .assetBURI }}" | ||
version = "4.5.6" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
api = "0.2" | ||
|
||
[buildpack] | ||
id = "simple/nested" | ||
version = "nested-version" | ||
name = "Nested Asset Buildpack" | ||
|
||
[[order]] | ||
[[order.group]] | ||
id = "simple/asset-buildpack" | ||
version = "simple-asset-buildpack-version" | ||
[[order.group]] | ||
id = "second-simple/asset-buildpack" | ||
version = "second-simple-asset-buildpack-version" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
api = "0.2" | ||
|
||
[buildpack] | ||
id = "second-simple/asset-buildpack" | ||
version = "second-simple-asset-buildpack-version" | ||
name = "Second Simple Asset Buildpack Buildpack" | ||
|
||
[[stacks]] | ||
id = "pack.test.stack" | ||
|
||
|
||
[[assets]] | ||
id = "asset C" | ||
sha256 = "339b5181dac7c2d01cbbd6fff90f541f0350864f03a02f05faf852baa2826064" | ||
name = "C Asset" | ||
stacks = ["pack.test.stack"] | ||
uri = "{{ .assetCURI }}" | ||
version = "1.3.5" | ||
|
||
[[assets]] | ||
id = "asset B repeat" | ||
name = "B Asset Repeat" | ||
sha256 = "61eea2ec4053ca25b9bd5d7bebaba48ee5398569aa1da5bc3541cbab1d09b86b" | ||
stacks = ["pack.test.stack"] | ||
uri = "{{ .assetBURI }}" | ||
version = "4.5.6" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "---> Build: Simple Asset Layers Buildpack" | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
launch_dir=$1 | ||
|
||
## makes a launch layer | ||
echo "making launch layer" | ||
|
||
# Add color line, to test for --no-color | ||
echo "Color: [0mStyled" | ||
|
||
mkdir "$launch_dir/launch-layer" | ||
echo "Launch Dep Contents" > "$launch_dir/launch-layer/launch-dep" | ||
ln -snf "$launch_dir/launch-layer" launch-deps | ||
echo "launch = true" > "$launch_dir/launch-layer.toml" | ||
|
||
## checks if assetsA is available | ||
if [[ -f "/cnb/assets/797b3f6bf2b2c10a8299d51dfdbcfed329d3c133fdc7e695beddbe8f70b49da9" ]]; then | ||
echo "Asset A exists!" | ||
cat "/cnb/assets/797b3f6bf2b2c10a8299d51dfdbcfed329d3c133fdc7e695beddbe8f70b49da9" | ||
printf "\n" | ||
fi | ||
|
||
if [[ -f "/cnb/assets/61eea2ec4053ca25b9bd5d7bebaba48ee5398569aa1da5bc3541cbab1d09b86b" ]]; then | ||
echo "Asset B exists!" | ||
cat "/cnb/assets/61eea2ec4053ca25b9bd5d7bebaba48ee5398569aa1da5bc3541cbab1d09b86b" | ||
printf "\n" | ||
fi | ||
|
||
## makes a cached launch layer | ||
if [[ ! -f "$launch_dir/cached-launch-layer.toml" ]]; then | ||
echo "making cached launch layer" | ||
mkdir "$launch_dir/cached-launch-layer" | ||
echo "Cached Dep Contents" > "$launch_dir/cached-launch-layer/cached-dep" | ||
ln -snf "$launch_dir/cached-launch-layer" cached-deps | ||
echo "launch = true" > "$launch_dir/cached-launch-layer.toml" | ||
echo "cache = true" >> "$launch_dir/cached-launch-layer.toml" | ||
else | ||
echo "reusing cached launch layer" | ||
ln -snf "$launch_dir/cached-launch-layer" cached-deps | ||
fi | ||
|
||
## adds a process | ||
cat <<EOF > "$launch_dir/launch.toml" | ||
[[processes]] | ||
type = "web" | ||
command = "./run" | ||
args = ["8080"] | ||
|
||
[[processes]] | ||
type = "hello" | ||
command = "echo" | ||
args = ["hello", "world"] | ||
direct = true | ||
EOF | ||
|
||
echo "---> Done" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@echo off | ||
echo --- Build: Simple Asset Layers Buildpack | ||
|
||
set launch_dir=%1 | ||
|
||
:: makes a launch layer | ||
echo making launch layer %launch_dir%\launch-layer | ||
mkdir %launch_dir%\launch-layer | ||
echo Launch Dep Contents > "%launch_dir%\launch-layer\launch-dep | ||
mklink /j launch-deps %launch_dir%\launch-layer | ||
echo launch = true > %launch_dir%\launch-layer.toml | ||
|
||
:: makes a cached launch layer | ||
if not exist %launch_dir%\cached-launch-layer.toml ( | ||
echo making cached launch layer %launch_dir%\cached-launch-layer | ||
mkdir %launch_dir%\cached-launch-layer | ||
echo Cached Dep Contents > %launch_dir%\cached-launch-layer\cached-dep | ||
mklink /j cached-deps %launch_dir%\cached-launch-layer | ||
echo launch = true > %launch_dir%\cached-launch-layer.toml | ||
echo cache = true >> %launch_dir%\cached-launch-layer.toml | ||
) else ( | ||
echo reusing cached launch layer %launch_dir%\cached-launch-layer | ||
mklink /j cached-deps %launch_dir%\cached-launch-layer | ||
) | ||
|
||
:: check if assets are locally available | ||
if exist "/cnb/assets/797b3f6bf2b2c10a8299d51dfdbcfed329d3c133fdc7e695beddbe8f70b49da9" ( | ||
echo "Asset A exists!" | ||
type \cnb\assets\797b3f6bf2b2c10a8299d51dfdbcfed329d3c133fdc7e695beddbe8f70b49da9 | ||
) | ||
|
||
if exist "/cnb/assets/61eea2ec4053ca25b9bd5d7bebaba48ee5398569aa1da5bc3541cbab1d09b86b" ( | ||
echo "Asset B exists!" | ||
type \cnb\assets\61eea2ec4053ca25b9bd5d7bebaba48ee5398569aa1da5bc3541cbab1d09b86b | ||
) | ||
|
||
:: adds a process | ||
( | ||
echo [[processes]] | ||
echo type = "web" | ||
echo command = '.\run' | ||
echo args = ["8080"] | ||
echo. | ||
echo [[processes]] | ||
echo type = "hello" | ||
echo command = "cmd" | ||
echo args = ["/c", "echo hello world"] | ||
echo direct = true | ||
) > %launch_dir%\launch.toml | ||
|
||
echo --- Done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
## always detect |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@echo off | ||
:: always detect |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
api = "0.2" | ||
|
||
[buildpack] | ||
id = "simple/asset-buildpack" | ||
version = "simple-asset-buildpack-version" | ||
name = "Simple Asset Buildpack Buildpack" | ||
|
||
[[stacks]] | ||
id = "pack.test.stack" | ||
|
||
[[assets]] | ||
id = "asset A" | ||
sha256 = "797b3f6bf2b2c10a8299d51dfdbcfed329d3c133fdc7e695beddbe8f70b49da9" | ||
name = "A Asset" | ||
stacks = ["pack.test.stack"] | ||
uri = "{{ .assetAURI }}" | ||
version = "1.2.3" | ||
|
||
[[assets]] | ||
id = "asset B" | ||
name = "B Asset" | ||
sha256 = "61eea2ec4053ca25b9bd5d7bebaba48ee5398569aa1da5bc3541cbab1d09b86b" | ||
stacks = ["pack.test.stack"] | ||
uri = "{{ .assetBURI }}" | ||
version = "4.5.6" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[[buildpacks]] | ||
image = "{{.simple_buildpack_with_assets}}" | ||
|
||
[lifecycle] | ||
{{- if .lifecycle_uri}} | ||
uri = "{{.lifecycle_uri}}" | ||
{{- end}} | ||
{{- if .lifecycle_version}} | ||
version = "{{.lifecycle_version}}" | ||
{{- end}} | ||
|
||
[[order]] | ||
[[order.group]] | ||
id = "simple/asset-buildpack" | ||
|
||
[stack] | ||
id = "pack.test.stack" | ||
build-image = "pack-test/build" | ||
run-image = "pack-test/run" | ||
run-image-mirrors = ["{{.run_image_mirror}}"] | ||
|
||
[assets] | ||
[[assets.package]] | ||
image = "{{.asset_package_image_name}}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[buildpack] | ||
uri = "{{ .buildpack_uri }}" | ||
|
||
[platform] | ||
os = "{{ .OS }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[buildpack] | ||
uri = "nested-assets-buildpack.tgz" | ||
|
||
[[dependencies]] | ||
image = "{{.simple_buildpack}}" | ||
|
||
[[dependencies]] | ||
image = "{{.second_simple_buildpack}}" | ||
|
||
[platform] | ||
os = "{{ .OS }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside, this can be taken out, but this probably isn't the place to do that.