Skip to content

Commit e2fe4f0

Browse files
committed
add persistentImages
1 parent 2206028 commit e2fe4f0

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

cmd/flags.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ var disabledFeaturesHelpMessage = `
184184
Flags with the prefix '--no-' can be used to disable features of the container,
185185
particularly those that mount volumes or specify extra environment variables.
186186
187-
In addition to CLI flags, these features can be disabled via Viper environment variables or configuration file.
187+
In addition to CLI flags, these features can be disabled via Viper environment variables or configuration file.
188188
189-
For example:
189+
For example:
190190
191-
'no-aws' can be set to 'true' in the configuration file, or
191+
'no-aws' can be set to 'true' in the configuration file, or
192192
'OCMC_NO_AWS' can be set to 'TRUE' in the environment to disable AWS CLI mounts and environment.
193193
`
194194

@@ -234,6 +234,10 @@ var disableFeatureFlags = []cliFlag{
234234
name: "no-persistent-histories",
235235
helpMsg: "Disable persistent histories file mounts and environment",
236236
},
237+
{
238+
name: "no-persistent-images",
239+
helpMsg: "Disable local container storage cache mount",
240+
},
237241
{
238242
name: "no-personalizations",
239243
helpMsg: "Disable personalizations file mounts and environment",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package persistentImages
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/openshift/ocm-container/pkg/engine"
8+
"github.com/openshift/ocm-container/pkg/ocm"
9+
)
10+
11+
const (
12+
destDir = "/var/lib/containers/"
13+
sourceDir = "/.cache/ocm-container/images/"
14+
)
15+
16+
type Config struct {
17+
Env map[string]string
18+
Mounts []engine.VolumeMount
19+
}
20+
21+
func New(home string) (*Config, error) {
22+
var err error
23+
24+
config := &Config{}
25+
26+
ocmClient, err := ocm.NewClient()
27+
if err != nil {
28+
return config, err
29+
}
30+
defer ocmClient.Close()
31+
32+
mount := filepath.Join(home, sourceDir)
33+
err = os.MkdirAll(mount, os.ModePerm)
34+
if err != nil {
35+
return config, err
36+
}
37+
38+
config.Mounts = append(config.Mounts, engine.VolumeMount{
39+
Source: mount,
40+
Destination: destDir,
41+
MountOptions: "rw",
42+
})
43+
44+
return config, nil
45+
}

pkg/ocmcontainer/ocmcontainer.go

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/openshift/ocm-container/pkg/featureSet/osdctl"
2121
"github.com/openshift/ocm-container/pkg/featureSet/pagerduty"
2222
"github.com/openshift/ocm-container/pkg/featureSet/persistentHistories"
23+
"github.com/openshift/ocm-container/pkg/featureSet/persistentImages"
2324
personalize "github.com/openshift/ocm-container/pkg/featureSet/personalization"
2425
"github.com/openshift/ocm-container/pkg/featureSet/scratch"
2526
"github.com/openshift/ocm-container/pkg/ocm"
@@ -223,6 +224,15 @@ func New(cmd *cobra.Command, args []string) (*ocmContainer, error) {
223224
}
224225
}
225226

227+
// Persistent container images
228+
if featureEnabled("persistent-images") {
229+
persistentImagesConfig, err := persistentImages.New(home)
230+
if err != nil {
231+
return o, err
232+
}
233+
c.Volumes = append(c.Volumes, persistentImagesConfig.Mounts...)
234+
}
235+
226236
// Personalization
227237
if featureEnabled("personalizations") && viper.GetBool("enable_personalization_mount") {
228238
personalizationDirOrFile := viper.GetString("personalization_file")

0 commit comments

Comments
 (0)