Command aptly publish repo. #10

This commit is contained in:
Andrey Smirnov
2014-03-25 18:42:56 +04:00
parent 1a88876e63
commit 37ea845fd9
3 changed files with 76 additions and 13 deletions
+1
View File
@@ -29,6 +29,7 @@ func makeCmdPublish() *commander.Command {
UsageLine: "publish",
Short: "manage published repositories",
Subcommands: []*commander.Command{
makeCmdPublishRepo(),
makeCmdPublishSnapshot(),
makeCmdPublishList(),
makeCmdPublishDrop(),
+37
View File
@@ -0,0 +1,37 @@
package cmd
import (
"github.com/gonuts/commander"
"github.com/gonuts/flag"
)
func makeCmdPublishRepo() *commander.Command {
cmd := &commander.Command{
Run: aptlyPublishSnapshotOrRepo,
UsageLine: "repo <name> [<prefix>]",
Short: "publish local repository",
Long: `
Command publishes current state of local repository ready to be consumed
by apt tools. Published repostiories appear under rootDir/public directory.
Valid GPG key is required for publishing.
It is not recommended to publish local repositories directly unless the
repository is for testing purposes and changes happen frequently. For
production usage please take snapshot of repository and publish it
using publish snapshot command.
Example:
$ aptly publish repo testing
`,
Flag: *flag.NewFlagSet("aptly-publish-repo", flag.ExitOnError),
}
cmd.Flag.String("distribution", "", "distribution name to publish")
cmd.Flag.String("component", "", "component name to publish")
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
cmd.Flag.String("keyring", "", "GPG keyring to use (instead of default)")
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
return cmd
}
+38 -13
View File
@@ -9,7 +9,7 @@ import (
"strings"
)
func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
var err error
if len(args) < 1 || len(args) > 2 {
cmd.Usage()
@@ -25,20 +25,45 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
prefix = ""
}
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(name)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
var (
source interface{}
message string
)
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
if cmd.Name() == "snapshot" {
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(name)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
source = snapshot
message = fmt.Sprintf("Snapshot %s", snapshot.Name)
} else if cmd.Name() == "repo" {
localRepo, err := context.collectionFactory.LocalRepoCollection().ByName(name)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
err = context.collectionFactory.LocalRepoCollection().LoadComplete(localRepo)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
source = localRepo
message = fmt.Sprintf("Local repo %s", localRepo.Name)
} else {
panic("unknown command")
}
component := cmd.Flag.Lookup("component").Value.String()
distribution := cmd.Flag.Lookup("distribution").Value.String()
published, err := debian.NewPublishedRepo(prefix, distribution, component, context.architecturesList, snapshot, context.collectionFactory)
published, err := debian.NewPublishedRepo(prefix, distribution, component, context.architecturesList, source, context.collectionFactory)
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
@@ -71,8 +96,8 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
prefix += "/"
}
context.progress.Printf("\nSnapshot %s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
snapshot.Name, context.publishedStorage.PublicPath())
context.progress.Printf("\n%s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
message, context.publishedStorage.PublicPath())
context.progress.Printf("Now you can add following line to apt sources:\n")
context.progress.Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, component)
if utils.StrSliceHasItem(published.Architectures, "source") {
@@ -86,11 +111,11 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
func makeCmdPublishSnapshot() *commander.Command {
cmd := &commander.Command{
Run: aptlyPublishSnapshot,
Run: aptlyPublishSnapshotOrRepo,
UsageLine: "snapshot <name> [<prefix>]",
Short: "publish snapshot",
Long: `
Command publish publishes snapshot as Debian repository ready to be consumed
Command publishes snapshot as Debian repository ready to be consumed
by apt tools. Published repostiories appear under rootDir/public directory.
Valid GPG key is required for publishing.