Skip to content

Commit

Permalink
Support for Windows ( whalebrew#29 )
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit ed225df
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Fri Sep 8 10:29:39 2017 +0900

    Fix CI

commit 94a625d
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Fri Sep 8 10:26:49 2017 +0900

    Fix windows installer

commit 0bea8fb
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Fri Sep 8 10:26:20 2017 +0900

    Fix README for Windows installer

commit 237a4a7
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 19:11:19 2017 +0900

    Fix build for Windows

commit bc508d7
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 18:59:16 2017 +0900

    Fix to set API version (moby/moby#32779)

commit 442be2f
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 18:03:01 2017 +0900

    Update README for Windows

commit e83b2ed
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 18:01:01 2017 +0900

    Add installer for Windows

commit 776b931
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 18:00:38 2017 +0900

    Build for Windows

commit bc01aef
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 17:43:43 2017 +0900

    Fix `run.go` for Windows

commit 63b9490
Merge: a72237f 0fea7e2
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 17:43:01 2017 +0900

    Merge tag '0.1.0' of https://github.com/bfirsh/whalebrew into support-windows

commit a72237f
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 17:26:29 2017 +0900

    Fix `ForceInstall` for windows

commit de458d9
Merge: 03d00bf e7d0792
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Thu Sep 7 17:22:41 2017 +0900

    Merge tag '0.0.5' into support-windows

commit 03d00bf
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Tue Feb 14 00:01:52 2017 +0900

    Fix batch file's shebang

commit 21bcf14
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 22:19:25 2017 +0900

    Fix .travis.yml for forked project

commit a0e486c
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 21:59:19 2017 +0900

    Add appveyor.yml

commit fe06f35
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 21:34:46 2017 +0900

    MakePackagePath

commit bc12aa0
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 21:23:31 2017 +0900

    Rewrite test

commit 7453d37
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 20:28:33 2017 +0900

    `path.Join` -> `filepath.Join`

commit 4ded1a2
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 16:53:51 2017 +0900

    LF -> CRLF in batch file

commit 8078165
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 16:34:08 2017 +0900

    Fix edit for Windows

commit 8746496
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 16:15:55 2017 +0900

    Fix run for windows

commit bb652d4
Merge: 8a6d783 e7e6427
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Mon Feb 13 16:08:42 2017 +0900

    Merge v0.0.4

    Merge remote-tracking branch 'origin/master' into support-windows

commit 8a6d783
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Sun Feb 5 21:11:59 2017 +0900

    Support to run and return status code on Windows

commit ce3d298
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Sun Feb 5 20:58:21 2017 +0900

    Revert "syscall -> exec (for working on windows)"

    This reverts commit 276a9cd.

commit ffbdd15
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Sun Feb 5 20:50:08 2017 +0900

    Add batch file support (for working on windows)

commit cdc5a05
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Sun Feb 5 20:34:30 2017 +0900

    Revert "Add batch file support (for working on windows)"

    This reverts commit aba79b0.

commit 10e10a0
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Fri Feb 3 00:53:23 2017 +0900

    Revert "Fix checking args (for working on windows)"

    This reverts commit 926f422.

commit 74db526
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Wed Feb 1 03:14:59 2017 +0900

    Fix default WHALEBREW_INSTALL_PATH (for working on windows)

commit aba79b0
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Wed Feb 1 03:06:00 2017 +0900

    Add batch file support (for working on windows)

commit 926f422
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Wed Feb 1 01:45:51 2017 +0900

    Fix checking args (for working on windows)

commit 276a9cd
Author: 3846masa <3846masahiro+git@gmail.com>
Date:   Wed Feb 1 01:36:56 2017 +0900

    syscall -> exec (for working on windows)
  • Loading branch information
3846masa committed Sep 8, 2017
1 parent cf6c366 commit 2b5145d
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 52 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
language: go
go:
- 1.7

# For forked project
before_install:
- mkdir -p $HOME/gopath/src/github.com/bfirsh/whalebrew
- rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/github.com/bfirsh/whalebrew/
- export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/bfirsh/whalebrew
- cd $HOME/gopath/src/github.com/bfirsh/whalebrew

install:
- go get -t ./...
- go get github.com/golang/lint/golint
Expand All @@ -15,6 +23,7 @@ deploy:
provider: releases
api_key:
secure: PvRBdjIyAzq+x8Sq0lJW+wRqE+kUE6t+FDxIpawmaUWLvJmA5R1n8RiHMniYTQFOE/0I8SaKu6TbzvnlIZBqG9DIvi3o/eu6mJJCh1tXQHCzo+sfbLtm6545svKUtLTzGF4jESWsKE5x43DgjMCboPKuE4Y7iLs6x7/n6qDgOffZyFkJCPEQd595D7O8LTtL3eHuvzXnxzDIcohSbe1z/YN7b/R4SvT04yXVrji5WmEcuueqQiq/z2BaCh8+TUBihApw024ICCWjALgWQF3XBYnWgW6TR8RQzJB+uA16VjWPetFpPiyOGX824fhUU9u9UoEQyJOQ0BvtI3qTP+2m7VWWKnZuLBxQ68H2o3U/qufrnklVXnargem1455Dq0wVXxwYbTANZcHx0rEzIhcQeAwhMiHFKAGQMpEOqvSC0A2m1RbO4K/LjBNLu6Ab+HfIzgdecRP78U79NVPGVX7PZijxPlvhMYk4z+J20kH65yRZUZoRSqmT/AwMlmdOUEbPjqIsBGinfydWspUfUNf85uDsIfONznTd/X148Pj78CPV5mew9zdx4Jjc9FwYmSyO2zUYpsBJfsF5KMgU3E8SQuKj9s0wwvGAAOTcQMufe9U3bJkq/AxwQOq9CiuNAGTpm1NYZFEuRRCyvnVZ/DJiE6hp4Q98koIzI2p0lpRH+/0=
skip_cleanup: true
file:
- "build/whalebrew-Darwin-x86_64"
- "build/whalebrew-Linux-x86_64"
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Docker works well for packaging up development environments, but there are lots
Whalebrew can run almost any CLI tool, but it isn't for everything (e.g. where commands must start instantly). It works particularly well for:

* **Complex dependencies.** For example, a Python app that requires C libraries, specific package versions, and other CLI tools that you don't want to clutter up your machine with.
* **Cross-platform portability.** Package managers tend to be very closely tied to the system they are running on. Whalebrew packages work on any modern version of macOS, Linux, and Windows (coming soon).
* **Cross-platform portability.** Package managers tend to be very closely tied to the system they are running on. Whalebrew packages work on any modern version of macOS, Linux, and Windows.

## Install

Expand All @@ -44,7 +44,13 @@ Next, on macOS and Linux:

curl -L "https://github.com/bfirsh/whalebrew/releases/download/0.1.0/whalebrew-$(uname -s)-$(uname -m)" -o /usr/local/bin/whalebrew; chmod +x /usr/local/bin/whalebrew

Windows support is theoretically possible, but not implemented yet.
on Windows with Command Prompt:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "Set-ExecutionPolicy -Scope CurrentUser Bypass; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/bfirsh/whalebrew/0.1.0/install.ps1'))" && SET "WHALEBREW_INSTALL_PATH=C:\whalebrew" && SET "PATH=%PATH%;%WHALEBREW_INSTALL_PATH%"

on Windows with Powershell:

Set-ExecutionPolicy -Scope CurrentUser AllSigned; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/bfirsh/whalebrew/0.1.0/install.ps1'))

## Usage

Expand Down Expand Up @@ -94,7 +100,7 @@ To upgrade a single package, just pull its image:

Whalebrew is configured with environment variables, which you can either provide at runtime or put in your `~/.bashrc` file (or whatever shell you use).

- `WHALEBREW_INSTALL_PATH`: The directory to install packages in. (default: `/usr/local/bin`)
- `WHALEBREW_INSTALL_PATH`: The directory to install packages in. (default for macOS and Linux: `/usr/local/bin`, default for Windows: `C:\whalebrew`)

## How it works

Expand Down
35 changes: 35 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "{build}"

os: Windows Server 2012 R2

clone_folder: c:\gopath\src\github.com\bfirsh\whalebrew

environment:
GOPATH: c:\gopath

artifacts:
- path: build\*

install:
- set PATH=%GOPATH%\bin;%PATH%
- git submodule update --init --recursive
- go version
- go env
- go get -t ./...
- go get -u github.com/golang/lint/golint
- go get -u github.com/mitchellh/gox

build_script:
- golint ./...
- go test ./...
- ps: script/build-for-windows.ps1

test: off

deploy:
provider: GitHub
auth_token:
secure: ""
artifact: build\whalebrew-Windows-x86_64.exe
on:
appveyor_repo_tag: true
7 changes: 3 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package client

import (
"context"

"github.com/docker/docker/client"
)

// DefaultVersion is the Engine API version used by Whalebrew
const DefaultVersion string = "1.20"

// NewClient returns a Docker client configured for Whalebrew
func NewClient() (*client.Client, error) {
cli, err := client.NewEnvClient()
if err != nil {
return cli, err
}
cli.UpdateClientVersion(DefaultVersion)
cli.NegotiateAPIVersion(context.Background())
return cli, nil
}
31 changes: 28 additions & 3 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"os"
"os/exec"
"path"
"runtime"
"syscall"

"github.com/bfirsh/whalebrew/packages"
Expand Down Expand Up @@ -35,7 +35,11 @@ var editCommand = &cobra.Command{
if !ok {
editor, ok = os.LookupEnv("GIT_EDITOR")
if !ok {
editor = "vi"
if runtime.GOOS == "windows" {
editor = "notepad"
} else {
editor = "vi"
}
}
}

Expand All @@ -46,7 +50,28 @@ var editCommand = &cobra.Command{

editorArgs := []string{
editorPath,
path.Join(pm.InstallPath, pkgName),
pm.MakePackagePath(pkgName),
}

if runtime.GOOS == "windows" {
editorCmd := exec.Command(editorPath, editorArgs[1:]...)
editorCmd.Env = os.Environ()
editorCmd.Stdin = os.Stdin
editorCmd.Stdout = os.Stdout
editorCmd.Stderr = os.Stderr

exitStatus := 1
if err := editorCmd.Run(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
if ws, ok := exitError.Sys().(syscall.WaitStatus); ok {
exitStatus = ws.ExitStatus()
}
}
} else {
ws := editorCmd.ProcessState.Sys().(syscall.WaitStatus)
exitStatus = ws.ExitStatus()
}
os.Exit(exitStatus)
}

return syscall.Exec(editorPath, editorArgs, os.Environ())
Expand Down
3 changes: 1 addition & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/exec"
"path"

"github.com/Songmu/prompter"
"github.com/bfirsh/whalebrew/client"
Expand Down Expand Up @@ -91,7 +90,7 @@ var installCommand = &cobra.Command{
if err != nil {
return err
}
fmt.Printf("🐳 Installed %s to %s\n", imageName, path.Join(pm.InstallPath, pkg.Name))
fmt.Printf("🐳 Installed %s to %s\n", imageName, pm.MakePackagePath(pkg.Name))
return nil
},
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package cmd

import (
"runtime"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func init() {
viper.SetEnvPrefix("whalebrew")
viper.SetDefault("install_path", "/usr/local/bin")
if runtime.GOOS == "windows" {
viper.SetDefault("install_path", "C:\\whalebrew")
}
viper.BindEnv("install_path")
}

Expand Down
27 changes: 27 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
"syscall"

"runtime"

"github.com/bfirsh/whalebrew/packages"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
Expand Down Expand Up @@ -70,11 +72,36 @@ var runCommand = &cobra.Command{
dockerArgs = append(dockerArgs, "-p")
dockerArgs = append(dockerArgs, portmap)
}

for _, network := range pkg.Networks {
dockerArgs = append(dockerArgs, "--net")
dockerArgs = append(dockerArgs, network)
}

if runtime.GOOS == "windows" {
dockerArgs = append(dockerArgs, pkg.Image)
dockerArgs = append(dockerArgs, args[1:]...)

dockerCmd := exec.Command(dockerPath, dockerArgs[1:]...)
dockerCmd.Env = os.Environ()
dockerCmd.Stdin = os.Stdin
dockerCmd.Stdout = os.Stdout
dockerCmd.Stderr = os.Stderr

exitStatus := 1
if err := dockerCmd.Run(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
if ws, ok := exitError.Sys().(syscall.WaitStatus); ok {
exitStatus = ws.ExitStatus()
}
}
} else {
ws := dockerCmd.ProcessState.Sys().(syscall.WaitStatus)
exitStatus = ws.ExitStatus()
}
os.Exit(exitStatus)
}

user, err := user.Current()
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"path"

"github.com/Songmu/prompter"
"github.com/bfirsh/whalebrew/packages"
Expand All @@ -28,7 +27,7 @@ var uninstallCommand = &cobra.Command{
pm := packages.NewPackageManager(viper.GetString("install_path"))
packageName := args[0]

path := path.Join(pm.InstallPath, packageName)
path := pm.MakePackagePath(packageName)

if !prompter.YN(fmt.Sprintf("This will permanently delete '%s'. Are you sure?", path), false) {
return nil
Expand Down
38 changes: 38 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Whalebrew Installer for Windows

try {
$orgErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "Stop"

$VERSION = "0.1.0"
$BINARY_URL = "https://github.com/3846masa/whalebrew/releases/download/$VERSION/whalebrew-Windows-x86_64.exe"
$USER_PATH = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
$WHALEBREW_INSTALL_PATH = [Environment]::GetEnvironmentVariable("WHALEBREW_INSTALL_PATH", [System.EnvironmentVariableTarget]::User)

if ($WHALEBREW_INSTALL_PATH -eq $null -or $WHALEBREW_INSTALL_PATH -eq '') {
$WHALEBREW_INSTALL_PATH = 'C:\whalebrew';
[Environment]::SetEnvironmentVariable("WHALEBREW_INSTALL_PATH", $WHALEBREW_INSTALL_PATH, [System.EnvironmentVariableTarget]::User)
}

if (![System.IO.Directory]::Exists($WHALEBREW_INSTALL_PATH)) {
[System.IO.Directory]::CreateDirectory($WHALEBREW_INSTALL_PATH)
}

if ($($USER_PATH).ToLower().Contains($($WHALEBREW_INSTALL_PATH).ToLower()) -eq $false) {
[Environment]::SetEnvironmentVariable("Path", "$USER_PATH;%WHALEBREW_INSTALL_PATH%", [System.EnvironmentVariableTarget]::User)
}

Write-Output "`nDownloading Whalebrew from : $BINARY_URL"

$WHALEBREW_PATH = Join-Path $WHALEBREW_INSTALL_PATH "whalebrew.exe"
(New-Object System.Net.WebClient).DownloadFile($BINARY_URL, "$WHALEBREW_PATH")

Write-Output "`nInstalled whalebrew to `"$WHALEBREW_PATH`"`n"
}
catch {
$Host.UI.WriteErrorLine("`nFailed to install whalebrew...`n")
Write-Error $error[1]
}
finally {
$ErrorActionPreference = $orgErrorActionPreference
}
Loading

0 comments on commit 2b5145d

Please sign in to comment.