Skip to content

Commit

Permalink
Merge pull request #101 from mysteriumnetwork/version-1.0.44
Browse files Browse the repository at this point in the history
Add Linux support (CLI)
  • Loading branch information
Zensey authored Jan 25, 2024
2 parents 6889bf5 + 182ee69 commit 2710581
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 98 deletions.
70 changes: 52 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ on:
- '*.*.*'

jobs:
release-linux-armd64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19

- name: Install cross-compilation tools
run: |
set -ex
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build
run: |
go build -v -trimpath -ldflags "-s -w" -o bin/myst-launcher-cli-arm64-linux github.com/mysteriumnetwork/myst-launcher/cmd/app-cli
env:
GOARCH: arm64
GOOS: linux
CC: aarch64-linux-gnu-gcc
CGO_ENABLED: 1
CC_FOR_TARGET: gcc-aarch64-linux-gnu

- name: Upload
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
prerelease: true
files: |
bin/myst-launcher-cli-arm64-linux
release-windows-amd64:
runs-on: windows-2019
steps:
Expand All @@ -34,15 +68,15 @@ jobs:
GOARCH: amd64
GOOS: windows

- name: Sign
env:
CODE_SIGNING_PFX: ${{ secrets.WINDOWS_CERTS }}
CODE_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_CERTS_PASSWORD }}
SIGNTOOL: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe"
run: |
Set-Content -Path bundle.txt -Value $env:CODE_SIGNING_PFX
certutil -decode bundle.txt bundle.pfx
& $env:SIGNTOOL sign /fd SHA256 /f bundle.pfx /p "$env:CODE_SIGNING_PFX_PASSWORD" /tr "http://timestamp.digicert.com" /td SHA256 /d "Mysterium Launcher" bin/myst-launcher-amd64.exe
# - name: Sign
# env:
# CODE_SIGNING_PFX: ${{ secrets.WINDOWS_CERTS }}
# CODE_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_CERTS_PASSWORD }}
# SIGNTOOL: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe"
# run: |
# Set-Content -Path bundle.txt -Value $env:CODE_SIGNING_PFX
# certutil -decode bundle.txt bundle.pfx
# & $env:SIGNTOOL sign /fd SHA256 /f bundle.pfx /p "$env:CODE_SIGNING_PFX_PASSWORD" /tr "http://timestamp.digicert.com" /td SHA256 /d "Mysterium Launcher" bin/myst-launcher-amd64.exe

- name: Build
run: |
Expand All @@ -53,15 +87,15 @@ jobs:
candle installer\installer.wxs installer\licenseDialogue.wxs -arch x64 -out installer\
light installer\installer.wixobj installer\licenseDialogue.wixobj -dcl:high -ext WixUIExtension.dll -ext WixUtilExtension.dll -out installer\myst-launcher-x64.msi
- name: Sign
env:
CODE_SIGNING_PFX: ${{ secrets.WINDOWS_CERTS }}
CODE_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_CERTS_PASSWORD }}
SIGNTOOL: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe"
run: |
Set-Content -Path bundle.txt -Value $env:CODE_SIGNING_PFX
certutil -decode bundle.txt bundle.pfx
& $env:SIGNTOOL sign /fd SHA256 /f bundle.pfx /p "$env:CODE_SIGNING_PFX_PASSWORD" /tr "http://timestamp.digicert.com" /td SHA256 /d "Mysterium Launcher" installer/myst-launcher-x64.msi bin/myst-launcher-cli.exe
# - name: Sign
# env:
# CODE_SIGNING_PFX: ${{ secrets.WINDOWS_CERTS }}
# CODE_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_CERTS_PASSWORD }}
# SIGNTOOL: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe"
# run: |
# Set-Content -Path bundle.txt -Value $env:CODE_SIGNING_PFX
# certutil -decode bundle.txt bundle.pfx
# & $env:SIGNTOOL sign /fd SHA256 /f bundle.pfx /p "$env:CODE_SIGNING_PFX_PASSWORD" /tr "http://timestamp.digicert.com" /td SHA256 /d "Mysterium Launcher" installer/myst-launcher-x64.msi bin/myst-launcher-cli.exe

