Skip to content

Commit

Permalink
No longer use build.sh to build binaries (#3328)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Plourde <[email protected]>
  • Loading branch information
Simon Plourde authored Oct 9, 2019
1 parent f001d07 commit d0d9518
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 828 deletions.
45 changes: 0 additions & 45 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,51 +224,6 @@ Once you make a change to any `*.proto` file within the **types** package, you w
Sensu uses [Go modules](https://github.com/golang/go/wiki/Modules) for managing
its dependencies.

## Building

### Docker

The simplest way to the build Sensu is with the `sensu-go-build` image. The
image contains all the required tools to build the agent, backend and sensuctl.

```sh
docker pull sensu/sensu-go-build
docker run -it -e GOOS=darwin -v `pwd`:/go/src/github.com/sensu/sensu-go --entrypoint='/go/src/github.com/sensu/sensu-go/build.sh' sensu/sensu-go-build
```

If you would like to build for different platforms and architectures use GOOS
and GOARCH env variables. See [Optional environment variables](https://golang.org/doc/install/source#environment) for more.

When complete your binaries will be present in the `target` directory.

### Manually

First ensure that you have the required tools installed to build the programs.

* Ensure that you have the Go tools installed and your environment configured.
If not follow the official
[Install the Go tools](https://golang.org/doc/install#install) guide.
* When building the Sensu backend you will need NodeJS and Yarn installed so
that the web UI may be included in the binary. Follow
[Installing Node.js](https://nodejs.org/en/download/package-manager/) and
[Yarn Installation](https://yarnpkg.com/en/docs/install) for installation
instructions for your platform.

Once all the tools are installed you are now ready to use the build script. To
build the Sensu backend, agent and sensuctl, run:

```sh
./build.sh build
```

Each product can built separately, with one of the following:

```sh
./build.sh build_agent
./build.sh build_backend
./build.sh build_cli
```

## Testing

Run test suites:
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@ to get started is with the official Docker image, sensu/sensu.

See the [installation documentation](https://docs.sensu.io/sensu-go/latest/installation/install-sensu/) to get started.

### Building from source

The various components of Sensu Go can be manually built from this repository.
You will first need [Go 1.13.1](https://golang.org/doc/install#install)
installed. Then, you should clone this repository **outside** of the GOPATH
since Sensu Go uses [Go Modules](https://github.com/golang/go/wiki/Modules):
```
$ git clone https://github.com/sensu/sensu-go.git
$ cd sensu-go
```

To compile and then run Sensu Go within a single step:
```
$ go run ./cmd/sensu-agent
$ go run ./cmd/sensu-backend
$ go run ./cmd/sensuctl
```

To build Sensu Go binaries and save them into the `bin/` directory:
```
$ go build -o bin/sensu-agent ./cmd/sensu-agent
$ go build -o bin/sensu-backend ./cmd/sensu-backend
$ go build -o bin/sensuctl ./cmd/sensuctl
```

To build Sensu Go binaries with the version information:
```
# sensu-agent
$ go build -ldflags '-X "github.com/sensu/sensu-go/version.Version=5.14.0" -X "github.com/sensu/sensu-go/version.BuildDate=2019-10-08" -X "github.com/sensu/sensu-go/version.BuildSHA='`git rev-parse HEAD`'"' -o bin/sensu-agent ./cmd/sensu-agent
# sensu-backend
$ go build -ldflags '-X "github.com/sensu/sensu-go/version.Version=5.14.0" -X "github.com/sensu/sensu-go/version.BuildDate=2019-10-08" -X "github.com/sensu/sensu-go/version.BuildSHA='`git rev-parse HEAD`'"' -o bin/sensu-backend ./cmd/sensu-backend
# sensuctl
$ go build -ldflags '-X "github.com/sensu/sensu-go/version.Version=5.14.0" -X "github.com/sensu/sensu-go/version.BuildDate=2019-10-08" -X "github.com/sensu/sensu-go/version.BuildSHA='`git rev-parse HEAD`'"' -o bin/sensuctl ./cmd/sensuctl
```

## Contributing

For guidelines on how to contribute to this project, how to hack on Sensu, and
Expand Down
7 changes: 1 addition & 6 deletions agent/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"fmt"
"io/ioutil"
"path/filepath"

Expand Down Expand Up @@ -77,11 +76,7 @@ func newVersionCommand() *cobra.Command {
Use: "version",
Short: "Show the sensu-agent version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("sensu-agent version %s, build %s, built %s\n",
version.Semver(),
version.BuildSHA,
version.BuildDate,
)
version.Println("sensu-agent")
},
}

Expand Down
4 changes: 2 additions & 2 deletions agent/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestTranslateToEvent(t *testing.T) {
Subscriptions: []string{"default"},
User: "test-user",
LastSeen: time.Now().Unix(),
SensuAgentVersion: "#",
SensuAgentVersion: "",
},
},
},
Expand All @@ -74,7 +74,7 @@ func TestTranslateToEvent(t *testing.T) {
Subscriptions: []string{"default"},
User: "test-user",
LastSeen: time.Now().Unix(),
SensuAgentVersion: "#",
SensuAgentVersion: "",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion backend/apid/actions/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func TestGetVersion(t *testing.T) {
assert.NotEmpty(response)
assert.Equal("foo-version", response.Etcd.Cluster)
assert.Contains(response.Etcd.Server, "3")
assert.Contains(response.SensuBackend, "#")
assert.Contains(response.SensuBackend, "")
}
8 changes: 1 addition & 7 deletions backend/cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cmd

import (
"fmt"

"github.com/sensu/sensu-go/version"
"github.com/spf13/cobra"
)
Expand All @@ -12,11 +10,7 @@ func VersionCommand() *cobra.Command {
Use: "version",
Short: "Show the sensu-backend version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("sensu-backend version %s, build %s, built %s\n",
version.Semver(),
version.BuildSHA,
version.BuildDate,
)
version.Println("sensu-backend")
},
}

Expand Down
5 changes: 0 additions & 5 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ function build_binary([string]$goos, [string]$goarch, [string]$bin, [string]$cmd
$ldflags = $ldflags + " -X $version_pkg.BuildDate=$build_date"
$ldflags = $ldflags + " -X $version_pkg.BuildSHA=$build_sha"

If ($build_type -ne "nightly" -And $build_type -ne "stable") {
$prerelease = &"go" "run" "./version/cmd/version/version.go" "-p" | Out-String
$ldflags = $ldflags + " -X $version_pkg.PreReleaseIdentifier=$prerelease"
}

$main_pkg = "cmd/$cmd_name"

go build -ldflags "$ldflags" -o $outfile "$REPO_PATH/$main_pkg"
Expand Down
Loading

0 comments on commit d0d9518

Please sign in to comment.