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

feat: Support legacy 'import' directive and use 'imports' for future #543

Merged
merged 2 commits into from
Nov 25, 2023
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
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build-env:
from:
type: docker
url: ${{STACKER_BUILD_BASE_IMAGE}}
import:
imports:
- https://github.com/json-c/json-c/archive/refs/tags/json-c-0.16-20220414.tar.gz
- https://gitlab.com/cryptsetup/cryptsetup/-/archive/v2.6.0/cryptsetup-v2.6.0.tar.gz
- https://github.com/lvmteam/lvm2/archive/refs/tags/v2_03_18.tar.gz
Expand Down
15 changes: 9 additions & 6 deletions cmd/stacker/bom.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"stackerbuild.io/stacker-bom/pkg/bom"
"stackerbuild.io/stacker-bom/pkg/distro"
"stackerbuild.io/stacker-bom/pkg/fs"
"stackerbuild.io/stacker/pkg/types"
)

var bomCmd = cli.Command{
Expand Down Expand Up @@ -39,7 +40,7 @@
author := "stacker-internal"
org := "stacker-internal"

if err := fs.Discover(author, org, "/stacker/artifacts/installed-packages.json"); err != nil {
if err := fs.Discover(author, org, types.InternalStackerDir+"/artifacts/installed-packages.json"); err != nil {

Check warning on line 43 in cmd/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

cmd/stacker/bom.go#L43

Added line #L43 was not covered by tests
return nil
}

Expand All @@ -57,7 +58,8 @@
org := "stacker-internal"
lic := "unknown"

if err := distro.ParsePackage(input, author, org, lic, fmt.Sprintf("/stacker/artifacts/%s.json", filepath.Base(input))); err != nil {
if err := distro.ParsePackage(input, author, org, lic, fmt.Sprintf("%s/artifacts/%s.json",
types.InternalStackerDir, filepath.Base(input))); err != nil {

Check warning on line 62 in cmd/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

cmd/stacker/bom.go#L61-L62

Added lines #L61 - L62 were not covered by tests
return nil
}

Expand Down Expand Up @@ -98,16 +100,17 @@
org := ctx.Args().Get(3)

// first merge all individual sbom artifacts that may have been generated
if err := bom.MergeDocuments("/stacker/artifacts", name, author, org, dest); err != nil {
iDir := types.InternalStackerDir
if err := bom.MergeDocuments(iDir+"/artifacts", name, author, org, dest); err != nil {

Check warning on line 104 in cmd/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

cmd/stacker/bom.go#L103-L104

Added lines #L103 - L104 were not covered by tests
return err
}

// check against inventory
if err := fs.GenerateInventory("/",
[]string{"/proc", "/sys", "/dev", "/etc/resolv.conf", "/stacker"},
"/stacker/artifacts/inventory.json"); err != nil {
[]string{"/proc", "/sys", "/dev", "/etc/resolv.conf", iDir},
iDir+"/artifacts/inventory.json"); err != nil {

Check warning on line 111 in cmd/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

cmd/stacker/bom.go#L110-L111

Added lines #L110 - L111 were not covered by tests
return err
}

return fs.Verify(dest, "/stacker/artifacts/inventory.json", "")
return fs.Verify(dest, iDir+"/artifacts/inventory.json", "")

Check warning on line 115 in cmd/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

cmd/stacker/bom.go#L115

Added line #L115 was not covered by tests
}
4 changes: 2 additions & 2 deletions cmd/stacker/chroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func doChroot(ctx *cli.Context) error {
}
defer c.Close()

err = stacker.SetupBuildContainerConfig(config, s, c, name)
err = stacker.SetupBuildContainerConfig(config, s, c, types.InternalStackerDir, name)
if err != nil {
return err
}
err = stacker.SetupLayerConfig(config, c, layer, name)
err = stacker.SetupLayerConfig(config, c, layer, types.InternalStackerDir, name)
if err != nil {
return err
}
Expand Down
22 changes: 14 additions & 8 deletions doc/stacker_yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ layer on a previously specified layer in the stacker file.
of `import` to generate minimal images, e.g. for statically built binaries.


### `import`
### `imports`

The `import` directive describes what files should be made available in
`/stacker` during the `run` phase. There are three forms of importing supported
The `imports` directive describes what files should be made available in
`/stacker/imports` during the `run` phase. There are three forms of importing supported
today:

/path/to/file
Expand All @@ -89,10 +89,10 @@ Will grab /path/to/file from the previously built layer `$name`.

#### `import hash`

The `import` directive also supports specifying the hash(sha256sum) of import source,
for all the three forms presented above, for example:
Each entry in the `imports' directive also supports specifying the hash(sha256sum) of
import source, for all the three forms presented above, for example:
```
import:
imports:
- path: config.json
hash: f55af805b012017bc....
- path: http://example.com/foo.tar.gz
Expand All @@ -115,7 +115,7 @@ If `--require-hash` is not passed, this import mode can be combined with uncheck
and only files which have the hash specified will be checked.

```
import:
imports:
- path: "config.json
hash: "BEEFcafeaaaaAAAA...."
- /path/to/file
Expand All @@ -127,11 +127,17 @@ The `import` directive also supports specifying the destination path (specified
by `dest`) in the resulting container image, where the source file (specified
by `path`) will be copyied to, for example:
```
import:
imports:
- path: config.json
dest: /
```


### (Deprecated) `import`
The deprecated `import` directive works like `imports` except that
the entries in the `import` array will be placed into `/stacker/` rather
than `/stacker/imports`.

### `overlay_dirs`
This directive works only with OverlayFS backend storage.

Expand Down
12 changes: 6 additions & 6 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ output will look something like:

There are two new stacker file directives here:

import:
imports:
- config.json
- install.sh

Expand All @@ -115,8 +115,8 @@ And then there is:

run: |
mkdir -p /etc/myapp
cp /stacker/config.json /etc/myapp/
/stacker/install.sh
cp /stacker/imports/config.json /etc/myapp/
/stacker/imports/install.sh

Which is the set of commands to run in order to install and configure the
image.
Expand Down Expand Up @@ -152,8 +152,8 @@ emitted in the final OCI image. For example:
from:
type: docker
url: docker://centos:latest
import: stacker://build/umoci.static
run: cp /stacker/umoci.static /usr/bin/umoci
imports: stacker://build/umoci.static
run: cp /stacker/imports/umoci.static /usr/bin/umoci

Will build a static version of umoci in an ubuntu container, but the final
image will only contain an `umoci` tag with a statically linked version of
Expand All @@ -165,7 +165,7 @@ indicates that the container shouldn't be emitted in the final image, because
we're going to import something from it and don't need the rest of it. The
line:

import: stacker://build/umoci.static
imports: stacker://build/umoci.static

is what actually does this import, and it says "from a previously built stacker
image called 'build', import /umoci.static".
19 changes: 11 additions & 8 deletions pkg/stacker/bom.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"io"
"os"
"path"
"path/filepath"

"stackerbuild.io/stacker/pkg/container"
"stackerbuild.io/stacker/pkg/log"
Expand All @@ -27,24 +28,25 @@
}
defer c.Close()

err = SetupBuildContainerConfig(sc, storage, c, tag)
inDir := types.InternalStackerDir
err = SetupBuildContainerConfig(sc, storage, c, inDir, tag)

Check warning on line 32 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L31-L32

Added lines #L31 - L32 were not covered by tests
if err != nil {
log.Errorf("build container %v", err)
return err
}

err = SetupLayerConfig(sc, c, l, tag)
err = SetupLayerConfig(sc, c, l, inDir, tag)

Check warning on line 38 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L38

Added line #L38 was not covered by tests
if err != nil {
return err
}

cmd := []string{insideStaticStacker}
cmd := []string{filepath.Join(inDir, types.BinStacker)}

Check warning on line 43 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L43

Added line #L43 was not covered by tests

if sc.Debug {
cmd = append(cmd, "--debug")
}

cmd = append(cmd, "bom", "build", "/stacker/artifacts",
cmd = append(cmd, "bom", "build", filepath.Join(inDir, "artifacts"),

Check warning on line 49 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L49

Added line #L49 was not covered by tests
l.Annotations[types.AuthorAnnotation],
l.Annotations[types.OrgAnnotation],
l.Annotations[types.LicenseAnnotation],
Expand All @@ -71,25 +73,26 @@
}
defer c.Close()

err = SetupBuildContainerConfig(sc, storage, c, tag)
inDir := types.InternalStackerDir
err = SetupBuildContainerConfig(sc, storage, c, inDir, tag)

Check warning on line 77 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L76-L77

Added lines #L76 - L77 were not covered by tests
if err != nil {
log.Errorf("build container %v", err)
return err
}

err = SetupLayerConfig(sc, c, l, tag)
err = SetupLayerConfig(sc, c, l, inDir, tag)

Check warning on line 83 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L83

Added line #L83 was not covered by tests
if err != nil {
return err
}

cmd := []string{insideStaticStacker}
cmd := []string{filepath.Join(inDir, types.BinStacker)}

Check warning on line 88 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L88

Added line #L88 was not covered by tests

if sc.Debug {
cmd = append(cmd, "--debug")
}

cmd = append(cmd, "bom", "verify",
fmt.Sprintf("/stacker/artifacts/%s.json", tag),
fmt.Sprintf(types.InternalStackerDir+"/artifacts/%s.json", tag),

Check warning on line 95 in pkg/stacker/bom.go

View check run for this annotation

Codecov / codecov/patch

pkg/stacker/bom.go#L95

Added line #L95 was not covered by tests
tag, l.Annotations[types.AuthorAnnotation], l.Annotations[types.OrgAnnotation])

err = c.Execute(cmd, os.Stdin)
Expand Down
Loading
Loading