Allow to customize Origin/Label during publishing. #29

This commit is contained in:
Andrey Smirnov
2014-04-15 11:47:21 +04:00
parent 108dc235a7
commit b85f46547b
12 changed files with 118 additions and 4 deletions

View File

@@ -32,6 +32,8 @@ Example:
cmd.Flag.Var(&keyRingsFlag{}, "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")
cmd.Flag.String("origin", "", "origin name to publish")
cmd.Flag.String("label", "", "label to publish")
return cmd
}

View File

@@ -69,6 +69,8 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
if err != nil {
return fmt.Errorf("unable to publish: %s", err)
}
published.Origin = cmd.Flag.Lookup("origin").Value.String()
published.Label = cmd.Flag.Lookup("label").Value.String()
duplicate := context.CollectionFactory().PublishedRepoCollection().CheckDuplicate(published)
if duplicate != nil {
@@ -133,6 +135,8 @@ Example:
cmd.Flag.Var(&keyRingsFlag{}, "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")
cmd.Flag.String("origin", "", "origin name to publish")
cmd.Flag.String("label", "", "label to publish")
return cmd
}

View File

@@ -25,6 +25,8 @@ type PublishedRepo struct {
Prefix string
Distribution string
Component string
Origin string
Label string
// Architectures is a list of all architectures published
Architectures []string
// SourceKind is "local"/"repo"
@@ -173,7 +175,17 @@ func (p *PublishedRepo) String() string {
panic("no snapshot/localRepo")
}
return fmt.Sprintf("%s/%s (%s) [%s] publishes %s", p.Prefix, p.Distribution, p.Component, strings.Join(p.Architectures, ", "), source)
var extra string
if p.Origin != "" {
extra += fmt.Sprintf(", origin: %s", p.Origin)
}
if p.Label != "" {
extra += fmt.Sprintf(", label: %s", p.Label)
}
return fmt.Sprintf("%s/%s (%s%s) [%s] publishes %s", p.Prefix, p.Distribution, p.Component, extra, strings.Join(p.Architectures, ", "), source)
}
// Key returns unique key identifying PublishedRepo
@@ -367,8 +379,16 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorage
}
release := make(Stanza)
release["Origin"] = p.Prefix + " " + p.Distribution
release["Label"] = p.Prefix + " " + p.Distribution
if p.Origin == "" {
release["Origin"] = p.Prefix + " " + p.Distribution
} else {
release["Origin"] = p.Origin
}
if p.Label == "" {
release["Label"] = p.Prefix + " " + p.Distribution
} else {
release["Label"] = p.Label
}
release["Codename"] = p.Distribution
release["Date"] = time.Now().UTC().Format("Mon, 2 Jan 2006 15:04:05 MST")
release["Components"] = p.Component

View File

@@ -274,6 +274,12 @@ func (s *PublishedRepoSuite) TestString(c *C) {
repo, _ = NewPublishedRepo("", "squeeze", "main", []string{"i386", "amd64"}, s.snapshot, s.factory)
c.Check(repo.String(), Equals,
"./squeeze (main) [i386, amd64] publishes [snap]: Snapshot from mirror [yandex]: http://mirror.yandex.ru/debian/ squeeze")
repo.Origin = "myorigin"
c.Check(repo.String(), Equals,
"./squeeze (main, origin: myorigin) [i386, amd64] publishes [snap]: Snapshot from mirror [yandex]: http://mirror.yandex.ru/debian/ squeeze")
repo.Label = "mylabel"
c.Check(repo.String(), Equals,
"./squeeze (main, origin: myorigin, label: mylabel) [i386, amd64] publishes [snap]: Snapshot from mirror [yandex]: http://mirror.yandex.ru/debian/ squeeze")
}
func (s *PublishedRepoSuite) TestKey(c *C) {

View File

@@ -1,3 +1,5 @@
Published repositories:
* ./maverick (main) [amd64, i386] publishes [snap1]: Snapshot from mirror [gnuplot-maverick]: http://ppa.launchpad.net/gladky-anton/gnuplot/ubuntu/ maverick
* ppa/smira/wheezy (contrib) [amd64] publishes [snap2]: Merged from sources: 'snap1'
* ppa/tr1/maverick (main, origin: origin1) [amd64, i386] publishes [snap2]: Merged from sources: 'snap1'
* ppa/tr2/maverick (main, label: label1) [amd64, i386] publishes [snap2]: Merged from sources: 'snap1'

View File

@@ -0,0 +1,13 @@
Loading packages...
Generating metadata files and linking package files...
Signing file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
Clearsigning file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
Local repo local-repo has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ maverick contrib
deb-src http://your-server/ maverick contrib
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -0,0 +1,9 @@
Origin: . maverick
Label: label15
Codename: maverick
Architectures: i386
Components: contrib
Description: Generated by aptly
MD5Sum:
SHA1:
SHA256:

View File

@@ -0,0 +1,12 @@
Loading packages...
Generating metadata files and linking package files...
Signing file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Clearsigning file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Snapshot snap24 has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ squeeze main
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -0,0 +1,9 @@
Origin: aptly24
Label: . squeeze
Codename: squeeze
Architectures: amd64 i386
Components: main
Description: Generated by aptly
MD5Sum:
SHA1:
SHA256:

View File

@@ -10,7 +10,7 @@ class PublishList1Test(BaseTest):
class PublishList2Test(BaseTest):
"""
publish list: several snapshots list
publish list: several repos list
"""
fixtureDB = True
fixturePool = True
@@ -19,5 +19,7 @@ class PublishList2Test(BaseTest):
"aptly snapshot merge snap2 snap1",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap1",
"aptly -architectures=amd64 publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=wheezy -component=contrib snap2 ppa/smira",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -origin=origin1 snap2 ppa/tr1",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -label=label1 snap2 ppa/tr2",
]
runCmd = "aptly publish list"

View File

@@ -340,3 +340,19 @@ class PublishRepo14Test(BaseTest):
self.check_exists('public/pool/contrib/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb')
class PublishRepo15Test(BaseTest):
"""
publish repo: custom label
"""
fixtureCmds = [
"aptly repo create local-repo",
"aptly repo add local-repo ${files}",
]
runCmd = "aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick -component=contrib -label=label15 local-repo"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishRepo15Test, self).check()
# verify contents except of sums
self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor)

View File

@@ -556,3 +556,22 @@ class PublishSnapshot23Test(BaseTest):
]
runCmd = "aptly publish snapshot -skip-signing snap3"
gold_processor = BaseTest.expand_environ
class PublishSnapshot24Test(BaseTest):
"""
publish snapshot: custom origin
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap24 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze -origin=aptly24 snap24"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot24Test, self).check()
# verify contents except of sums
self.check_file_contents('public/dists/squeeze/Release', 'release', match_prepare=strip_processor)