1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-17 01:42:37 +02:00

feat: docker - added linker for extra directories

When adding extra files to docker using a hard link it is impossible
to add a directory because only files can be linked hard. For directories
I added a linker that recursively linkes all files in a directory and re-
creates the directory structure in the dist directory.
This commit is contained in:
Sven Loth
2017-12-20 22:08:35 +01:00
parent 4f3ed001da
commit e4da87b262
2 changed files with 116 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/pipeline"
"github.com/stretchr/testify/assert"
"syscall"
)
func killAndRm(t *testing.T) {
@ -236,3 +237,60 @@ func TestDefaultSet(t *testing.T) {
assert.Equal(t, "{{ .Version }}", docker.TagTemplate)
assert.Equal(t, "Dockerfile.foo", docker.Dockerfile)
}
func TestLinkFile(t *testing.T) {
const srcFile = "/tmp/test"
const dstFile = "/tmp/linked"
err := ioutil.WriteFile(srcFile, []byte("foo"), 0644)
if err != nil {
t.Log("Cannot setup test file")
t.Fail()
}
err = link(srcFile, dstFile)
if err != nil {
t.Log("Failed to link: ", err)
t.Fail()
}
if inode(srcFile) != inode(dstFile) {
t.Log("Inodes do not match, destination file is not a link")
t.Fail()
}
// cleanup
os.Remove(srcFile)
os.Remove(dstFile)
}
func TestLinkDirectory(t *testing.T) {
const srcDir = "/tmp/testdir"
const testFile = "test"
const dstDir = "/tmp/linkedDir"
os.Mkdir(srcDir, 0755)
err := ioutil.WriteFile(srcDir+"/"+testFile, []byte("foo"), 0644)
if err != nil {
t.Log("Cannot setup test file")
t.Fail()
}
err = directoryLink(srcDir, dstDir, nil)
if err != nil {
t.Log("Failed to link: ", err)
t.Fail()
}
if inode(srcDir+"/"+testFile) != inode(dstDir+"/"+testFile) {
t.Log("Inodes do not match, destination file is not a link")
t.Fail()
}
// cleanup
os.RemoveAll(srcDir)
os.RemoveAll(dstDir)
}
func inode(file string) uint64 {
fileInfo, err := os.Stat(file)
if err != nil {
return 0
}
stat := fileInfo.Sys().(*syscall.Stat_t)
return stat.Ino
}