- name: Upload
uses: softprops/action-gh-release@v1
Expand Down
18 changes: 4 additions & 14 deletions app/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ package app
import (
"fmt"

"github.com/mysteriumnetwork/myst-launcher/controller/docker"
"github.com/mysteriumnetwork/myst-launcher/controller/native"
"github.com/mysteriumnetwork/myst-launcher/controller"
"github.com/mysteriumnetwork/myst-launcher/model"
)

type AppState struct {
action chan string

model *model.UIModel //gui.Model
ui model.Gui_

model *model.UIModel //gui.Model
ui model.Gui_
ctrApp model.Controller
}

Expand All @@ -37,14 +34,7 @@ func (s *AppState) StopAppController() {

func (s *AppState) StartAppController() {
setUIController := func() {
var nc model.Controller

switch s.model.Config.Backend {
case "native":
nc = native.NewController()
case "docker":
nc = docker.NewController()
}
nc := controller.NewController(s.model.Config.Backend)
s.setAppController(nc)
go nc.Start()
}
Expand Down
9 changes: 7 additions & 2 deletions controller/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Controller) Start() {
panic(err) // TODO handle gracefully
}
c.mystManager = mystManager
docker := NewDockerRunner(mystManager.GetDockerClient())
docker := NewDockerRunner(mystManager)

c.wg.Add(1)
defer c.setFinished()
Expand Down Expand Up @@ -281,6 +281,11 @@ func (c *Controller) startContainer() {
mdl.Config.InitialState = model_.InitialStateNormalRun
mdl.Config.Save()

ui.ShowNotificationInstalled()
if ui != nil {
ui.ShowNotificationInstalled()
ui.OpenNodeUI()
} else {
c.lg.Println("node installed!")
}
}
}
15 changes: 15 additions & 0 deletions controller/docker/install_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build linux
// +build linux

