Skip to content

Commit

Permalink
Add goreleaser
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <[email protected]>
  • Loading branch information
kakkoyun committed Sep 27, 2021
1 parent 603ac63 commit bcefba1
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 4 deletions.
47 changes: 46 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,71 @@ on:
branches: [ main ]

jobs:
goreleaser:
name: Goreleaer Dry
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Install llvm
run: sudo apt-get install llvm libelf-dev

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Initialize and update libbpf submodule
run: git submodule init && git submodule update

- name: Configure git for private modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://parca:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Build eBPF
run: make bpf

- name: Set Env
run: echo "BPF_OUT=$(pwd)/dist" >> $GITHUB_ENV

- name: Dry Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist --skip-validate --skip-publish
env:
# BPF_OUT: ${{ env.GITHUB_WORKSPACE }}/dist
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

container:
name: Container build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Initialize and update libbpf submodule
run: git submodule init && git submodule update

- name: Get branch name
shell: bash
run: echo "GITHUB_BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV

- name: Build container
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: make container

- name: Login to registry
if: ${{ github.event_name != 'pull_request' }}
run: |
echo "${{ secrets.QUAY_PASSWORD }}" | buildah login -u "${{ secrets.QUAY_USERNAME }}" --password-stdin quay.io
- name: Push container
if: ${{ github.event_name != 'pull_request' }}
run: |
Expand All @@ -35,7 +81,6 @@ jobs:
name: Go Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,46 @@ permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Install llvm
run: sudo apt-get install llvm libelf-dev

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Initialize and update libbpf submodule
run: git submodule init && git submodule update

- name: Configure git for private modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://parca:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Build eBPF
run: make bpf

- name: Set Env
run: echo "BPF_OUT=$(pwd)/dist" >> $GITHUB_ENV

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
# BPF_OUT: ${{ env.GITHUB_WORKSPACE }}/dist
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

container:
name: Container build and release
runs-on: ubuntu-latest
Expand Down
40 changes: 40 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
before:
hooks:
- go mod tidy
env:
- CGO_CFLAGS=-I{{ .Env.BPF_OUT }}/libbpf/usr/include
- CGO_LDFLAGS={{ .Env.BPF_OUT }}/libbpf/libbpf.a
builds:
- main: ./cmd/parca-agent/
id: "parca-agent"
binary: parca-agent
env:
- CGO_ENABLED=1
- CC=clang
goos:
- linux
goarch:
- amd64
hooks:
pre:
- make clean
- make bpf
flags:
- -trimpath
- -v
ldflags:
- main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`
archives:
- replacements:
linux: Linux
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bpf: $(OUT_BPF)

linux_arch := $(ARCH:x86_64=x86)
ifndef DOCKER
$(OUT_BPF): $(BPF_SRC) $(LIBBPF_HEADERS) | $(OUT_DIR) $(bpf_compile_tools)
$(OUT_BPF): $(BPF_SRC) $(LIBBPF_HEADERS) $(LIBBPF_OBJ) | $(OUT_DIR) $(bpf_compile_tools)
mkdir -p pkg/agent
@v=$$($(CMD_CLANG) --version); test $$(echo $${v#*version} | head -n1 | cut -d '.' -f1) -ge '9' || (echo 'required minimum clang version: 9' ; false)
$(CMD_CLANG) -S \
Expand Down
19 changes: 17 additions & 2 deletions cmd/parca-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ import (
parcadebuginfo "github.com/parca-dev/parca/pkg/debuginfo"
)

var (
version string
commit string
date string
builtBy string
)

type flags struct {
LogLevel string `kong:"enum='error,warn,info,debug',help='Log level.',default='info'"`
HttpAddress string `kong:"help='Address to bind HTTP server to.',default=':7071'"`
Expand All @@ -68,10 +75,18 @@ func main() {
flags := flags{}
kong.Parse(&flags)

node := flags.Node
logger := logger.NewLogger(flags.LogLevel, logger.LogFormatLogfmt, "")

node := flags.Node
logger.Log("msg", "starting...", "node", node, "store", flags.StoreAddress)
level.Debug(logger).Log("msg", "configuration", "bearertoken", flags.BearerToken, "insecure", flags.Insecure, "podselector", flags.PodLabelSelector, "samplingratio", flags.SamplingRatio)
level.Debug(logger).Log("msg", "parca-agent initialized",
"version", version,
"commit", commit,
"date", date,
"builtBy", builtBy,
"config", flags,
)

mux := http.NewServeMux()
reg := prometheus.NewRegistry()
ctx := context.Background()
Expand Down

0 comments on commit bcefba1

Please sign in to comment.