mirror of
https://github.com/mudler/luet.git
synced 2025-09-07 10:10:17 +00:00
🔧 Allow to specify a snapshot ID #276
This commit is contained in:
@@ -100,6 +100,7 @@ Create a repository from the metadata description defined in the luet.yaml confi
|
|||||||
helpers.CheckErr(err)
|
helpers.CheckErr(err)
|
||||||
force := viper.GetBool("force-push")
|
force := viper.GetBool("force-push")
|
||||||
imagePush := viper.GetBool("push-images")
|
imagePush := viper.GetBool("push-images")
|
||||||
|
snapshotID, _ := cmd.Flags().GetString("snapshot-id")
|
||||||
|
|
||||||
opts := []installer.RepositoryOption{
|
opts := []installer.RepositoryOption{
|
||||||
installer.WithSource(viper.GetString("packages")),
|
installer.WithSource(viper.GetString("packages")),
|
||||||
@@ -163,7 +164,7 @@ Create a repository from the metadata description defined in the luet.yaml confi
|
|||||||
if metaName != "" {
|
if metaName != "" {
|
||||||
metaFile.SetFileName(metaName)
|
metaFile.SetFileName(metaName)
|
||||||
}
|
}
|
||||||
|
repo.SetSnapshotID(snapshotID)
|
||||||
repo.SetRepositoryFile(installer.REPOFILE_TREE_KEY, treeFile)
|
repo.SetRepositoryFile(installer.REPOFILE_TREE_KEY, treeFile)
|
||||||
repo.SetRepositoryFile(installer.REPOFILE_META_KEY, metaFile)
|
repo.SetRepositoryFile(installer.REPOFILE_META_KEY, metaFile)
|
||||||
|
|
||||||
@@ -197,6 +198,7 @@ func init() {
|
|||||||
createrepoCmd.Flags().String("meta-compression", "none", "Compression alg: none, gzip, zstd")
|
createrepoCmd.Flags().String("meta-compression", "none", "Compression alg: none, gzip, zstd")
|
||||||
createrepoCmd.Flags().String("meta-filename", installer.REPOSITORY_METAFILE+".tar", "Repository metadata filename")
|
createrepoCmd.Flags().String("meta-filename", installer.REPOSITORY_METAFILE+".tar", "Repository metadata filename")
|
||||||
createrepoCmd.Flags().Bool("from-repositories", false, "Consume the user-defined repositories to pull specfiles from")
|
createrepoCmd.Flags().Bool("from-repositories", false, "Consume the user-defined repositories to pull specfiles from")
|
||||||
|
createrepoCmd.Flags().String("snapshot-id", "", "Unique ID to use when creating repository snapshots")
|
||||||
|
|
||||||
RootCmd.AddCommand(createrepoCmd)
|
RootCmd.AddCommand(createrepoCmd)
|
||||||
}
|
}
|
||||||
|
@@ -74,7 +74,7 @@ type LuetSystemRepository struct {
|
|||||||
PushImages bool `json:"-"`
|
PushImages bool `json:"-"`
|
||||||
ForcePush bool `json:"-"`
|
ForcePush bool `json:"-"`
|
||||||
|
|
||||||
imagePrefix string
|
imagePrefix, snapshotID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type LuetSystemRepositoryMetadata struct {
|
type LuetSystemRepositoryMetadata struct {
|
||||||
@@ -379,7 +379,7 @@ func (r *LuetSystemRepository) SetPriority(n int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *LuetSystemRepository) initialize(ctx *types.Context, src string) error {
|
func (r *LuetSystemRepository) initialize(ctx *types.Context, src string) error {
|
||||||
generator, err := r.getGenerator(ctx)
|
generator, err := r.getGenerator(ctx, r.snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "while constructing repository generator")
|
return errors.Wrap(err, "while constructing repository generator")
|
||||||
}
|
}
|
||||||
@@ -430,6 +430,11 @@ func (r *LuetSystemRepository) SetType(p string) {
|
|||||||
r.LuetRepository.Type = p
|
r.LuetRepository.Type = p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets snapshot ID
|
||||||
|
func (r *LuetSystemRepository) SetSnapshotID(i string) {
|
||||||
|
r.snapshotID = i
|
||||||
|
}
|
||||||
|
|
||||||
func (r *LuetSystemRepository) GetVerify() bool {
|
func (r *LuetSystemRepository) GetVerify() bool {
|
||||||
return r.LuetRepository.Verify
|
return r.LuetRepository.Verify
|
||||||
}
|
}
|
||||||
@@ -705,11 +710,15 @@ type RepositoryGenerator interface {
|
|||||||
Initialize(string, pkg.PackageDatabase) ([]*artifact.PackageArtifact, error)
|
Initialize(string, pkg.PackageDatabase) ([]*artifact.PackageArtifact, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LuetSystemRepository) getGenerator(ctx *types.Context) (RepositoryGenerator, error) {
|
func (r *LuetSystemRepository) getGenerator(ctx *types.Context, snapshotID string) (RepositoryGenerator, error) {
|
||||||
|
if snapshotID == "" {
|
||||||
|
snapshotID = time.Now().Format("20060102150405")
|
||||||
|
}
|
||||||
|
|
||||||
var rg RepositoryGenerator
|
var rg RepositoryGenerator
|
||||||
switch r.GetType() {
|
switch r.GetType() {
|
||||||
case DiskRepositoryType, HttpRepositoryType:
|
case DiskRepositoryType, HttpRepositoryType:
|
||||||
rg = &localRepositoryGenerator{context: ctx}
|
rg = &localRepositoryGenerator{context: ctx, snapshotID: snapshotID}
|
||||||
case DockerRepositoryType:
|
case DockerRepositoryType:
|
||||||
rg = &dockerRepositoryGenerator{
|
rg = &dockerRepositoryGenerator{
|
||||||
b: r.Backend,
|
b: r.Backend,
|
||||||
@@ -717,6 +726,7 @@ func (r *LuetSystemRepository) getGenerator(ctx *types.Context) (RepositoryGener
|
|||||||
imagePush: r.PushImages,
|
imagePush: r.PushImages,
|
||||||
force: r.ForcePush,
|
force: r.ForcePush,
|
||||||
context: ctx,
|
context: ctx,
|
||||||
|
snapshotID: snapshotID,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("invalid repository type")
|
return nil, errors.New("invalid repository type")
|
||||||
@@ -726,7 +736,7 @@ func (r *LuetSystemRepository) getGenerator(ctx *types.Context) (RepositoryGener
|
|||||||
|
|
||||||
// Write writes the repository metadata to the supplied destination
|
// Write writes the repository metadata to the supplied destination
|
||||||
func (r *LuetSystemRepository) Write(ctx *types.Context, dst string, resetRevision, force bool) error {
|
func (r *LuetSystemRepository) Write(ctx *types.Context, dst string, resetRevision, force bool) error {
|
||||||
rg, err := r.getGenerator(ctx)
|
rg, err := r.getGenerator(ctx, r.snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -37,10 +37,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type dockerRepositoryGenerator struct {
|
type dockerRepositoryGenerator struct {
|
||||||
b compiler.CompilerBackend
|
b compiler.CompilerBackend
|
||||||
imagePrefix string
|
imagePrefix, snapshotID string
|
||||||
imagePush, force bool
|
imagePush, force bool
|
||||||
context *types.Context
|
context *types.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *dockerRepositoryGenerator) Initialize(path string, db pkg.PackageDatabase) ([]*artifact.PackageArtifact, error) {
|
func (l *dockerRepositoryGenerator) Initialize(path string, db pkg.PackageDatabase) ([]*artifact.PackageArtifact, error) {
|
||||||
@@ -270,8 +270,7 @@ func (d *dockerRepositoryGenerator) Generate(r *LuetSystemRepository, imagePrefi
|
|||||||
// Create a named snapshot and push it.
|
// Create a named snapshot and push it.
|
||||||
// It edits the metadata pointing at the repository files associated with the snapshot
|
// It edits the metadata pointing at the repository files associated with the snapshot
|
||||||
// And copies the new files
|
// And copies the new files
|
||||||
id := time.Now().Format("20060102150405")
|
artifacts, snapshotRepoFile, err := r.Snapshot(d.snapshotID, repoTemp)
|
||||||
artifacts, snapshotRepoFile, err := r.Snapshot(id, repoTemp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "while creating snapshot")
|
return errors.Wrap(err, "while creating snapshot")
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,10 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type localRepositoryGenerator struct{ context *types.Context }
|
type localRepositoryGenerator struct {
|
||||||
|
context *types.Context
|
||||||
|
snapshotID string
|
||||||
|
}
|
||||||
|
|
||||||
func (l *localRepositoryGenerator) Initialize(path string, db pkg.PackageDatabase) ([]*artifact.PackageArtifact, error) {
|
func (l *localRepositoryGenerator) Initialize(path string, db pkg.PackageDatabase) ([]*artifact.PackageArtifact, error) {
|
||||||
return buildPackageIndex(l.context, path, db)
|
return buildPackageIndex(l.context, path, db)
|
||||||
@@ -124,7 +127,7 @@ func (g *localRepositoryGenerator) Generate(r *LuetSystemRepository, dst string,
|
|||||||
// Create named snapshot.
|
// Create named snapshot.
|
||||||
// It edits the metadata pointing at the repository files associated with the snapshot
|
// It edits the metadata pointing at the repository files associated with the snapshot
|
||||||
// And copies the new files
|
// And copies the new files
|
||||||
if _, _, err := r.Snapshot(time.Now().Format("20060102150405"), dst); err != nil {
|
if _, _, err := r.Snapshot(g.snapshotID, dst); err != nil {
|
||||||
return errors.Wrap(err, "while creating snapshot")
|
return errors.Wrap(err, "while creating snapshot")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user