@@ -4,20 +4,22 @@ import (
44 "fmt"
55 "os"
66 "path/filepath"
7+ "strconv"
78
89 "github.com/openshift/appliance/pkg/executer"
910 "github.com/pkg/errors"
1011)
1112
12- const (
13- bundleBuildCmd = "podman build -f %s -t %s %s"
14- bundlePushCmd = "podman push --tls-verify=false %s"
15- )
13+ const bundlePushCmd = "podman push --tls-verify=false %s"
1614
1715type BundleConfig struct {
1816 Executer executer.Executer
1917 Port int
2018 ReleaseVersion string
19+ // ImageSetPath is the absolute path to the rendered imageset.yaml used for oc mirror.
20+ ImageSetPath string
21+ // MappingBytes is oc-mirror mapping.txt content (may be nil if not produced).
22+ MappingBytes []byte
2123}
2224
2325type Bundle struct {
@@ -32,14 +34,51 @@ func NewBundle(config BundleConfig) *Bundle {
3234}
3335
3436func (b * Bundle ) Push () error {
35- dockerfilePath , ctx , err := resolveDockerfile ()
37+ if b .ImageSetPath == "" {
38+ return errors .New ("bundle: ImageSetPath is required" )
39+ }
40+ dockerfileSrc , err := readBundleDockerfile ()
3641 if err != nil {
3742 return err
3843 }
3944
45+ stagedir , err := os .MkdirTemp ("" , "appliance-release-bundle-*" )
46+ if err != nil {
47+ return errors .Wrap (err , "create bundle staging dir" )
48+ }
49+ defer os .RemoveAll (stagedir )
50+
51+ dockerfileDest := filepath .Join (stagedir , "Dockerfile.bundle" )
52+ if err := os .WriteFile (dockerfileDest , dockerfileSrc , 0o644 ); err != nil {
53+ return errors .Wrap (err , "write staged Dockerfile.bundle" )
54+ }
55+
56+ imageSetSrc , err := os .ReadFile (b .ImageSetPath )
57+ if err != nil {
58+ return errors .Wrap (err , "read imageset for bundle" )
59+ }
60+ if err := os .WriteFile (filepath .Join (stagedir , "imageset.yaml" ), imageSetSrc , 0o644 ); err != nil {
61+ return errors .Wrap (err , "write staged imageset.yaml" )
62+ }
63+
64+ mapping := b .MappingBytes
65+ if len (mapping ) == 0 {
66+ mapping = []byte ("# mapping.txt was not found under the oc-mirror workspace\n " )
67+ }
68+ if err := os .WriteFile (filepath .Join (stagedir , "mapping.txt" ), mapping , 0o644 ); err != nil {
69+ return errors .Wrap (err , "write staged mapping.txt" )
70+ }
71+
4072 tag := Tag (b .ReleaseVersion )
4173 imageRef := registryImageRef (b .Port , tag )
42- buildCmd := fmt .Sprintf (bundleBuildCmd , dockerfilePath , imageRef , ctx )
74+ bundleVer := b .ReleaseVersion
75+ if bundleVer == "" {
76+ bundleVer = "unknown"
77+ }
78+ buildCmd := fmt .Sprintf (
79+ "podman build --build-arg BUNDLE_VERSION=%s --build-arg BUNDLE_RELEASE=1 -f %s -t %s %s" ,
80+ strconv .Quote (bundleVer ), dockerfileDest , imageRef , stagedir ,
81+ )
4382 if _ , err := b .Executer .Execute (buildCmd ); err != nil {
4483 return errors .Wrap (err , "build release bundle image" )
4584 }
@@ -52,13 +91,40 @@ func (b *Bundle) Push() error {
5291 return nil
5392}
5493
94+ func readBundleDockerfile () ([]byte , error ) {
95+ path , err := bundleDockerfileAbsPath ()
96+ if err != nil {
97+ return nil , err
98+ }
99+ data , err := os .ReadFile (path )
100+ if err != nil {
101+ return nil , errors .Wrap (err , "read bundle Dockerfile.bundle" )
102+ }
103+ return data , nil
104+ }
105+
106+ func bundleDockerfileAbsPath () (string , error ) {
107+ path , _ , err := resolveDockerfile ()
108+ if err != nil {
109+ return "" , err
110+ }
111+ if filepath .IsAbs (path ) {
112+ return path , nil
113+ }
114+ cwd , err := os .Getwd ()
115+ if err != nil {
116+ return "" , err
117+ }
118+ return filepath .Join (cwd , path ), nil
119+ }
120+
55121// registryImageRef is the image reference used for podman build/push against the local registry
56122// during appliance data ISO generation (must stay aligned with oc mirror localhost layout).
57123func registryImageRef (port int , tag string ) string {
58124 return fmt .Sprintf ("127.0.0.1:%d/%s:%s" , port , ImageRepository , tag )
59125}
60126
61- // resolveDockerfile returns paths for podman build: Dockerfile path and build context directory .
127+ // resolveDockerfile returns paths for locating Dockerfile.bundle ( path may be relative to cwd) .
62128func resolveDockerfile () (dockerfilePath , contextDir string , err error ) {
63129 candidates := []struct {
64130 dockerfile string
0 commit comments