Skip to content

Commit

Permalink
feat: adds goreleaser (#112)
Browse files Browse the repository at this point in the history
Adds config and GHA for GoReleaser. 
It is configured to build kubectl retina for
[linux,windows,darwin]x[arm64,amd64] on tag.
When a tag is published, it will build the matrix of binaries and create
a GitHub release with a changelog, and attach the binaries as release
artifacts.

See https://github.com/rbtr/retina/releases/tag/v0.0.2 for sample
release.

Fixes #100

Signed-off-by: GitHub <[email protected]>
  • Loading branch information
rbtr authored Mar 21, 2024
1 parent 0b8a44c commit ae4bcde
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 133 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ name: golangci-lint
on:
workflow_dispatch:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
jobs:
golangci:
strategy:
fail-fast: false
matrix:
go-version: ['1.21.x']
go-version: ["1.21.x"]
os: [ubuntu-latest, windows-latest]
name: Lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.55
args: --concurrency 4 --verbose --config=.golangci.yaml --timeout=25m
only-new-issues: true
skip-cache: true
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.55
args: --concurrency 4 --verbose --config=.golangci.yaml --timeout=25m
only-new-issues: true
skip-cache: true
50 changes: 50 additions & 0 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: goreleaser
on:
pull_request:
branches: [main]
push:
tags: ["v*"]
permissions:
contents: write
packages: write
jobs:
build:
name: Build kubectl-retina
if: github.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ">=1.21.0"
- name: Run GoReleaser build
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: build --snapshot --clean
release:
name: Release kubectl-retina
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ">=1.21.0"
- name: Run GoReleaser release
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 3 additions & 33 deletions .github/workflows/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Retina Container Images

on:
pull_request:
branches: [ main ]
branches: [main]

permissions:
contents: read
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build Images
shell: bash
run: |
Expand Down Expand Up @@ -88,42 +88,12 @@ jobs:

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build Images
shell: bash
run: |
set -euo pipefail
echo "TAG=$(make version)" >> $GITHUB_ENV
make retina-operator-image \
IMAGE_NAMESPACE=${{ github.repository }} \
PLATFORM=${{ matrix.platform }}/${{ matrix.arch }}
kubectl-retina-images:
name: Build kubectl-retina Images
runs-on: ubuntu-latest

strategy:
matrix:
platform: ["linux"]
arch: ["amd64", "arm64"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version: ">=1.21.0"
- run: go version

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build Images
shell: bash
run: |
set -euo pipefail
echo "TAG=$(make version)" >> $GITHUB_ENV
make kubectl-retina-image \
make retina-operator-image \
IMAGE_NAMESPACE=${{ github.repository }} \
PLATFORM=${{ matrix.platform }}/${{ matrix.arch }}
34 changes: 0 additions & 34 deletions .github/workflows/release-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,6 @@ jobs:
PLATFORM=${{ matrix.platform }}/${{ matrix.arch }} \
BUILDX_ACTION=--push
kubectl-retina-images:
name: Build kubectl-retina Images
runs-on: ubuntu-latest

strategy:
matrix:
platform: ["linux"]
arch: ["amd64", "arm64"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version: ">=1.21.0"
- run: go version

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Build/Push Images
shell: bash
run: |
set -euo pipefail
echo "TAG=$(make version)" >> $GITHUB_ENV
make kubectl-retina-image \
IMAGE_NAMESPACE=${{ github.repository }} \
PLATFORM=${{ matrix.platform }}/${{ matrix.arch }} \
BUILDX_ACTION=--push
manifests:
name: Generate Manifests
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ hack/tools/bin

#vscode
.vscode/

dist/
38 changes: 38 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy

builds:
- binary: kubectl-retina-{{ .Os }}-{{ .Arch }}
env:
- CGO_ENABLED=0
goarch:
- amd64
- arm64
gcflags:
- -dwarflocationlists=true
goos:
- linux
- windows
- darwin
ldflags:
- -X cli/cmd.Version={{.Version}}
main: cli/main.go

archives:
- format: binary
name_template: "{{ .Binary }}_{{ .Version }}"
wrap_in_directory: false

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
26 changes: 0 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,6 @@ retina-binary: ## build the Retina binary
export CGO_ENABLED=0
go build -v -o $(RETINA_BUILD_DIR)/retina$(EXE_EXT) -gcflags="-dwarflocationlists=true" -ldflags "-X main.version=$(TAG) -X main.applicationInsightsID=$(APP_INSIGHTS_ID)" $(RETINA_DIR)/main.go

all-kubectl-retina: $(addprefix kubectl-retina-linux-,${ALL_ARCH.linux}) $(addprefix kubectl-retina-windows-,${ALL_ARCH.windows}) ## build kubectl plugin for all platforms

kubectl-retina: # build kubectl plugin for current platform
if [ "$(BUILD_LOCALLY)" = "true" ]; then \
$(MAKE) kubectl-retina-binary-$(GOOS)-$(GOARCH); \
else \
$(MAKE) kubectl-retina-$(GOOS)-$(GOARCH); \
fi
cp $(KUBECTL_RETINA_BUILD_DIR)/kubectl-retina-$(GOOS)-$(GOARCH) $(KUBECTL_RETINA_BUILD_DIR)/kubectl-gadget

kubectl-retina-binary-%: ## build kubectl plugin locally.
export CGO_ENABLED=0 && \
export GOOS=$(shell echo $* |cut -f1 -d-) GOARCH=$(shell echo $* |cut -f2 -d-) && \
Expand All @@ -167,21 +157,6 @@ kubectl-retina-binary-%: ## build kubectl plugin locally.
-ldflags "-X github.com/microsoft/retina/cli/cmd.Version=$(TAG)" \
github.com/microsoft/retina/cli

kubectl-retina-%: ## build kubectl plugin
CONTAINER_BUILDER=docker $(MAKE) kubectl-retina-image
# copy the binary from the container image.
mkdir -p output/kubectl-retina
docker run --rm --platform=linux/amd64 \
--user $(shell id -u):$(shell id -g) \
-v $(PWD):/app \
$(IMAGE_REGISTRY)/$(KUBECTL_RETINA_IMAGE):$(RETINA_PLATFORM_TAG) \
sh -c "cp /bin/kubectl-retina /app/output/kubectl-retina/kubectl-gadget && cp /bin/kubectl-retina /app/output/kubectl-retina/kubectl-retina-$(GOOS)-$(GOARCH)"

install-kubectl-retina: kubectl-retina ## install kubectl plugin
chmod +x $(KUBECTL_RETINA_BUILD_DIR)/kubectl-gadget
sudo cp $(KUBECTL_RETINA_BUILD_DIR)/kubectl-gadget /usr/local/bin/kubectl-retina
kubectl retina --help

retina-capture-workload: ## build the Retina capture workload
cd $(CAPTURE_WORKLOAD_DIR) && CGO_ENABLED=0 go build -v -o $(RETINA_BUILD_DIR)/captureworkload$(EXE_EXT) -gcflags="-dwarflocationlists=true" -ldflags "-X main.version=$(TAG)"

Expand All @@ -194,7 +169,6 @@ RETINA_BUILDER_IMAGE = $(IMAGE_NAMESPACE)/retina-builder
RETINA_TOOLS_IMAGE = $(IMAGE_NAMESPACE)/retina-tools
RETINA_IMAGE = $(IMAGE_NAMESPACE)/retina-agent
RETINA_INIT_IMAGE = $(IMAGE_NAMESPACE)/retina-init
KUBECTL_RETINA_IMAGE = $(IMAGE_NAMESPACE)/kubectl-retina
RETINA_OPERATOR_IMAGE = $(IMAGE_NAMESPACE)/retina-operator
RETINA_INTEGRATION_TEST_IMAGE = $(IMAGE_NAMESPACE)/retina-integration-test
RETINA_PROTO_IMAGE = $(IMAGE_NAMESPACE)/retina-proto-gen
Expand Down
20 changes: 0 additions & 20 deletions cli/Dockerfile.kubectl-retina

This file was deleted.

1 change: 1 addition & 0 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package tools
import (
_ "github.com/golang/mock/mockgen"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/goreleaser/goreleaser"
_ "github.com/onsi/ginkgo"
_ "mvdan.cc/gofumpt"
_ "sigs.k8s.io/controller-runtime/tools/setup-envtest"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux
//go:build unix

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Expand Down Expand Up @@ -111,7 +110,6 @@ func (ncp *NetworkCaptureProvider) CaptureNetworkPacket(filter string, duration,
}()

err = captureStartCmd.Start()

if err != nil {
ncp.l.Error("Failed to start tcpdump", zap.Error(err))
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/capture/provider/network_capture_win.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unix

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unix

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

Expand Down

0 comments on commit ae4bcde

Please sign in to comment.