Skip to content

Commit

Permalink
symbolic links are now created after all files are downloaded
Browse files Browse the repository at this point in the history
reduced log verbosity
  • Loading branch information
djcass44 committed Jul 5, 2024
1 parent cc4b808 commit 7871cf8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
9 changes: 8 additions & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,17 @@ func build(cmd *cobra.Command, _ []string) error {
Statement: &pipelines.Env{},
})

// collect a list of all the file statements in case
// something should be run after files are in place
var fileDeps []string

// download files
for i, file := range cfg.Spec.Files {
// expand paths using environment variables
path := filepath.Clean(os.Expand(file.Path, expandMap(envOpts)))
id := fmt.Sprintf("file-download-%d", i)
pipelineStatements = append(pipelineStatements, pipelines.OrderedPipelineStatement{
ID: fmt.Sprintf("file-download-%d", i),
ID: id,
Options: map[string]any{
"uri": airutil.ExpandEnv(file.URI),
"path": path,
Expand All @@ -219,6 +224,7 @@ func build(cmd *cobra.Command, _ []string) error {
Statement: &pipelines.File{},
DependsOn: []string{statements.StatementEnv},
})
fileDeps = append(fileDeps, id)
}

// create links
Expand All @@ -232,6 +238,7 @@ func build(cmd *cobra.Command, _ []string) error {
ID: "symbolic-links",
Options: linkOpts,
Statement: &pipelines.SymbolicLink{},
DependsOn: fileDeps,
})

// update ca certificates
Expand Down
8 changes: 6 additions & 2 deletions cmd/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func lock(cmd *cobra.Command, _ []string) error {
}

// get the digest of the base image
log.Info("generating parent image checksum")
if cfg.Spec.From != containers.MagicImageScratch {
baseDigest, err := crane.Digest(airutil.ExpandEnv(cfg.Spec.From), crane.WithAuthFromKeychain(auth.KeyChain(auth.Auth{})))
if err != nil {
Expand Down Expand Up @@ -122,6 +123,7 @@ func lock(cmd *cobra.Command, _ []string) error {
}

// get package integrity
log.Info("generating package checksums")
for _, pkg := range cfg.Spec.Packages {
var keeper packages.PackageManager
switch pkg.Type {
Expand All @@ -142,7 +144,7 @@ func lock(cmd *cobra.Command, _ []string) error {
}

for _, p := range packageList {
log.Info("downloading package", "name", p.Name)
log.V(1).Info("downloading package", "name", p.Name)

packageUrl := p.Resolved
for _, r := range repoList {
Expand All @@ -163,6 +165,7 @@ func lock(cmd *cobra.Command, _ []string) error {
}

// get file integrity
log.Info("generating file checksums")
for _, file := range cfg.Spec.Files {
dst, err := os.CreateTemp("", "file-download-*")
if err != nil {
Expand All @@ -179,7 +182,7 @@ func lock(cmd *cobra.Command, _ []string) error {
q.Set("archive", "false")
srcUri.RawQuery = q.Encode()

log.Info("downloading file", "file", srcUri, "path", dst.Name())
log.V(1).Info("downloading file", "file", srcUri, "path", dst.Name())
client := &getter.Client{
Ctx: cmd.Context(),
Pwd: wd,
Expand All @@ -205,6 +208,7 @@ func lock(cmd *cobra.Command, _ []string) error {
}
}

log.Info("exporting lockfile")
f, err := os.Create(lockfile.Name(configPath))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/statements/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *PackageStatement) Run(ctx *pipelines.BuildContext, _ ...cbev1.Options)
return cbev1.Options{}, fmt.Errorf("unknown package type: %s", packageType)
}

log.Info("installing package", "name", name, "version", version)
log.V(1).Info("installing package", "name", name, "version", version)

// download the package
pkgPath, err := s.dl.Download(ctx.Context, airutil.ExpandEnv(resolved))
Expand Down
2 changes: 1 addition & 1 deletion pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (d *Downloader) Download(ctx context.Context, src string) (string, error) {
dst := filepath.Join(d.cacheDir, filepath.Base(uri.Path))
log.V(1).Info("preparing to download file", "dst", dst)

log.Info("downloading file", "src", src, "dst", dst)
log.V(1).Info("downloading file", "src", src, "dst", dst)

client := &getter.Client{
Ctx: ctx,
Expand Down
34 changes: 17 additions & 17 deletions tests/fixtures/alpine_318_full-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"": {
"type": "OCI",
"version": "",
"resolved": "harbor.dcas.dev/docker.io/library/alpine:3.18@sha256:11e21d7b981a59554b3f822c49f6e9f57b6068bb74f49c4cd5cc4c663c7e5160",
"integrity": "sha256:11e21d7b981a59554b3f822c49f6e9f57b6068bb74f49c4cd5cc4c663c7e5160",
"resolved": "harbor.dcas.dev/docker.io/library/alpine:3.18@sha256:1875c923b73448b558132e7d4a44b815d078779ed7a73f76209c6372de95ea8d",
"integrity": "sha256:1875c923b73448b558132e7d4a44b815d078779ed7a73f76209c6372de95ea8d",
"direct": false
},
"binutils": {
Expand All @@ -32,16 +32,16 @@
},
"busybox": {
"type": "Alpine",
"version": "1.36.1-r6",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/busybox-1.36.1-r6.apk",
"integrity": "Q1KNW4neQTQeKuinldJ+uwTCbJUYw=",
"version": "1.36.1-r7",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/busybox-1.36.1-r7.apk",
"integrity": "Q1ierGKl33AY17yZdo8YN+z8NeMPg=",
"direct": false
},
"busybox-binsh": {
"type": "Alpine",
"version": "1.36.1-r6",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/busybox-binsh-1.36.1-r6.apk",
"integrity": "Q1wa39cNs6hgUKJi1R9VK3OzppxMg=",
"version": "1.36.1-r7",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/busybox-binsh-1.36.1-r7.apk",
"integrity": "Q1bChMYpNVeA+TjgHg35IplQm8/Y4=",
"direct": false
},
"ca-certificates": {
Expand Down Expand Up @@ -123,9 +123,9 @@
},
"libcrypto3": {
"type": "Alpine",
"version": "3.1.5-r0",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/libcrypto3-3.1.5-r0.apk",
"integrity": "Q1UOuu4GBUp8YDXrqDCQVawBtJij0=",
"version": "3.1.6-r0",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/libcrypto3-3.1.6-r0.apk",
"integrity": "Q1NqaoieInWRQIGbXme4KArtJ6RGQ=",
"direct": false
},
"libcurl": {
Expand Down Expand Up @@ -172,9 +172,9 @@
},
"libssl3": {
"type": "Alpine",
"version": "3.1.5-r0",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/libssl3-3.1.5-r0.apk",
"integrity": "Q1JeulgUsCMFAHgkHGkl/7+Dq+7OE=",
"version": "3.1.6-r0",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/libssl3-3.1.6-r0.apk",
"integrity": "Q1bIJpgoMXDXSbUq6KZQYVP1bJSBc=",
"direct": false
},
"libstdc++": {
Expand Down Expand Up @@ -256,9 +256,9 @@
},
"ssl_client": {
"type": "Alpine",
"version": "1.36.1-r6",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/ssl_client-1.36.1-r6.apk",
"integrity": "Q1khfMSMr4I/TB71tr+of1zjfXexg=",
"version": "1.36.1-r7",
"resolved": "https://mirror.aarnet.edu.au/pub/alpine/v3.18/main/x86_64/ssl_client-1.36.1-r7.apk",
"integrity": "Q1x4zGPlbjZ/7ZsYMAtZPaGWTob/k=",
"direct": false
},
"zlib": {
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/alpine_318_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ spec:
files:
- uri: https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz?checksum=cf04af86dc085268c5f4470fbae49b18afbc221b78096aab842d934a76bad0ab&archive=false
path: /hello-2.12.tar.gz
links:
- source: /hello-2.12.tar.gz
target: /hello

0 comments on commit 7871cf8

Please sign in to comment.