/**
* Copyright (c) 2021 BlockDev AG
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package docker

func (c *Controller) tryInstallDocker() {
return
}
29 changes: 8 additions & 21 deletions controller/docker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,30 @@
package docker

import (
"context"
"errors"

// "log"
"fmt"
"os"
"os/exec"
"runtime"
"time"

"github.com/docker/docker/client"

"github.com/mysteriumnetwork/myst-launcher/model"
"github.com/mysteriumnetwork/myst-launcher/utils"
)

type DockerRunner struct {
tryStartCount int
dockerAPI *client.Client
myst model.DockerManager
}

func NewDockerRunner(docker *client.Client) *DockerRunner {
func NewDockerRunner(myst model.DockerManager) *DockerRunner {
return &DockerRunner{
tryStartCount: 0,
dockerAPI: docker,
myst: myst,
}
}

func (r *DockerRunner) canPingDocker() bool {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

_, err := r.dockerAPI.Ping(ctx)
return err == nil
}

func (r *DockerRunner) IsRunning() bool {
canPingDocker := r.canPingDocker()
canPingDocker := r.myst.PingDocker()
// defer log.Println("IsRunning >", canPingDocker)

if canPingDocker {
Expand All @@ -58,7 +45,7 @@ func (r *DockerRunner) IsRunningOrTryStart() (bool, bool) {
// fmt.Println("IsRunningOrTryStart >")
// defer fmt.Println("IsRunningOrTryStart >>>")

if !r.canPingDocker() {
if !r.myst.PingDocker() {
r.tryStartCount++

if !r.tryStartDockerDesktop() || r.tryStartCount >= 20 {
Expand Down Expand Up @@ -97,7 +84,7 @@ func (r *DockerRunner) tryStartDockerDesktop() bool {

func startDockerDesktop() error {
var cmd *exec.Cmd
// fmt.Println("Start Docker Desktop>", runtime.GOOS)
fmt.Println("Start Docker Desktop>", runtime.GOOS)

switch runtime.GOOS {
case "windows":
Expand All @@ -109,7 +96,7 @@ func startDockerDesktop() error {
default:
return errors.New("unsupported OS: " + runtime.GOOS)
}
// fmt.Println("Start Docker Desktop>", cmd)
fmt.Println("Start Docker Desktop>", cmd)

if err := cmd.Start(); err != nil {
fmt.Println("err>", err)
Expand Down
21 changes: 21 additions & 0 deletions controller/factory_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build !linux
// +build !linux

package controller

import (
"github.com/mysteriumnetwork/myst-launcher/controller/docker"
"github.com/mysteriumnetwork/myst-launcher/controller/native"
"github.com/mysteriumnetwork/myst-launcher/model"
)

func NewController(n string) model.Controller {
switch n {
case "native":
return native.NewController()
case "docker":
return docker.NewController()
default:
return nil
}
}
18 changes: 18 additions & 0 deletions controller/factory_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build linux
// +build linux

package controller

import (
"github.com/mysteriumnetwork/myst-launcher/controller/native"
"github.com/mysteriumnetwork/myst-launcher/model"
)

func NewController(n string) model.Controller {
switch n {
case "native":
return native.NewController()
default:
return nil
}
}
3 changes: 3 additions & 0 deletions controller/launcher_updates.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !linux
// +build !linux

package controller

import (
Expand Down
14 changes: 7 additions & 7 deletions controller/native/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package native

import (
"context"
"fmt"
"log"
"os"
"path"
Expand All @@ -24,13 +25,13 @@ const (
)

func getAssetName() string {
switch runtime.GOOS {
case "windows":
return "myst_windows_amd64.zip"
case "darwin":
return "myst_darwin_amd64.tar.gz"
os := runtime.GOOS
arch := runtime.GOARCH
f := "tar.gz"
if os == "windows" {
f = "zip"
}
return ""
return fmt.Sprintf("myst_%s_%s.%s", os, arch, f)
}

func (c *Controller) CheckAndUpgradeNodeExe(forceUpgrade bool) bool {
Expand Down Expand Up @@ -164,7 +165,6 @@ var once sync.Once

func tryInstallFirewallRules(ui model.Gui_) {
once.Do(func() {

// check firewall rules
needFirewallSetup := checkFirewallRules()

Expand Down
12 changes: 7 additions & 5 deletions controller/native/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ func (c *Controller) startContainer() {
case model_.InitialStateFirstRunAfterInstall, model_.InitialStateUndefined:
cfg.InitialState = model_.InitialStateNormalRun
cfg.Save()
if ui != nil {
ui.ShowNotificationInstalled()
} else {
c.lg.Println("node installed!")
}

if ui != nil {
ui.ShowNotificationInstalled()
ui.OpenNodeUI()
} else {
c.lg.Println("node installed!")
}
}
}
}
10 changes: 6 additions & 4 deletions controller/native/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (r *NodeRunner) IsRunning() bool {
}

func getNodeProcessName() string {
exe := "myst.exe"
if runtime.GOOS == "darwin" {
exe = "myst"
exe := "myst"
if runtime.GOOS == "windows" {
exe = "myst.exe"
}
return exe
}
Expand Down Expand Up @@ -143,7 +143,9 @@ func (r *NodeRunner) startNode() error {
}

switch runtime.GOOS {
case "windows", "darwin":
case "windows", "darwin", "linux":
log.Println("!startNode", fullExePath, args)

cmd, err := utils.CmdStart(fullExePath, args...)
if err != nil {
log.Println("run node failed:", err)
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/codingsince1985/checksum v1.3.0
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v23.0.1+incompatible
github.com/docker/docker v24.0.7+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand All @@ -32,15 +32,15 @@ require (
github.com/pkg/errors v0.9.1
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/scjalliance/comshim v0.0.0-20230315213746-5e51f40bd3b9
github.com/stretchr/testify v1.8.2
github.com/shirou/gopsutil/v3 v3.23.9 // indirect
github.com/stretchr/testify v1.8.4
github.com/tc-hib/winres v0.1.6
github.com/tryor/gdiplus v0.0.0-20200830101413-c570de9579b3
github.com/tryor/winapi v0.0.0-20200525040926-cd87d62e2f9b
github.com/winlabs/gowin32 v0.0.0-20221003142512-0d265587d3c9
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/image v0.6.0 // indirect
golang.org/x/net v0.8.0
golang.org/x/sys v0.6.0
golang.org/x/image v0.10.0 // indirect
golang.org/x/net v0.17.0
golang.org/x/sys v0.13.0
golang.org/x/time v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect
Expand Down
Loading

0 comments on commit 2710581

Please sign in to comment.