This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): add digest to invocation image on build
resolves #690
- Loading branch information
Michelle Noorali
committed
Apr 5, 2019
1 parent
e40ac08
commit dfd15f8
Showing
8 changed files
with
215 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package digester | ||
|
||
import ( | ||
"golang.org/x/net/context" | ||
|
||
"github.com/docker/docker/client" | ||
"github.com/opencontainers/go-digest" | ||
) | ||
|
||
type Digester struct { | ||
Client client.ImageAPIClient | ||
Image string | ||
Context context.Context | ||
} | ||
|
||
// NewDigester returns a Digester given the args client, image, ctx | ||
// | ||
// ctx is context to use and pass to Docker client | ||
// client allows us to talk to the Docker client | ||
// image is a string identifier of the image we want to compute digest of | ||
func NewDigester(ctx context.Context, client client.ImageAPIClient, image string) *Digester { | ||
return &Digester{ | ||
Client: client, | ||
Image: image, | ||
Context: ctx, | ||
} | ||
} | ||
|
||
// Digest returns the digest of the image tar | ||
func (d *Digester) Digest() (string, error) { | ||
reader, err := d.Client.ImageSave(d.Context, []string{d.Image}) | ||
if err != nil { | ||
return "", err | ||
} | ||
computedDigest, err := digest.Canonical.FromReader(reader) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer reader.Close() | ||
|
||
return computedDigest.String(), nil | ||
} |
Oops, something went wrong.