From bcefba135349cda9ebcf585d1d8d88cc24a68ff4 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Mon, 27 Sep 2021 12:15:18 +0200 Subject: [PATCH] Add goreleaser Signed-off-by: Kemal Akkoyun --- .github/workflows/build.yml | 47 ++++++++++++++++++++++++++++++++++- .github/workflows/release.yml | 40 +++++++++++++++++++++++++++++ .goreleaser.yml | 40 +++++++++++++++++++++++++++++ Makefile | 2 +- cmd/parca-agent/main.go | 19 ++++++++++++-- 5 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 .goreleaser.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5641b88acb..6306aeda49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: | @@ -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: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4d9e72b0f7..6b17881c6e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000000..ce49626c3b --- /dev/null +++ b/.goreleaser.yml @@ -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:' diff --git a/Makefile b/Makefile index 09c67b0b12..4903a8d55a 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/cmd/parca-agent/main.go b/cmd/parca-agent/main.go index 10189be14a..f42c3667b4 100644 --- a/cmd/parca-agent/main.go +++ b/cmd/parca-agent/main.go @@ -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'"` @@ -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()