-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Builds and loads the unpacker binary into the operator-controller image so we don't need to use the rukpak image. Signed-off-by: dtfranz <dfranz@redhat.com>
- Loading branch information
Showing
8 changed files
with
180 additions
and
15 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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
# Note: This dockerfile does not build the binaries | ||
# required and is intended to be built only with the | ||
# 'make build' or 'make release' targets. | ||
# Stage 1: | ||
FROM gcr.io/distroless/static:debug-nonroot AS builder | ||
|
||
# Stage 2: | ||
FROM gcr.io/distroless/static:nonroot | ||
|
||
# Grab the cp binary so we can cp the unpack | ||
# binary to a shared volume in the bundle image | ||
COPY --from=builder /busybox/cp /cp | ||
|
||
WORKDIR / | ||
|
||
COPY manager manager | ||
COPY unpack unpack | ||
|
||
EXPOSE 8080 | ||
|
||
USER 65532:65532 | ||
|
||
ENTRYPOINT ["/manager"] |
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,121 @@ | ||
package main | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"compress/gzip" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
) | ||
|
||
func main() { | ||
var bundleDir string | ||
var opConVersion bool | ||
|
||
skipRootPaths := sets.NewString( | ||
"/dev", | ||
"/etc", | ||
"/proc", | ||
"/product_name", | ||
"/product_uuid", | ||
"/sys", | ||
"/bin", | ||
) | ||
cmd := &cobra.Command{ | ||
Use: "unpack", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
if opConVersion { | ||
// TODO | ||
//fmt.Println(version.String()) | ||
os.Exit(0) | ||
} | ||
var err error | ||
bundleDir, err = filepath.Abs(bundleDir) | ||
if err != nil { | ||
log.Fatalf("get absolute path of bundle directory %q: %v", bundleDir, err) | ||
} | ||
|
||
bundleFS := os.DirFS(bundleDir) | ||
buf := &bytes.Buffer{} | ||
gzw := gzip.NewWriter(buf) | ||
tw := tar.NewWriter(gzw) | ||
if err := fs.WalkDir(bundleFS, ".", func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if d.Type()&os.ModeSymlink != 0 { | ||
return nil | ||
} | ||
if bundleDir == "/" { | ||
// If bundleDir is the filesystem root, skip some known unrelated directories | ||
fullPath := filepath.Join(bundleDir, path) | ||
if skipRootPaths.Has(fullPath) { | ||
return filepath.SkipDir | ||
} | ||
} | ||
info, err := d.Info() | ||
if err != nil { | ||
return fmt.Errorf("get file info for %q: %v", path, err) | ||
} | ||
|
||
h, err := tar.FileInfoHeader(info, "") | ||
if err != nil { | ||
return fmt.Errorf("build tar file info header for %q: %v", path, err) | ||
} | ||
h.Uid = 0 | ||
h.Gid = 0 | ||
h.Uname = "" | ||
h.Gname = "" | ||
h.Name = path | ||
|
||
if err := tw.WriteHeader(h); err != nil { | ||
return fmt.Errorf("write tar header for %q: %v", path, err) | ||
} | ||
if d.IsDir() { | ||
return nil | ||
} | ||
f, err := bundleFS.Open(path) | ||
if err != nil { | ||
return fmt.Errorf("open file %q: %v", path, err) | ||
} | ||
if _, err := io.Copy(tw, f); err != nil { | ||
return fmt.Errorf("write tar data for %q: %v", path, err) | ||
} | ||
return nil | ||
}); err != nil { | ||
log.Fatalf("generate tar.gz for bundle dir %q: %v", bundleDir, err) | ||
} | ||
if err := tw.Close(); err != nil { | ||
log.Fatal(err) | ||
} | ||
if err := gzw.Close(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
bundleMap := map[string]interface{}{ | ||
"content": buf.Bytes(), | ||
} | ||
enc := json.NewEncoder(os.Stdout) | ||
if err := enc.Encode(bundleMap); err != nil { | ||
log.Fatalf("encode bundle map as JSON: %v", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().StringVar(&bundleDir, "bundle-dir", "", "directory in which the bundle can be found") | ||
cmd.Flags().BoolVar(&opConVersion, "version", false, "displays operator-controller version information") | ||
|
||
if err := cmd.Execute(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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