-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hypotenuse - a tool for extracting the base images out of a Dockerfile.
- Loading branch information
Dan Lorenc
committed
Mar 28, 2021
1 parent
6e30908
commit 8215f2d
Showing
5 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM us-central1-docker.pkg.dev/dlorenc-vmtest2/test/golang:1.16.2 AS builder | ||
|
||
ADD go.mod go.sum $APP_ROOT/src/ | ||
RUN go mod download | ||
|
||
# Add source code | ||
ADD ./ $APP_ROOT/src/ | ||
|
||
RUN go build ./cmd/server | ||
|
||
# Multi-Stage production build | ||
FROM us-central1-docker.pkg.dev/dlorenc-vmtest2/test/distroless as deploy | ||
|
||
# Retrieve the binary from the previous stage | ||
COPY --from=builder /opt/app-root/src/server /usr/local/bin/server | ||
|
||
# Set the binary as the entrypoint of the container | ||
CMD ["server", "serve"] |
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,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/google/go-containerregistry/pkg/authn" | ||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/google/go-containerregistry/pkg/v1/remote" | ||
"github.com/uber/makisu/lib/parser/dockerfile" | ||
) | ||
|
||
func main() { | ||
f := os.Args[1] | ||
c, err := ioutil.ReadFile(f) | ||
if err != nil { | ||
panic(err) | ||
} | ||
stages, err := dockerfile.ParseFile(string(c), nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
stageNames := map[string]struct{}{} | ||
for _, s := range stages { | ||
if s.From.Alias != "" { | ||
stageNames[s.From.Alias] = struct{}{} | ||
} | ||
if _, ok := stageNames[s.From.Image]; ok { | ||
continue | ||
} | ||
ref, err := name.ParseReference(s.From.Image) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
img, err := remote.Image(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
dgst, err := img.Digest() | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(ref.Context().Digest(dgst.String())) | ||
} | ||
} |
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