mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-27 13:57:46 +00:00
Command aptly publish repo. #10
This commit is contained in:
@@ -29,6 +29,7 @@ func makeCmdPublish() *commander.Command {
|
|||||||
UsageLine: "publish",
|
UsageLine: "publish",
|
||||||
Short: "manage published repositories",
|
Short: "manage published repositories",
|
||||||
Subcommands: []*commander.Command{
|
Subcommands: []*commander.Command{
|
||||||
|
makeCmdPublishRepo(),
|
||||||
makeCmdPublishSnapshot(),
|
makeCmdPublishSnapshot(),
|
||||||
makeCmdPublishList(),
|
makeCmdPublishList(),
|
||||||
makeCmdPublishDrop(),
|
makeCmdPublishDrop(),
|
||||||
|
|||||||
@@ -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
@@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
|
func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
var err error
|
||||||
if len(args) < 1 || len(args) > 2 {
|
if len(args) < 1 || len(args) > 2 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
@@ -25,20 +25,45 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
|
|||||||
prefix = ""
|
prefix = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(name)
|
var (
|
||||||
if err != nil {
|
source interface{}
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
message string
|
||||||
}
|
)
|
||||||
|
|
||||||
err = context.collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
if cmd.Name() == "snapshot" {
|
||||||
if err != nil {
|
snapshot, err := context.collectionFactory.SnapshotCollection().ByName(name)
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
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()
|
component := cmd.Flag.Lookup("component").Value.String()
|
||||||
distribution := cmd.Flag.Lookup("distribution").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 {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
@@ -71,8 +96,8 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
|
|||||||
prefix += "/"
|
prefix += "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
context.progress.Printf("\nSnapshot %s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
|
context.progress.Printf("\n%s has been successfully published.\nPlease setup your webserver to serve directory '%s' with autoindexing.\n",
|
||||||
snapshot.Name, context.publishedStorage.PublicPath())
|
message, context.publishedStorage.PublicPath())
|
||||||
context.progress.Printf("Now you can add following line to apt sources:\n")
|
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)
|
context.progress.Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, component)
|
||||||
if utils.StrSliceHasItem(published.Architectures, "source") {
|
if utils.StrSliceHasItem(published.Architectures, "source") {
|
||||||
@@ -86,11 +111,11 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
func makeCmdPublishSnapshot() *commander.Command {
|
func makeCmdPublishSnapshot() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyPublishSnapshot,
|
Run: aptlyPublishSnapshotOrRepo,
|
||||||
UsageLine: "snapshot <name> [<prefix>]",
|
UsageLine: "snapshot <name> [<prefix>]",
|
||||||
Short: "publish snapshot",
|
Short: "publish snapshot",
|
||||||
Long: `
|
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.
|
by apt tools. Published repostiories appear under rootDir/public directory.
|
||||||
Valid GPG key is required for publishing.
|
Valid GPG key is required for publishing.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user