Skip to content

Commit

Permalink
feat: Create Updater artifact (#529)
Browse files Browse the repository at this point in the history
* add new binary to everything but windows

* add to windows msi

* add version flag to updater

* build using combined target

* fix manual build

* add license header

* break updater into separate module

* add new module to dependabot

* copy version pkg to new updater internal pkg

To not have a dependency on the root module

* Workaround for securego/gosec#501
  • Loading branch information
BinaryFissionGames authored and StefanKurek committed Aug 4, 2022
1 parent 8a2a3c3 commit 87a9b6a
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ updates:
commit-message:
prefix: "deps"
include: "scope"
- package-ecosystem: "gomod"
directory: "/updater"
schedule:
interval: "weekly"
ignore:
# Opentelemetry updates will be done manually
- dependency-name: "github.com/open-telemetry/opentelemetry-collector*"
- dependency-name: "go.opentelemetry.io/collector/*"
commit-message:
prefix: "deps"
include: "scope"
4 changes: 3 additions & 1 deletion .github/workflows/manual_msi_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ jobs:
args: build --single-target --skip-validate --rm-dist --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Copy Windows Binary
- name: Copy Windows Collector Binary
run: cp dist/collector_windows_amd64_v1/observiq-otel-collector.exe windows/observiq-otel-collector.exe
- name: Copy Windows Updater Binary
run: cp dist/updater_windows_amd64_v1/updater.exe windows/updater.exe
- name: Copy Plugins to MSI Build Directory
run: cp -r release_deps/plugins windows/
- name: Copy Example Config
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ jobs:
args: build --single-target --skip-validate --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Copy Windows Binary
- name: Copy Windows Collector Binary
run: cp dist/collector_windows_amd64_v1/observiq-otel-collector.exe windows/observiq-otel-collector.exe
- name: Copy Windows Updater Binary
run: cp dist/updater_windows_amd64_v1/updater.exe windows/updater.exe
- name: Copy Plugins to MSI Build Directory
run: cp -r release_deps/plugins windows/
- name: Copy Example Config
Expand Down
26 changes: 26 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ builds:
- -X github.com/observiq/observiq-otel-collector/internal/version.gitHash={{ .FullCommit }}
- -X github.com/observiq/observiq-otel-collector/internal/version.date={{ .Date }}
no_unique_dist_dir: false
- id: updater
binary: updater
dir: ./updater/
main: ./cmd/updater
env:
- CGO_ENABLED=0
mod_timestamp: "{{ .CommitTimestamp }}"
goos:
- windows
- linux
- darwin
goarch:
- amd64
- arm64
- arm
ignore:
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
ldflags:
- -s -w
- -X github.com/observiq/observiq-otel-collector/updater/internal/version.version=v{{ .Version }}
- -X github.com/observiq/observiq-otel-collector/updater/internal/version.gitHash={{ .FullCommit }}
- -X github.com/observiq/observiq-otel-collector/updater/internal/version.date={{ .Date }}
no_unique_dist_dir: false

# https://goreleaser.com/customization/archive/
archives:
Expand Down
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,23 @@ CURRENT_TAG := $(shell git tag --sort=v:refname --points-at HEAD | grep -E "v[0-
# Version will be the tag pointing to the current commit, or the previous version tag if there is no such tag
VERSION ?= $(if $(CURRENT_TAG),$(CURRENT_TAG),$(PREVIOUS_TAG))

# Default build target; making this should build for the current os/arch
# Build binaries for current GOOS/GOARCH by default
.DEFAULT_GOAL := build-binaries

# Builds just the collector for current GOOS/GOARCH pair
.PHONY: collector
collector:
go build -ldflags "-s -w -X github.com/observiq/observiq-otel-collector/internal/version.version=$(VERSION)" -o $(OUTDIR)/collector_$(GOOS)_$(GOARCH)$(EXT) ./cmd/collector

# Builds just the updater for current GOOS/GOARCH pair
.PHONY: updater
updater:
cd ./updater/; go build -ldflags "-s -w -X github.com/observiq/observiq-otel-collector/internal/version.version=$(VERSION)" -o ../$(OUTDIR)/updater_$(GOOS)_$(GOARCH)$(EXT) ./cmd/updater

# Builds the updater + collector for current GOOS/GOARCH pair
.PHONY: build-binaries
build-binaries: collector updater

.PHONY: build-all
build-all: build-linux build-darwin build-windows

Expand All @@ -40,27 +52,27 @@ build-windows: build-windows-amd64

.PHONY: build-linux-amd64
build-linux-amd64:
GOOS=linux GOARCH=amd64 $(MAKE) collector
GOOS=linux GOARCH=amd64 $(MAKE) build-binaries -j2

.PHONY: build-linux-arm64
build-linux-arm64:
GOOS=linux GOARCH=arm64 $(MAKE) collector
GOOS=linux GOARCH=arm64 $(MAKE) build-binaries -j2

.PHONY: build-linux-arm
build-linux-arm:
GOOS=linux GOARCH=arm $(MAKE) collector
GOOS=linux GOARCH=arm $(MAKE) build-binaries -j2

.PHONY: build-darwin-amd64
build-darwin-amd64:
GOOS=darwin GOARCH=amd64 $(MAKE) collector
GOOS=darwin GOARCH=amd64 $(MAKE) build-binaries -j2

.PHONY: build-darwin-arm64
build-darwin-arm64:
GOOS=darwin GOARCH=arm64 $(MAKE) collector
GOOS=darwin GOARCH=arm64 $(MAKE) build-binaries -j2

.PHONY: build-windows-amd64
build-windows-amd64:
GOOS=windows GOARCH=amd64 $(MAKE) collector
GOOS=windows GOARCH=amd64 $(MAKE) build-binaries -j2

# tool-related commands
.PHONY: install-tools
Expand Down Expand Up @@ -115,7 +127,8 @@ tidy:

.PHONY: gosec
gosec:
gosec ./...
gosec -exclude-dir updater ./...
cd updater; gosec ./...

# This target performs all checks that CI will do (excluding the build itself)
.PHONY: ci-checks
Expand Down
35 changes: 35 additions & 0 deletions updater/cmd/updater/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright observIQ, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"

"github.com/observiq/observiq-otel-collector/updater/internal/version"
"github.com/spf13/pflag"
)

// Unimplemented
func main() {
var showVersion = pflag.BoolP("version", "v", false, "prints the version of the collector")
pflag.Parse()

if *showVersion {
fmt.Println("observiq-otel-collector updater version", version.Version())
fmt.Println("commit:", version.GitHash())
fmt.Println("built at:", version.Date())
return
}
}
14 changes: 14 additions & 0 deletions updater/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/observiq/observiq-otel-collector/updater

go 1.17

require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
14 changes: 14 additions & 0 deletions updater/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
37 changes: 37 additions & 0 deletions updater/internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright observIQ, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package version

// these will be replaced at link time by make.
var (
version = "latest" // Semantic version, or "latest" by default
gitHash = "unknown" // Commit hash from which this build was generated
date = "unknown" // Date the build was generated
)

// Version returns the version of the collector.
func Version() string {
return version
}

// GitHash returns the githash associated with the collector's version.
func GitHash() string {
return gitHash
}

// Date returns the publish date associated with the collector's version.
func Date() string {
return date
}
27 changes: 27 additions & 0 deletions updater/internal/version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright observIQ, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package version

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestDefaults(t *testing.T) {
require.Equal(t, version, Version())
require.Equal(t, gitHash, GitHash())
require.Equal(t, date, Date())
}
1 change: 1 addition & 0 deletions windows/scripts/build-msi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mkdir -p storage
touch storage/.include

cp "$PROJECT_BASE/dist/collector_windows_amd64.exe" "observiq-otel-collector.exe"
cp "$PROJECT_BASE/dist/updater_windows_amd64.exe" "updater.exe"

vagrant winrm -c \
"cd C:/vagrant; go-msi.exe make -m observiq-otel-collector.msi --version v0.0.1 --arch amd64"
3 changes: 3 additions & 0 deletions windows/wix.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"arguments": "--config "[INSTALLDIR]config.yaml" --logging "[INSTALLDIR]logging.yaml" --manager "[INSTALLDIR]manager.yaml""
}
},
{
"path": "updater.exe"
},
{
"path": "config.yaml",
"never_overwrite": true
Expand Down

0 comments on commit 87a9b6a

Please sign in to comment.