1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00

Merge pull request #325 from elopio/snap-plugs-daemon

Allow plugs and daemon in the snaps
This commit is contained in:
Carlos Alexandro Becker 2017-08-04 08:48:23 -03:00 committed by GitHub
commit 6cfc3e3253
3 changed files with 65 additions and 11 deletions

View File

@ -123,12 +123,19 @@ type FPM struct {
XXX map[string]interface{} `yaml:",inline"` XXX map[string]interface{} `yaml:",inline"`
} }
// SnapcraftAppMetadata for the binaries that will be in the snap package
type SnapcraftAppMetadata struct {
Plugs []string
Daemon string
}
// Snapcraft config // Snapcraft config
type Snapcraft struct { type Snapcraft struct {
Summary string `yaml:",omitempty"` Summary string `yaml:",omitempty"`
Description string `yaml:",omitempty"` Description string `yaml:",omitempty"`
Grade string `yaml:",omitempty"` Grade string `yaml:",omitempty"`
Confinement string `yaml:",omitempty"` Confinement string `yaml:",omitempty"`
Apps map[string]SnapcraftAppMetadata `yaml:",omitempty"`
// Capture all undefined fields and should be empty after loading // Capture all undefined fields and should be empty after loading
XXX map[string]interface{} `yaml:",inline"` XXX map[string]interface{} `yaml:",inline"`

View File

@ -28,14 +28,14 @@ type SnapcraftMetadata struct {
Grade string `yaml:",omitempty"` Grade string `yaml:",omitempty"`
Confinement string `yaml:",omitempty"` Confinement string `yaml:",omitempty"`
Architectures []string Architectures []string
Apps map[string]AppsMetadata Apps map[string]AppMetadata
} }
// AppsMetadata for the binaries that will be in the snap package // AppMetadata for the binaries that will be in the snap package
type AppsMetadata struct { type AppMetadata struct {
Command string Command string
// Plugs []string Plugs []string `yaml:",omitempty"`
// Daemon string Daemon string `yaml:",omitempty"`
} }
// Pipe for snapcraft packaging // Pipe for snapcraft packaging
@ -111,14 +111,19 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
Grade: ctx.Config.Snapcraft.Grade, Grade: ctx.Config.Snapcraft.Grade,
Confinement: ctx.Config.Snapcraft.Confinement, Confinement: ctx.Config.Snapcraft.Confinement,
Architectures: []string{arch}, Architectures: []string{arch},
Apps: make(map[string]AppsMetadata), Apps: make(map[string]AppMetadata),
} }
for _, binary := range binaries { for _, binary := range binaries {
log.WithField("path", binary.Path). log.WithField("path", binary.Path).
WithField("name", binary.Name). WithField("name", binary.Name).
Info("passed binary to snapcraft") Info("passed binary to snapcraft")
metadata.Apps[binary.Name] = AppsMetadata{Command: binary.Name} appMetadata := AppMetadata{Command: binary.Name}
if configAppMetadata, ok := ctx.Config.Snapcraft.Apps[binary.Name]; ok {
appMetadata.Plugs = configAppMetadata.Plugs
appMetadata.Daemon = configAppMetadata.Daemon
}
metadata.Apps[binary.Name] = appMetadata
destBinaryPath := filepath.Join(primeDir, filepath.Base(binary.Path)) destBinaryPath := filepath.Join(primeDir, filepath.Base(binary.Path))
if err := os.Link(binary.Path, destBinaryPath); err != nil { if err := os.Link(binary.Path, destBinaryPath); err != nil {

View File

@ -9,6 +9,7 @@ import (
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
yaml "gopkg.in/yaml.v2"
) )
func TestDescription(t *testing.T) { func TestDescription(t *testing.T) {
@ -66,6 +67,47 @@ func TestRunPipe(t *testing.T) {
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(Pipe{}.Run(ctx))
} }
func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(err)
var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755))
assert.NoError(err)
var ctx = &context.Context{
Version: "testversion",
Config: config.Project{
ProjectName: "mybin",
Dist: dist,
Snapcraft: config.Snapcraft{
Summary: "test summary",
Description: "test description",
Apps: map[string]config.SnapcraftAppMetadata{
"mybin": config.SnapcraftAppMetadata{
Plugs: []string{"home", "network"},
Daemon: "simple",
},
},
},
},
}
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64", "linuxarm64", "linuxarmhf"} {
var folder = "mybin_" + plat
assert.NoError(os.Mkdir(filepath.Join(dist, folder), 0755))
var binPath = filepath.Join(dist, folder, "mybin")
_, err = os.Create(binPath)
ctx.AddBinary(plat, folder, "mybin", binPath)
}
assert.NoError(Pipe{}.Run(ctx))
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "mybin_linuxamd64", "prime", "meta", "snap.yaml"))
assert.NoError(err)
var snapcraftMetadata SnapcraftMetadata
err = yaml.Unmarshal(yamlFile, &snapcraftMetadata)
assert.NoError(err)
assert.Equal(snapcraftMetadata.Apps["mybin"].Plugs, []string{"home", "network"})
assert.Equal(snapcraftMetadata.Apps["mybin"].Daemon, "simple")
}
func TestNoSnapcraftInPath(t *testing.T) { func TestNoSnapcraftInPath(t *testing.T) {
var assert = assert.New(t) var assert = assert.New(t)
var path = os.Getenv("PATH") var path = os.Getenv("PATH")