Skip to content

Commit

Permalink
Fix pull actions and tag image for podman
Browse files Browse the repository at this point in the history
- The runner is now globally set
- We prefix the image by "docker.io" in calls. It works with any runner
  (docker, podman, runc...) - it's recommanded by OCI and it avoids
  podman to ask which registry to use.
- If podman is used, the Makefile tags the images with the "docker.io"
  prefix. It could be OK for docker also, but at this time it's enough
  to avoid the image overwrite
  • Loading branch information
metal3d committed Jul 13, 2021
1 parent 44978e2 commit a88ea79
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tag := $(shell date +"%y.%m.%d")
RUNNER := $(shell 2>/dev/null 1>&2 docker version && echo "docker" || echo "podman")
REGISTRY := docker.io
FYNE_CROSS_VERSION := "1.1"


Expand Down Expand Up @@ -32,6 +33,9 @@ windows: base

# build all images for release. Note do not build darwin
build-images: base android freebsd linux windows
ifeq ($(RUNNER),podman)
$(MAKE) podman-tag
endif

# tag the images with the YY.MM.DD suffix
tag-images:
Expand All @@ -51,6 +55,24 @@ tag-images:
# tag windows images
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-windows fyneio/fyne-cross:${FYNE_CROSS_VERSION}-windows-$(tag)

podman-tag:
# tag base images
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-base $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-base
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-base-llvm $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-base-llvm
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-base-freebsd $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-base-freebsd
# tag android images
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-android $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-android
# tag linux images
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-linux-386 $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-linux-386
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-linux-arm $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-linux-arm
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-linux-arm64 $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-linux-arm64
# tag freebsd images
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-freebsd-amd64 $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-freebsd-amd64
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-freebsd-arm64 $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-freebsd-arm64
# tag windows images
@$(RUNNER) tag fyneio/fyne-cross:${FYNE_CROSS_VERSION}-windows $(REGISTRY)/fyneio/fyne-cross:${FYNE_CROSS_VERSION}-windows


# push the latest images
push-latest-images:
@$(RUNNER) push fyneio/fyne-cross:${FYNE_CROSS_VERSION}-base
Expand Down
25 changes: 16 additions & 9 deletions internal/command/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ import (
"github.com/fyne-io/fyne-cross/internal/volume"
)

// IsPodman is set by init() function, and is true if podman is used
var IsPodman bool
var (
// IsPodman is set by init() function, and is true if podman is used
IsPodman bool
// Runner is either "docker" or "podman"
Runner string
)

const (
// fyneBin is the path of the fyne binary into the docker image
fyneBin = "/usr/local/bin/fyne"
// gowindresBin is the path of the gowindres binary into the docker image
gowindresBin = "/usr/local/bin/gowindres"
// registry is the docker registry to use to pull images
registry = "docker.io"
)

// CheckRequirements checks if the docker binary is in PATH
Expand All @@ -41,6 +47,11 @@ func CheckRequirements() error {
func init() {
// Initialise podman detection once
IsPodman = initIsPodman()
if IsPodman {
Runner = "podman"
} else {
Runner = "docker"
}
}

// Options define the options for the docker run command
Expand Down Expand Up @@ -120,17 +131,13 @@ func Cmd(image string, vol volume.Volume, opts Options, cmdArgs []string) *exec.
}

// specify the image to use
args = append(args, image)
args = append(args, registry+"/"+image)

// add the command to execute
args = append(args, cmdArgs...)

// run the command inside the container
c := "docker"
if IsPodman {
c = "podman"
}
cmd := exec.Command(c, args...)
cmd := exec.Command(Runner, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand Down Expand Up @@ -441,7 +448,7 @@ func pullImage(ctx Context) error {
buf := bytes.Buffer{}

// run the command inside the container
cmd := exec.Command("docker", "pull", "docker.io/"+ctx.DockerImage)
cmd := exec.Command(Runner, "pull", registry+"/"+ctx.DockerImage)
cmd.Stdout = &buf
cmd.Stderr = &buf

Expand Down

0 comments on commit a88ea79

Please sign in to comment.