Skip to content

Commit

Permalink
Switch from go-bindata to fileb0x (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi authored Jul 14, 2018
1 parent b0bba7b commit eed6172
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 288 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ This code should only include the CLI user interface and code used to manage loc

The Inertia client package manages all clientside functionality. The client codebase is in `./client/`.

To bootstrap servers, some bash scripting is often involved, but we'd like to avoid shipping bash scripts with our go binary - instead, we use [go-bindata](https://github.com/jteeuwen/go-bindata) to compile shell scripts into our Go executables. If you make changes to the bootstrapping shell scripts in `client/scripts/`, convert them to `Assets` by running:
To bootstrap servers, some bash scripting is often involved, but we'd like to avoid shipping bash scripts with our go binary - instead, we use [fileb0x](https://github.com/UnnoTed/fileb0x) to compile shell scripts into our Go executables. If you make changes to the bootstrapping shell scripts in `client/scripts/`, compile them by running:

```bash
$> make bootstrap
$> make scripts
```

Then use your asset!

```go
shellScriptData, err := Asset("client/scripts/myshellscript.sh")
shellScriptData, err := ReadFile("client/scripts/myshellscript.sh")
if err != nil {
log.Fatal("No asset with that name")
}
Expand Down
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ prod-deps:
# Sets up test dependencies
.PHONY: dev-deps
dev-deps:
go get -u github.com/jteeuwen/go-bindata/...
go get -u github.com/UnnoTed/fileb0x
bash test/docker_deps.sh
bash test/lint_deps.sh

Expand Down Expand Up @@ -131,11 +131,10 @@ daemon:
-t ubclaunchpad/inertia:$(RELEASE) .
docker push ubclaunchpad/inertia:$(RELEASE)

# Recompiles assets. Use whenever a script in client/bootstrap is
# modified.
.PHONY: bootstrap
bootstrap:
go-bindata -o client/internal/compiled.go -pkg internal client/scripts/...
# Recompiles assets. Use whenever a script in client/scripts is modified.
.PHONY: scripts
scripts:
fileb0x b0x.yml

# Install Inertia Web dependencies. Use PACKAGE to install something.
.PHONY: web-deps
Expand Down
25 changes: 25 additions & 0 deletions b0x.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# all folders and files are relative to the path
# where fileb0x was run at!

# package
pkg: internal

# destination
dest: "./client/internal"

# gofmt
fmt: true

# output file
output: "compiled.go"
noprefix: true

# debug mode where the files are read directly from the filesytem
debug: false

# files
custom:
- files:
# everything inside the folder
# type: array of strings
- "./client/scripts/"
14 changes: 7 additions & 7 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ key to your repository to enable continuous deployment.`+"\n")

// DaemonUp brings the daemon up on the remote instance.
func (c *Client) DaemonUp(daemonVersion, host, daemonPort string) error {
scriptBytes, err := internal.Asset("client/scripts/daemon-up.sh")
scriptBytes, err := internal.ReadFile("client/scripts/daemon-up.sh")
if err != nil {
return err
}
Expand All @@ -143,7 +143,7 @@ func (c *Client) DaemonUp(daemonVersion, host, daemonPort string) error {

// DaemonDown brings the daemon down on the remote instance
func (c *Client) DaemonDown() error {
scriptBytes, err := internal.Asset("client/scripts/daemon-down.sh")
scriptBytes, err := internal.ReadFile("client/scripts/daemon-down.sh")
if err != nil {
return err
}
Expand All @@ -158,7 +158,7 @@ func (c *Client) DaemonDown() error {

// InertiaDown removes the inertia/ directory on the remote instance
func (c *Client) InertiaDown() error {
scriptBytes, err := internal.Asset("client/scripts/inertia-down.sh")
scriptBytes, err := internal.ReadFile("client/scripts/inertia-down.sh")
if err != nil {
return err
}
Expand All @@ -173,7 +173,7 @@ func (c *Client) InertiaDown() error {

// installDocker installs docker on a remote vps.
func (c *Client) installDocker(session SSHSession) error {
installDockerSh, err := internal.Asset("client/scripts/docker.sh")
installDockerSh, err := internal.ReadFile("client/scripts/docker.sh")
if err != nil {
return err
}
Expand All @@ -191,7 +191,7 @@ func (c *Client) installDocker(session SSHSession) error {
// keyGen creates a public-private key-pair on the remote vps
// and returns the public key.
func (c *Client) keyGen(session SSHSession) (*bytes.Buffer, error) {
scriptBytes, err := internal.Asset("client/scripts/keygen.sh")
scriptBytes, err := internal.ReadFile("client/scripts/keygen.sh")
if err != nil {
return nil, err
}
Expand All @@ -209,7 +209,7 @@ func (c *Client) keyGen(session SSHSession) (*bytes.Buffer, error) {
// getDaemonAPIToken returns the daemon API token for RESTful access
// to the daemon.
func (c *Client) getDaemonAPIToken(session SSHSession, daemonVersion string) (string, error) {
scriptBytes, err := internal.Asset("client/scripts/token.sh")
scriptBytes, err := internal.ReadFile("client/scripts/token.sh")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (c *Client) Up(gitRemoteURL, buildType string, stream bool) (*http.Response
})
}

// Prune clears Docker assets on this remote.
// Prune clears Docker ReadFiles on this remote.
func (c *Client) Prune() (*http.Response, error) {
return c.post("/prune", nil)
}
Expand Down
Loading

0 comments on commit eed6172

Please sign in to comment.