Skip to content

Commit

Permalink
Propose the ability to use podman
Browse files Browse the repository at this point in the history
- fix the ldflags to be set in GOFLAGS, so there is no problem by
escaping environment variables
- ldflags "-H" should be set with equal sign `-H=windowsgui` instead of
`-H windowsgui'
- add podman detection
- add podman usage: no need to fix uid with gosu, podman has got an
option named "--userns" to set to "keep-id".
  • Loading branch information
metal3d committed Apr 22, 2021
1 parent aea6085 commit d219030
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docker/base/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/sh
set -e

if [ -n "$use_podman" ]; then
exec $@
fi

if [ -z "$fyne_uid" ] || [ $fyne_uid -eq 0 2>/dev/null ]; then
eval exec $@
exit $?
Expand Down
27 changes: 23 additions & 4 deletions internal/command/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ type Options struct {
Debug bool // Debug if true enable log verbosity
}

// IsPodman returns true if docker is an alias to podman (e.g. via podman-docker).
func IsPodman() bool {
out, err := exec.Command("docker", "info", "-f", "{{.Host.RemoteSocket.Path}}").Output()
if err != nil {
return false
}
// There should be an indication about the remote socket that is commonly named
// like /path/to/podman.sock
return strings.Index(string(out), "podman") > -1
}

// Cmd returns a command to run in a new container for the specified image
func Cmd(image string, vol volume.Volume, opts Options, cmdArgs []string) *exec.Cmd {

Expand All @@ -50,12 +61,17 @@ func Cmd(image string, vol volume.Volume, opts Options, cmdArgs []string) *exec.
args := []string{
"run", "--rm", "-t",
"-w", w, // set workdir
"-v", fmt.Sprintf("%s:%s", vol.WorkDirHost(), vol.WorkDirContainer()), // mount the working dir
"-v", fmt.Sprintf("%s:%s:z", vol.WorkDirHost(), vol.WorkDirContainer()), // mount the working dir
}

if IsPodman() {
log.Info("USE PODMAN")
args = append(args, "--userns", "keep-id", "-e", "use_podman=1")
}

// mount the cache dir if cache is enabled
if opts.CacheEnabled {
args = append(args, "-v", fmt.Sprintf("%s:%s", vol.CacheDirHost(), vol.CacheDirContainer()))
args = append(args, "-v", fmt.Sprintf("%s:%s:z", vol.CacheDirHost(), vol.CacheDirContainer()))
}

// add default env variables
Expand Down Expand Up @@ -137,9 +153,12 @@ func goBuild(ctx Context) error {

// add ldflags to command, if any
if len(ldflags) > 0 {
args = append(args, "-ldflags", fmt.Sprintf("'%s'", strings.Join(ldflags, " ")))
flags := make([]string, len(ldflags))
for i, flag := range ldflags {
flags[i] = fmt.Sprintf("-ldflags=%s", flag)
}
ctx.Env = append(ctx.Env, fmt.Sprintf("GOFLAGS=%s", strings.Join(flags, " ")))
}

// add tags to command, if any
tags := ctx.Tags
if len(tags) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func makeWindowsContext(flags *windowsFlags, args []string) ([]Context, error) {
}

if !flags.Console {
ctx.LdFlags = append(ctx.LdFlags, "-H windowsgui")
ctx.LdFlags = append(ctx.LdFlags, "-H=windowsgui")
}

if flags.DockerImage == "" {
Expand Down
6 changes: 3 additions & 3 deletions internal/command/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_makeWindowsContext(t *testing.T) {
OS: "windows",
Architecture: "amd64",
Env: []string{"GOOS=windows", "GOARCH=amd64", "CC=x86_64-w64-mingw32-gcc"},
LdFlags: []string{"-H windowsgui"},
LdFlags: []string{"-H=windowsgui"},
DockerImage: "fyneio/fyne-cross:base-latest",
},
},
Expand Down Expand Up @@ -95,7 +95,7 @@ func Test_makeWindowsContext(t *testing.T) {
OS: "windows",
Architecture: "amd64",
Env: []string{"GOOS=windows", "GOARCH=amd64", "CC=x86_64-w64-mingw32-gcc"},
LdFlags: []string{"-X main.version=1.2.3", "-H windowsgui"},
LdFlags: []string{"-X main.version=1.2.3", "-H=windowsgui"},
DockerImage: "fyneio/fyne-cross:base-latest",
},
},
Expand All @@ -122,7 +122,7 @@ func Test_makeWindowsContext(t *testing.T) {
OS: "windows",
Architecture: "amd64",
Env: []string{"GOOS=windows", "GOARCH=amd64", "CC=x86_64-w64-mingw32-gcc"},
LdFlags: []string{"-H windowsgui"},
LdFlags: []string{"-H=windowsgui"},
DockerImage: "test",
},
},
Expand Down

0 comments on commit d219030

Please sign in to comment.