mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
Publishing command.
This commit is contained in:
+106
@@ -0,0 +1,106 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/gonuts/commander"
|
||||||
|
"github.com/gonuts/flag"
|
||||||
|
"github.com/smira/aptly/debian"
|
||||||
|
"github.com/smira/aptly/utils"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
if len(args) != 2 {
|
||||||
|
cmd.Usage()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
name := args[0]
|
||||||
|
prefix := args[1]
|
||||||
|
|
||||||
|
snapshotCollection := debian.NewSnapshotCollection(context.database)
|
||||||
|
snapshot, err := snapshotCollection.ByName(name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = snapshotCollection.LoadComplete(snapshot)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var sourceRepo *debian.RemoteRepo
|
||||||
|
|
||||||
|
if snapshot.SourceKind == "repo" && len(snapshot.SourceIDs) == 1 {
|
||||||
|
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
||||||
|
|
||||||
|
sourceRepo, _ = repoCollection.ByUUID(snapshot.SourceIDs[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
component := cmd.Flag.Lookup("component").Value.String()
|
||||||
|
if component == "" {
|
||||||
|
if sourceRepo != nil && len(sourceRepo.Components) == 1 {
|
||||||
|
component = sourceRepo.Components[0]
|
||||||
|
} else {
|
||||||
|
component = "main"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
distribution := cmd.Flag.Lookup("distribution").Value.String()
|
||||||
|
if distribution == "" {
|
||||||
|
if sourceRepo != nil {
|
||||||
|
distribution = sourceRepo.Distribution
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("unable to guess distribution name, please specify explicitly")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var architecturesList []string
|
||||||
|
architectures := cmd.Flag.Lookup("architectures").Value.String()
|
||||||
|
if architectures != "" {
|
||||||
|
architecturesList = strings.Split(architectures, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
signer := &utils.GpgSigner{}
|
||||||
|
signer.SetKey(cmd.Flag.Lookup("gpg-key").Value.String())
|
||||||
|
|
||||||
|
published := debian.NewPublishedRepo(prefix, distribution, component, architecturesList, snapshot)
|
||||||
|
|
||||||
|
packageCollection := debian.NewPackageCollection(context.database)
|
||||||
|
err = published.Publish(context.packageRepository, packageCollection, signer)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCmdPublishSnapshot() *commander.Command {
|
||||||
|
cmd := &commander.Command{
|
||||||
|
Run: aptlyPublishSnapshot,
|
||||||
|
UsageLine: "snapshot",
|
||||||
|
Short: "makes Debian repository out of snapshot",
|
||||||
|
Long: `
|
||||||
|
Publishes snapshot as Debian repository ready to be used by apt tools.
|
||||||
|
|
||||||
|
ex:
|
||||||
|
$ aptly publish snapshot <name> <prefix>
|
||||||
|
`,
|
||||||
|
Flag: *flag.NewFlagSet("aptly-publish-snapshot", flag.ExitOnError),
|
||||||
|
}
|
||||||
|
cmd.Flag.String("distribution", "", "distribution name to publish")
|
||||||
|
cmd.Flag.String("component", "", "component name to publish")
|
||||||
|
cmd.Flag.String("architectures", "", "list of architectures to publish (comma-separated)")
|
||||||
|
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCmdPublish() *commander.Command {
|
||||||
|
return &commander.Command{
|
||||||
|
UsageLine: "publish",
|
||||||
|
Short: "manage published repositories",
|
||||||
|
Subcommands: []*commander.Command{
|
||||||
|
makeCmdPublishSnapshot(),
|
||||||
|
},
|
||||||
|
Flag: *flag.NewFlagSet("aptly-publish", flag.ExitOnError),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,10 +15,16 @@ var cmd *commander.Command
|
|||||||
func init() {
|
func init() {
|
||||||
cmd = &commander.Command{
|
cmd = &commander.Command{
|
||||||
UsageLine: os.Args[0],
|
UsageLine: os.Args[0],
|
||||||
Flag: *flag.NewFlagSet("aptly", flag.ExitOnError),
|
Short: "Debian repository management tool",
|
||||||
|
Long: `
|
||||||
|
aptly allows to create partial and full mirrors of remote
|
||||||
|
repositories, filter them, merge, upgrade individual packages,
|
||||||
|
take snapshots and publish them back as Debian repositories.`,
|
||||||
|
Flag: *flag.NewFlagSet("aptly", flag.ExitOnError),
|
||||||
Subcommands: []*commander.Command{
|
Subcommands: []*commander.Command{
|
||||||
makeCmdMirror(),
|
makeCmdMirror(),
|
||||||
makeCmdSnapshot(),
|
makeCmdSnapshot(),
|
||||||
|
makeCmdPublish(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,18 +41,18 @@ func main() {
|
|||||||
log.Fatalf("%s", err)
|
log.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.downloader = utils.NewDownloader(2)
|
context.downloader = utils.NewDownloader(4)
|
||||||
defer context.downloader.Shutdown()
|
defer context.downloader.Shutdown()
|
||||||
|
|
||||||
// TODO: configure DB dir
|
// TODO: configure DB dir
|
||||||
context.database, err = database.OpenDB("/tmp/aptly/db")
|
context.database, err = database.OpenDB("/var/aptly/db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("can't open database: %s", err)
|
log.Fatalf("can't open database: %s", err)
|
||||||
}
|
}
|
||||||
defer context.database.Close()
|
defer context.database.Close()
|
||||||
|
|
||||||
// TODO:configure pool dir
|
// TODO:configure pool dir
|
||||||
context.packageRepository = debian.NewRepository("/tmp/aptly")
|
context.packageRepository = debian.NewRepository("/var/aptly")
|
||||||
|
|
||||||
err = cmd.Dispatch(os.Args[1:])
|
err = cmd.Dispatch(os.Args[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user