Skip to content

Commit

Permalink
Bindings feature notification on Windows + fixing bugs when running a…
Browse files Browse the repository at this point in the history
…n image without '/' and prettifying display a bit
  • Loading branch information
FlUxIuS committed Dec 5, 2024
1 parent d223b9e commit fba767b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 107 deletions.
50 changes: 0 additions & 50 deletions .goreleaser.yaml

This file was deleted.

28 changes: 22 additions & 6 deletions go/rfswift/dock/rfdock.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ func DockerRun(containerName string) {
}
defer cli.Close()

if !strings.Contains(dockerObj.imagename, "/") {
if !strings.Contains(dockerObj.imagename, ":") {
// Prepend Config.General.RepoTag if the format is missing
dockerObj.imagename = fmt.Sprintf("%s:%s", dockerObj.repotag, dockerObj.imagename)
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ func DockerPull(imageref string, imagetag string) {
in(2): string Image tag target
*/

if !strings.Contains(imageref, "/") {
if !strings.Contains(imageref, ":") {
// Prepend Config.General.RepoTag if the format is missing
imageref = fmt.Sprintf("%s:%s", dockerObj.repotag, imageref)
}
Expand Down Expand Up @@ -1588,6 +1588,19 @@ func showLoadingIndicator(ctx context.Context, commandFunc func() error, stepNam
func UpdateMountBinding(containerName string, source string, target string, add bool) {
var timeout = 10 // Stop timeout

// Check if the system is Windows
if runtime.GOOS == "windows" {
title := "Unsupported on Windows"
message := `This function is not supported on Windows.
However, you can achieve similar functionality by using the following commands:
- "rfswift commit" to create a new image with a new tag.
- "rfswift remove" to remove the existing container.
- "rfswift run" to run a container with new bindings.`

rfutils.DisplayNotification(title, message, "warning")
os.Exit(1) // Exit since this function is not supported on Windows
}

if source == "" {
source = target
common.PrintWarningMessage(fmt.Sprintf("Source is empty. Defaulting source to target: %s", target))
Expand All @@ -1612,9 +1625,11 @@ func UpdateMountBinding(containerName string, source string, target string, add
common.PrintInfoMessage("Stopping the container...")

// Attempt graceful stop
err = cli.ContainerStop(ctx, containerID, container.StopOptions{Timeout: &timeout})
if err != nil {
if err := showLoadingIndicator(ctx, func() error {
return cli.ContainerStop(ctx, containerID, container.StopOptions{Timeout: &timeout})
}, "Stopping the container..."); err != nil {
common.PrintErrorMessage(fmt.Errorf("Failed to stop the container gracefully: %v", err))
os.Exit(1)
}

// Check if the container is still running
Expand Down Expand Up @@ -1696,8 +1711,9 @@ func UpdateMountBinding(containerName string, source string, target string, add
common.PrintSuccessMessage("config.v2.json updated successfully.")

// Restart the container
common.PrintInfoMessage("Restarting Docker service...")
if err := RestartDockerService(); err != nil {
if err := showLoadingIndicator(ctx, func() error {
return RestartDockerService()
}, "Restarting Docker service..."); err != nil {
common.PrintErrorMessage(fmt.Errorf("failed to restart Docker service: %v", err))
os.Exit(1)
}
Expand Down
8 changes: 6 additions & 2 deletions go/rfswift/rfutils/githutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ func DownloadFile(url, dest string) error {
}

func MakeExecutable(path string) error {
if runtime.GOOS == "windows" {
// No action needed on Windows
return nil
}

// Set executable bit on Unix-like systems
err := os.Chmod(path, 0755)
if err != nil {
return err
Expand Down Expand Up @@ -139,7 +145,6 @@ func VersionCompare(v1, v2 string) int {
return 0
}

// Extract .tar.gz files
func ExtractTarGz(src, destDir string) error {
file, err := os.Open(src)
if err != nil {
Expand Down Expand Up @@ -185,7 +190,6 @@ func ExtractTarGz(src, destDir string) error {
return nil
}

// Extract .zip files
func ExtractZip(src, destDir string) error {
r, err := zip.OpenReader(src)
if err != nil {
Expand Down
49 changes: 0 additions & 49 deletions installing_on_rfswift

This file was deleted.

0 comments on commit fba767b

Please sign in to comment.