Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go run (or go install) skywire without cloning this repo #1908

Open
0pcom opened this issue Nov 14, 2024 · 1 comment
Open

go run (or go install) skywire without cloning this repo #1908

0pcom opened this issue Nov 14, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@0pcom
Copy link
Collaborator

0pcom commented Nov 14, 2024

Demo

If one has golang, git, bash and some other parsing utility (like awk) it's possible to run skywire without cloning the repo in the following way:

[user@linux]$  _commit="$(git ls-remote https://github.com/skycoin/skywire refs/heads/develop | awk '{print $1}')" ; GO111MODULE=on go run -ldflags="-X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v1.3.29 -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit=${_commit} -X github.com/skycoin/skywire/pkg/visor.BuildTag=Linux" github.com/skycoin/skywire/cmd/skycoin-skywire@${_commit}

  ┌─┐┬┌─┬ ┬┬ ┬┬┬─┐┌─┐
  └─┐├┴┐└┬┘││││├┬┘├┤
  └─┘┴ ┴ ┴ └┴┘┴┴└─└─┘

 Available Commands:  
  visor     Skywire Visor  
  skycoin   skycoin daemon, cli, & newcoin  
  cli       Command Line Interface for skywire  
  svc       Skywire services  
  dmsg      DMSG services & utilities  
  app       skywire native applications        

Flags:
  -v, --version   version for skycoin-skywire

[user@linux]$ _commit="$(git ls-remote https://github.com/skycoin/skywire refs/heads/develop | awk '{print $1}')" ; GO111MODULE=on go run -ldflags="-X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v1.3.29 -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit=${_commit} -X github.com/skycoin/skywire/pkg/visor.BuildTag=Linux" github.com/skycoin/skywire/cmd/skycoin-skywire@${_commit} -v
skycoin-skywire version v1.3.29

Known Issues

  • the version must be manually specified. It should be possible to automatically version it
  • dmsghttp-config is not currently supported when running skywire like this, but it could easily be supported (the dmsghttp-config is already embedded in /skywire.go at the repo root)

Suggested Actions

We should include a systemd service (and perhaps a script as well) for running skywire in this way, if it's possible to get the version to be automatically generated & compiled into the binary.

Deployment Strategy

The strategy for running skywire in this way should follow this general outline:

  • generate a conf file for config gen (not a json config for the visor) at /etc/skywire.conf
  • Generate & set secret key there
  • specify that conf file as SKYENV=/etc/skywire.conf on config gen
  • pipe the config from STDOUT of skywire cli to STDIN of the visor (using -n flags)

i.e. - a shorthand example

SKYENV=/ertc/skywire.conf skywire cli config gen -rn | skywire visor -n

Notes

  • a working dir must be specified in the systemd service ; this will contain the local path where the visor will write any files at runtime
  • The json config should be re-generated every time the service starts (it won't be written to disk when using -n flags)

Apps

It may not be possible to run apps unless the binary is compiled and placed in a known location. However, it should be possible to change the app location or command which starts the apps to os.Args[0] in order to use the compilation of skywire which is generated inside /tmp when skywire is executed with go run - in other words, to use the same binary as is already running.

Pros & Cons

Advantages

  • the latest commits on develop will be used every time the visor is started or restarted
  • no repository configuration or packages are needed
  • the same setup (with the exception of the use of a systemd service) should work on all platforms

Disadvantages

  • some issues mentioned above may need to be resolved for skywire to work robustly in this way
  • This setup has not yet been thoroughly tested
  • A recent enough version of golang may not be available for this to work on debian
  • configuration may be less flexible when running in this way
@0pcom 0pcom added the documentation Improvements or additions to documentation label Nov 14, 2024
@0pcom 0pcom changed the title go run skywire without cloning this repo go run (or go install) skywire without cloning this repo Dec 13, 2024
@0pcom
Copy link
Collaborator Author

0pcom commented Dec 14, 2024

Refined approach

it's possible to get the informaton regarding the latest commits to a branch of this repo (for example develop) with go list ; example:

$ go list -m -json github.com/skycoin/skywire@develop
{
	"Path": "github.com/skycoin/skywire",
	"Version": "v1.3.29-rc1.0.20241112234958-c022441efa77",
	"Query": "develop",
	"Time": "2024-11-12T23:49:58Z",
	"Dir": "/home/user/go/pkg/mod/github.com/skycoin/skywire@v1.3.29-rc1.0.20241112234958-c022441efa77",
	"GoMod": "/home/user/go/pkg/mod/cache/download/github.com/skycoin/skywire/@v/v1.3.29-rc1.0.20241112234958-c022441efa77.mod",
	"GoVersion": "1.23",
	"Origin": {
		"VCS": "git",
		"URL": "https://github.com/skycoin/skywire",
		"Hash": "c022441efa773ff738c1566d6a9e138056fa11ba"
	}
}


The above should be executed in a subshell to set a variable at compile time via -ldflags= -X ... - in github.com/skycoin/skywire-utilities/pkg/buildinfo

So, for instance, instead of this compilation command:

go install -ldflags=-X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v1.3.29-rc1-14-gc022441ef -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date=2024-12-14T04:55:18Z -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit=c022441efa773ff738c1566d6a9e138056fa11ba -X github.com/skycoin/skywire/pkg/visor.BuildTag=Linux -mod=vendor  -o ./build/skywire ./cmd/skywire

one might run

go install -ldflags=" -X github.com/skycoin/skywire-utilities/pkg/buildinfo.buildInfo=$(go list -m -json github.com/skycoin/skywire@develop)" github.com/skycoin/skywire/cmd/skycoin-skywire@develop

and there should perhaps be some init function to parse the version and commit out of the json set in that variable at compile time in github.com/skycoin/skywire-utilities/pkg/buildinfo to the separate variables which are already there and already used to print the version from the help menu or setting the version in the config when it's regenerated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant