Skip to content

Commit

Permalink
persist multidist flag
Browse files Browse the repository at this point in the history
  • Loading branch information
neolynx committed Oct 7, 2024
1 parent 9093ea3 commit 5d2e78d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
51 changes: 28 additions & 23 deletions api/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,34 @@ func apiPublishList(c *gin.Context) {
c.JSON(200, result)
}

type publishCreateParams struct {
// source kind: local for local repositories and snapshot for snapshots
SourceKind string `binding:"required"`
Sources []struct {
Component string
Name string `binding:"required"`
} `binding:"required"`
Distribution string
Label string
Origin string
NotAutomatic string
ButAutomaticUpgrades string
ForceOverwrite bool
SkipContents *bool
SkipBz2 *bool
Architectures []string
Signing SigningOptions
AcquireByHash *bool
MultiDist bool
}

// @Summary TODO
// @Description **ToDo**
// @Description To Do
// @Tags Publish
// @Param prefix path string true "Publishing prefix, `.` for root"
// @Consume json
// @Param request body publishCreateParams true "Parameters"
// @Produce json
// @Success 200 {object} string "msg"
// @Failure 404 {object} Error "Not Found"
Expand All @@ -96,26 +120,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
param := parseEscapedPath(c.Params.ByName("prefix"))
storage, prefix := deb.ParsePrefix(param)

var b struct {
SourceKind string `binding:"required"`
Sources []struct {
Component string
Name string `binding:"required"`
} `binding:"required"`
Distribution string
Label string
Origin string
NotAutomatic string
ButAutomaticUpgrades string
ForceOverwrite bool
SkipContents *bool
SkipBz2 *bool
Architectures []string
Signing SigningOptions
AcquireByHash *bool
MultiDist bool
}

var b publishCreateParams
if c.Bind(&b) != nil {
return
}
Expand Down Expand Up @@ -189,7 +194,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
return
}

published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory)
published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory, b.MultiDist)
if err != nil {
AbortWithJSONError(c, 500, fmt.Errorf("unable to publish: %s", err))
return
Expand Down Expand Up @@ -239,7 +244,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate)
}

err := published.Publish(context.PackagePool(), context, collectionFactory, signer, publishOutput, b.ForceOverwrite, b.MultiDist)
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, publishOutput, b.ForceOverwrite)
if err != nil {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to publish: %s", err)
}
Expand Down Expand Up @@ -356,7 +361,7 @@ func apiPublishUpdateSwitch(c *gin.Context) {
resources = append(resources, string(published.Key()))
taskName := fmt.Sprintf("Update published %s (%s): %s", published.SourceKind, strings.Join(updatedComponents, " "), strings.Join(updatedSnapshots, ", "))
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite, b.MultiDist)
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite)
if err != nil {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/publish_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
butAutomaticUpgrades := context.Flags().Lookup("butautomaticupgrades").Value.String()
multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool)

published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, collectionFactory)
published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, collectionFactory, multiDist)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
context.Progress().ColoredPrintf("@rWARNING@|: force overwrite mode enabled, aptly might corrupt other published repositories sharing the same package pool.\n")
}

err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist)
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/publish_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
var err error

components := strings.Split(context.Flags().Lookup("component").Value.String(), ",")
multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool)

if len(args) < len(components)+1 || len(args) > len(components)+2 {
cmd.Usage()
Expand Down Expand Up @@ -96,7 +95,7 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
}

err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist)
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/publish_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {

distribution := args[0]
param := "."
multiDist := context.Flags().Lookup("multi-dist").Value.Get().(bool)

if len(args) == 2 {
param = args[1]
Expand Down Expand Up @@ -65,7 +64,7 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
}

err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite, multiDist)
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
Expand Down
12 changes: 7 additions & 5 deletions deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type PublishedRepo struct {
// Provide index files per hash also
AcquireByHash bool

// Provide index files per hash also
MiltiDist bool
// Support multiple distributions
MultiDist bool
}

// ParsePrefix splits [storage:]prefix into components
Expand Down Expand Up @@ -156,13 +156,14 @@ func walkUpTree(source interface{}, collectionFactory *CollectionFactory) (rootD
// distribution and architectures are user-defined properties
// components & sources are lists of component to source mapping (*Snapshot or *LocalRepo)
func NewPublishedRepo(storage, prefix, distribution string, architectures []string,
components []string, sources []interface{}, collectionFactory *CollectionFactory) (*PublishedRepo, error) {
components []string, sources []interface{}, collectionFactory *CollectionFactory, multiDist bool) (*PublishedRepo, error) {
result := &PublishedRepo{
UUID: uuid.New(),
Storage: storage,
Architectures: architectures,
Sources: make(map[string]string),
sourceItems: make(map[string]repoSourceItem),
MultiDist: multiDist,
}

if len(sources) == 0 {
Expand Down Expand Up @@ -318,6 +319,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
"Storage": p.Storage,
"SkipContents": p.SkipContents,
"AcquireByHash": p.AcquireByHash,
"MultiDist": p.MultiDist,
})
}

Expand Down Expand Up @@ -550,7 +552,7 @@ func (p *PublishedRepo) GetCodename() string {

// Publish publishes snapshot (repository) contents, links package files, generates Packages & Release files, signs them
func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageProvider aptly.PublishedStorageProvider,
collectionFactory *CollectionFactory, signer pgp.Signer, progress aptly.Progress, forceOverwrite, multiDist bool) error {
collectionFactory *CollectionFactory, signer pgp.Signer, progress aptly.Progress, forceOverwrite bool) error {
publishedStorage := publishedStorageProvider.GetPublishedStorage(p.Storage)

err := publishedStorage.MkDir(filepath.Join(p.Prefix, "pool"))
Expand Down Expand Up @@ -662,7 +664,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
if err2 != nil {
return err2
}
if multiDist {
if p.MultiDist {
relPath = filepath.Join("pool", p.Distribution, component, poolDir)
} else {
relPath = filepath.Join("pool", component, poolDir)
Expand Down

0 comments on commit 5d2e78d

Please sign in to comment.