-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1205 from wilsonehusin/distroless
Use distroless images
- Loading branch information
Showing
13 changed files
with
139 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
Copyright 2021 VMware Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package app | ||
|
||
import ( | ||
"archive/tar" | ||
"compress/gzip" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/vmware-tanzu/sonobuoy/pkg/errlog" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdSplat() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "splat AGGREGATOR_RESULTS_PATH", | ||
Short: "Reads all tarballs in the specified directory and prints the content to STDOUT (for internal use)", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := runSplat(args[0]); err != nil { | ||
errlog.LogError(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
Hidden: true, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
return cmd | ||
} | ||
|
||
func runSplat(dirPath string) error { | ||
sonobuoyResults, err := filepath.Glob(filepath.Join(dirPath, "*.tar.gz")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = loadResults(os.Stdout, sonobuoyResults); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func loadResults(w *os.File, filenames []string) error { | ||
gzipWriter := gzip.NewWriter(w) | ||
defer gzipWriter.Close() | ||
|
||
tarWriter := tar.NewWriter(gzipWriter) | ||
defer tarWriter.Close() | ||
|
||
for _, filename := range filenames { | ||
if err := addFileToTarball(tarWriter, filename); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func addFileToTarball(tarWriter *tar.Writer, filename string) error { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
infoHeader, err := file.Stat() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// archive path of content as basename instead of full path | ||
// so un-archiving will result in the working directory, not AGGREGATOR_RESULTS_PATH | ||
header, err := tar.FileInfoHeader(infoHeader, infoHeader.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = tarWriter.WriteHeader(header); err != nil { | ||
return err | ||
} | ||
|
||
fileContent, err := ioutil.ReadAll(file) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, err := tarWriter.Write(fileContent); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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 |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM golang:1.14-stretch AS base | ||
FROM golang:1.15-buster AS base | ||
WORKDIR /src | ||
|
||
# Handle the go modules first to take advantage of Docker cache. | ||
|
@@ -22,10 +22,10 @@ RUN go mod download | |
|
||
# Get the rest of the files and build. | ||
COPY src . | ||
RUN go build -o /go/bin/testImage ./... | ||
RUN CGO_ENABLED=0 go build -o /go/bin/testImage ./... | ||
|
||
FROM debian:stretch-slim | ||
MAINTAINER John Schnake "[email protected]" | ||
COPY --from=base /go/bin/testImage /bin/testImage | ||
FROM gcr.io/distroless/static-debian10:latest | ||
WORKDIR / | ||
COPY --from=base /go/bin/testImage /testImage | ||
COPY resources /resources | ||
CMD [ "testImage" ] | ||
CMD [ "/testImage" ] |
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
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