diff --git a/.drone/drone.yml b/.drone/drone.yml new file mode 100644 index 000000000000..2f6183f1d56a --- /dev/null +++ b/.drone/drone.yml @@ -0,0 +1,176 @@ +--- +kind: pipeline +name: Lint +platform: + os: linux + arch: amd64 +trigger: + event: + - push + - pull_request + - tag + ref: + - refs/heads/main + - refs/pull/*/head + - refs/tags/** + +steps: +- name: lint + image: golangci/golangci-lint:v1.37.1 + commands: + - apt-get update -y && apt-get install -y libsystemd-dev + - make lint + +--- +kind: pipeline +type: docker +name: Test +platform: + os: linux + arch: amd64 +trigger: + event: + - push + - pull_request + - tag + ref: + - refs/heads/main + - refs/pull/*/head + - refs/tags/** + +steps: +- name: test + image: rfratto/seego + commands: + - apt-get update && apt-get install -y rubygems rpm nsis apt-transport-https ca-certificates curl gnupg lsb-release + - gem install --no-document fpm + - mkdir -p /usr/local/go/bin + - wget -q https://golang.org/dl/go1.16.5.linux-amd64.tar.gz + - tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz + - rm go1.16.5.linux-amd64.tar.gz + - export PATH=$PATH:/usr/local/go/bin + - make DRONE=true BUILD_IN_CONTAINER=false test +depends_on: + - Lint + +--- +kind: pipeline +type: docker +name: Dist +platform: + os: linux + arch: amd64 +trigger: + ref: + - refs/tags/v* + +steps: +- name: distribute + image: rfratto/seego + commands: + - apt-get update && apt-get install -y rubygems rpm nsis + - gem install --no-document fpm + - mkdir -p /usr/local/go/bin + - wget -q https://golang.org/dl/go1.16.5.linux-amd64.tar.gz + - tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz + - rm go1.16.5.linux-amd64.tar.gz + - export PATH=$PATH:/usr/local/go/bin + - make DRONE=true BUILD_IN_CONTAINER=false RELEASE_TAG=v0.0.0 dist +depends_on: + - Test +--- +kind: pipeline +type: docker +name: Containerize +platform: + os: linux + arch: amd64 +trigger: + ref: + - refs/heads/main + - refs/tags/v* + +steps: +- name: Build Containers + image: docker + volumes: + - name: docker + path: /var/run/docker.sock + environment: + DOCKER_LOGIN: + from_secret: DOCKER_LOGIN + DOCKER_PASSWORD: + from_secret: DOCKER_PASSWORD + commands: + - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD + - apk update && apk add make bash wget git qemu + - wget -q https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64 + - mkdir -p ~/.docker/cli-plugins + - cp buildx-v0.5.1.linux-amd64 ~/.docker/cli-plugins/docker-buildx + - chmod a+x ~/.docker/cli-plugins/docker-buildx + - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - docker buildx create --name multiarch --driver docker-container --use + - make DRONE=true CROSS_BUILD=true RELEASE_BUILD=true agent-image + - make DRONE=true CROSS_BUILD=true RELEASE_BUILD=true agentctl-image + - docker buildx rm multiarch + + +depends_on: + - Lint + +volumes: +- name: docker + host: + path: /var/run/docker.sock +--- +kind: pipeline +type: docker +name: Release +platform: + os: linux + arch: amd64 +trigger: + ref: + - refs/tags/v* + +steps: +- name: create-release + image: rfratto/seego + volumes: + - name: docker + path: /var/run/docker.sock + environment: + DOCKER_LOGIN: + from_secret: DOCKER_LOGIN + DOCKER_PASSWORD: + from_secret: DOCKER_PASSWORD + GITHUB_TOKEN: + from_secret: GITHUB_KEY + commands: + - apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release + - curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - + - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" + - apt-get update && apt-get install -y rubygems rpm nsis docker-ce docker-ce-cli containerd.io + - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD + - gem install --no-document fpm + - mkdir -p /usr/local/go/bin + - wget -q https://golang.org/dl/go1.16.5.linux-amd64.tar.gz + - tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz + - rm go1.16.5.linux-amd64.tar.gz + - export PATH=$PATH:/usr/local/go/bin + - GO111MODULE=on go get -u github.com/mitchellh/gox github.com/tcnksm/ghr + - export PATH="$(go env GOPATH)/bin:$PATH" + - RELEASE_TAG=$DRONE_TAG + - make -j4 BUILD_IN_CONTAINER=false RELEASE_BUILD=true RELEASE_TAG=$RELEASE_TAG publish +depends_on: + - Dist + +volumes: +- name: docker + host: + path: /var/run/docker.sock +--- +kind: signature +hmac: 13ae086c4ff0380f263dc4e3e7289bb82b0130e266cd6763e75cf0e451928225 + +... diff --git a/.github/workflows/containerize.yml b/.github/workflows/containerize.yml deleted file mode 100644 index d2838d1caeb9..000000000000 --- a/.github/workflows/containerize.yml +++ /dev/null @@ -1,81 +0,0 @@ -name: Containerize -on: - push: - branches: - - main -jobs: - test: - name: Test - runs-on: ubuntu-latest - steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install libsystemd-dev - - - name: Set up Go 1.16 - uses: actions/setup-go@v1 - with: - go-version: 1.16 - id: go - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Test - run: make test - agent-container: - name: Build agent Container - runs-on: ubuntu-latest - needs: test - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Login to Docker Hub - run: docker login -u '${{ secrets.DOCKER_USER }}' -p '${{ secrets.DOCKER_PASS }}' - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Make Containers - run: CROSS_BUILD=true RELEASE_BUILD=true make agent-image - agentctl-container: - name: Build agentctl Container - runs-on: ubuntu-latest - needs: test - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Login to Docker Hub - run: docker login -u '${{ secrets.DOCKER_USER }}' -p '${{ secrets.DOCKER_PASS }}' - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Make Containers - run: CROSS_BUILD=true RELEASE_BUILD=true make agentctl-image - agent-operator-container: - name: Build agent-operator Container - runs-on: ubuntu-latest - needs: test - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Login to Docker Hub - run: docker login -u '${{ secrets.DOCKER_USER }}' -p '${{ secrets.DOCKER_PASS }}' - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Make Containers - run: CROSS_BUILD=true RELEASE_BUILD=true make agent-operator-image diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index a58882ffffa6..000000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,131 +0,0 @@ -name: Release -on: - push: - tags: - - '*' -jobs: - test: - name: Test - runs-on: ubuntu-latest - steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install libsystemd-dev - - - name: Set up Go 1.16 - uses: actions/setup-go@v1 - with: - go-version: 1.16 - id: go - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Test - run: make test - agent-container: - name: Build agent Container - runs-on: ubuntu-latest - needs: test - steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install binfmt-support qemu-user-static - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Login to Docker Hub - run: docker login -u '${{ secrets.DOCKER_USER }}' -p '${{ secrets.DOCKER_PASS }}' - - - name: Prepare buildx - run: | - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --name builder --driver docker-container --use - docker buildx inspect --bootstrap - - - name: Build container - run: | - export RELEASE_TAG=${GITHUB_REF##*/} - CROSS_BUILD=true RELEASE_BUILD=true make agent-image - agentctl-container: - name: Build agentctl Container - runs-on: ubuntu-latest - needs: test - steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install binfmt-support qemu-user-static - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Login to Docker Hub - run: docker login -u '${{ secrets.DOCKER_USER }}' -p '${{ secrets.DOCKER_PASS }}' - - - name: Prepare buildx - run: | - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --name builder --driver docker-container --use - docker buildx inspect --bootstrap - - - name: Build container - run: | - export RELEASE_TAG=${GITHUB_REF##*/} - CROSS_BUILD=true RELEASE_BUILD=true make agentctl-image - agent-operator-container: - name: Build agent-operator Container - runs-on: ubuntu-latest - needs: test - steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install binfmt-support qemu-user-static - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Login to Docker Hub - run: docker login -u '${{ secrets.DOCKER_USER }}' -p '${{ secrets.DOCKER_PASS }}' - - - name: Prepare buildx - run: | - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --name builder --driver docker-container --use - docker buildx inspect --bootstrap - - - name: Build container - run: | - export RELEASE_TAG=${GITHUB_REF##*/} - CROSS_BUILD=true RELEASE_BUILD=true make agent-operator-image - release: - name: Release - needs: test - runs-on: ubuntu-latest - steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install libsystemd-dev - - - name: Set up Go 1.16 - uses: actions/setup-go@v1 - with: - go-version: 1.16 - id: go - - - name: Install gox and ghr - run: | - pushd / - GO111MODULE=on go get -u \ - github.com/mitchellh/gox \ - github.com/tcnksm/ghr - popd - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Make Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # This is required so gox and ghr are available - export PATH="$(go env GOPATH)/bin:$PATH" - - export RELEASE_TAG=${GITHUB_REF##*/} - - make -j4 RELEASE_BUILD=true publish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 861e06a06d3b..692c55d5ff88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,37 +1,13 @@ name: Test on: [pull_request] jobs: - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install libsystemd-dev - - - name: Set up Go 1.16 - uses: actions/setup-go@v1 - with: - go-version: 1.16 - id: go - - name: Install golangci-lint - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/local/bin v1.37.1 - - name: Checkout code - uses: actions/checkout@v2 - - name: Lint - run: make lint - test: name: Test strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: [macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - name: Get build dependencies - run: sudo apt-get update && sudo apt-get install libsystemd-dev - if: matrix.platform == 'ubuntu-latest' - - name: Set up Go 1.16 uses: actions/setup-go@v1 with: @@ -40,15 +16,6 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Build - run: make cmd/agent/agent cmd/agentctl/agentctl cmd/agent-operator/agent-operator + run: make BUILD_IN_CONTAINER=false cmd/agent/agent cmd/agentctl/agentctl cmd/agent-operator/agent-operator - name: Test - run: make test - - package: - name: Test Packages - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Test Packages - run: RELEASE_TAG=v0.0.0 make test-packages + run: make BUILD_IN_CONTAINER=false test \ No newline at end of file diff --git a/.gitignore b/.gitignore index cba84c8dfcca..85e730ded16e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,11 +4,16 @@ .published .pkg .cache +.vscode +vendor cover*.out cmd/agent/agent cmd/agentctl/agentctl cmd/agent-operator/agent-operator dist/ +packaging/windows/LICENSE +packaging/windows/agent-windows-amd64.exe .DS_Store +buildx-v* diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a05f91eca75..8ae6b86b71a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ - [ENHANCEMENT] Allow reloading configuration using `SIGHUP` signal. (@tharun208) +- [ENHANCEMENT] Switch to drone for releases. (@mattdurham) + - [BUGFIX] Fix race condition that may occur and result in a panic when initializing scraping service cluster. (@rfratto) diff --git a/Makefile b/Makefile index 6b553ad4992e..339bc7eedc80 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,32 @@ SHELL = /usr/bin/env bash # Docker image info IMAGE_PREFIX ?= grafana IMAGE_TAG ?= $(shell ./tools/image-tag) +DRONE ?= false +# This is normally set by the caller but when building the agent windows installer it needs to be set to something +RELEASE_TAG ?= v0.0.0 + + +# TARGETPLATFORM is specifically called from `docker buildx --platform`, this is mainly used when pushing docker image manifests, normal generally means NON DRONE builds +TARGETPLATFORM ?=normal + +# This is used to set all the environment variables to pass to the go build/seego/docker commands +define SetBuildVarsConditional +$(if $(filter $(1),normal),CGO_ENABLED=1, \ +$(if $(filter $(1),linux/amd64),CGO_ENABLED=1 GOOS=linux GOARCH=amd64, \ +$(if $(filter $(1),linux/arm64),CGO_ENABLED=1 GOOS=linux GOARCH=arm64, \ +$(if $(filter $(1),linux/arm/v7),CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7, \ +$(if $(filter $(1),linux/arm/v6),CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6, \ +$(if $(filter $(1),darwin/amd64),CGO_ENABLED=1 GOOS=darwin GOARCH=amd64, \ +$(if $(filter $(1),darwin/arm64),CGO_ENABLED=1 GOOS=darwin GOARCH=arm64, \ +$(if $(filter $(1),windows),CGO_ENABLED=1 GOOS=windows GOARCH=amd64, \ +$(if $(filter $(1),mipls),CGO_ENABLED=1 GOOS=linux GOARCH=mipsle, \ +$(if $(filter $(1),freebsd),CGO_ENABLED=1 GOOS=freebsd GOARCH=amd64, $(error invalid flag $(1))) \ +))))))))) +endef + +ALL_CGO_BUILD_FLAGS = $(call SetBuildVarsConditional,$(TARGETPLATFORM)) + + # Setting CROSS_BUILD=true enables cross-compiling `agent` and `agentctl` for # different architectures. When true, docker buildx is used instead of docker, @@ -45,13 +71,12 @@ DOCKER_BUILD_FLAGS = --build-arg RELEASE_BUILD=$(RELEASE_BUILD) --build-arg IMAG # cause problems with some C libraries. CGO_FLAGS := -ldflags "-s -w $(GO_LDFLAGS)" -tags "netgo" DEBUG_CGO_FLAGS := -gcflags "all=-N -l" -ldflags "-s -w $(GO_LDFLAGS)" -tags "netgo" - # If we're not building the release, use the debug flags instead. ifeq ($(RELEASE_BUILD),false) GO_FLAGS = $(DEBUG_GO_FLAGS) endif -NETGO_CHECK = @strings $@ | grep cgo_stub\\\.go >/dev/null || { \ +NETGO_CHECK = strings $@ | grep cgo_stub\\\.go >/dev/null || { \ rm $@; \ echo "\nYour go standard library was built without the 'netgo' build tag."; \ echo "To fix that, run"; \ @@ -75,27 +100,39 @@ PACKAGE_RELEASE := 1 DOCKERFILE = Dockerfile -seego = docker run --rm -t -v "$(CURDIR):$(CURDIR)" -w "$(CURDIR)" -e "CGO_ENABLED=$$CGO_ENABLED" -e "GOOS=$$GOOS" -e "GOARCH=$$GOARCH" -e "GOARM=$$GOARM" -e "GOMIPS=$$GOMIPS" grafana/agent/seego -docker-build = docker build $(DOCKER_BUILD_FLAGS) +# If Go is installed locally mount the local module cache so seego builds +# aren't too slow. +ifeq (, $(shell which go)) +MOD_MOUNT="" +else +MOD_MOUNT=-v "$(shell go env GOMODCACHE):/go/pkg/mod" +endif +# seego is used by default when running bare make commands such as `make dist` this uses an image that has all the necessary libraries to cross build +# when using drone the docker in docker is more problematic so instead drone uses seego has the base image then calls make running "raw" commands +seego = docker run --rm -t $(MOD_MOUNT) -v "$(CURDIR):$(CURDIR)" -w "$(CURDIR)" -e "CGO_ENABLED=$$CGO_ENABLED" -e "GOOS=$$GOOS" -e "GOARCH=$$GOARCH" -e "GOARM=$$GOARM" -e "GOMIPS=$$GOMIPS" grafana/agent/seego +docker-build = docker build $(DOCKER_BUILD_FLAGS) ifeq ($(CROSS_BUILD),true) DOCKERFILE = Dockerfile.buildx - docker-build = docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 $(DOCKER_BUILD_FLAGS) endif -ifeq ($(BUILD_IN_CONTAINER),false) -seego = "/seego.sh" +# we want to override the default seego behavior. Drone always builds locally inside seego and if build in container is false then use +ifeq ($(DRONE),true) +seego = "/go_wrapper.sh" +else ifeq ($(BUILD_IN_CONTAINER),false) +seego = go endif + ######## # CRDs # ######## crds: ifeq ($(BUILD_IN_CONTAINER),true) - @mkdir -p $(shell pwd)/.pkg - @mkdir -p $(shell pwd)/.cache + mkdir -p $(shell pwd)/.pkg + mkdir -p $(shell pwd)/.cache docker run -i \ -v $(shell pwd)/.cache:/go/cache \ -v $(shell pwd)/.pkg:/go/pkg \ @@ -118,8 +155,8 @@ touch-protos: %.pb.go: $(PROTO_DEFS) ifeq ($(BUILD_IN_CONTAINER),true) - @mkdir -p $(shell pwd)/.pkg - @mkdir -p $(shell pwd)/.cache + mkdir -p $(shell pwd)/.pkg + mkdir -p $(shell pwd)/.cache docker run -i \ -v $(shell pwd)/.cache:/go/cache \ -v $(shell pwd)/.pkg:/go/pkg \ @@ -138,39 +175,34 @@ agent: cmd/agent/agent agentctl: cmd/agentctl/agentctl agent-operator: cmd/agent-operator/agent-operator -cmd/agent/agent: check-seego cmd/agent/main.go -ifeq ($(CROSS_BUILD),false) - CGO_ENABLED=1 go build $(CGO_FLAGS) -o $@ ./$(@D) -else - @CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM); $(seego) build $(CGO_FLAGS) -o $@ ./$(@D) -endif + + + +# In general DRONE variable should overwrite any other options, if DRONE is not set then fallback to normal behavior + +cmd/agent/agent: seego cmd/agent/main.go + $(ALL_CGO_BUILD_FLAGS) ; $(seego) build $(CGO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) -cmd/agentctl/agentctl: check-seego cmd/agentctl/main.go -ifeq ($(CROSS_BUILD),false) - CGO_ENABLED=1 go build $(CGO_FLAGS) -o $@ ./$(@D) -else - @CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM); $(seego) build $(CGO_FLAGS) -o $@ ./$(@D) -endif + +cmd/agentctl/agentctl: seego cmd/agentctl/main.go + $(ALL_CGO_BUILD_FLAGS) ; $(seego) build $(CGO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) + cmd/agent-operator/agent-operator: cmd/agent-operator/main.go -ifeq ($(CROSS_BUILD),false) - CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) -else - GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) -endif + $(ALL_CGO_BUILD_FLAGS) ; $(seego) build $(CGO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) + agent-image: $(docker-build) -t $(IMAGE_PREFIX)/agent:latest -t $(IMAGE_PREFIX)/agent:$(IMAGE_TAG) -f cmd/agent/$(DOCKERFILE) . - agentctl-image: $(docker-build) -t $(IMAGE_PREFIX)/agentctl:latest -t $(IMAGE_PREFIX)/agentctl:$(IMAGE_TAG) -f cmd/agentctl/$(DOCKERFILE) . - agent-operator-image: $(docker-build) -t $(IMAGE_PREFIX)/agent-operator:latest -t $(IMAGE_PREFIX)/agent-operator:$(IMAGE_TAG) -f cmd/agent-operator/$(DOCKERFILE) . + install: CGO_ENABLED=1 go install $(CGO_FLAGS) ./cmd/agent CGO_ENABLED=0 go install $(GO_FLAGS) ./cmd/agentctl @@ -223,62 +255,90 @@ dist: dist-agent dist-agentctl dist-packages pushd dist && sha256sum * > SHA256SUMS && popd .PHONY: dist +#################### +# BEGIN AGENT DIST # +#################### + dist-agent: seego dist/agent-linux-amd64 dist/agent-linux-arm64 dist/agent-linux-armv6 dist/agent-linux-armv7 dist/agent-darwin-amd64 dist/agent-darwin-arm64 dist/agent-windows-amd64.exe dist/agent-freebsd-amd64 dist/agent-windows-installer.exe dist/agent-linux-amd64: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,linux/amd64) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + dist/agent-linux-arm64: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=arm64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,linux/arm64) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + dist/agent-linux-armv6: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,linux/arm/v6) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + dist/agent-linux-armv7: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,linux/arm/v7) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + dist/agent-linux-mipsle: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=mipsle GOMIPS=softfloat; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent -dist/agent-darwin-amd64: seego - @CGO_ENABLED=1 GOOS=darwin GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,linux/mipsle) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + +dist/agent-darwin-amd64: seego + $(call SetBuildVarsConditional,darwin/amd64) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + dist/agent-darwin-arm64: seego - @CGO_ENABLED=1 GOOS=darwin GOARCH=arm64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,darwin/arm64) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + dist/agent-windows-amd64.exe: seego - @CGO_ENABLED=1 GOOS=windows GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,windows) ; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + dist/agent-windows-installer.exe: dist/agent-windows-amd64.exe - cp dist/agent-windows-amd64.exe ./packaging/windows + cp ./dist/agent-windows-amd64.exe ./packaging/windows cp LICENSE ./packaging/windows - docker build ./packaging/windows -t windows_nsis - docker run -e VERSION=${RELEASE_TAG} --rm -t -v $(CURDIR)/dist:/app windows_nsis +ifeq ($(BUILD_IN_CONTAINER),true) + docker build -t windows_installer ./packaging/windows + docker run --rm -t -v "${PWD}:/home" windows_installer +else + makensis -V4 -DVERSION=${RELEASE_TAG} -DOUT="../../dist/grafana-agent-installer.exe" ./packaging/windows/install_script.nsis +endif + dist/agent-freebsd-amd64: seego - @CGO_ENABLED=1 GOOS=freebsd GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + $(call SetBuildVarsConditional,freebsd); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agent + + +####################### +# BEGIN AGENTCTL DIST # +####################### dist-agentctl: seego dist/agentctl-linux-amd64 dist/agentctl-linux-arm64 dist/agentctl-linux-armv6 dist/agentctl-linux-armv7 dist/agentctl-darwin-amd64 dist/agentctl-darwin-arm64 dist/agentctl-windows-amd64.exe dist/agentctl-freebsd-amd64 + dist/agentctl-linux-amd64: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,linux/amd64); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-linux-arm64: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=arm64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,linux/arm64); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-linux-armv6: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,linux/arm/v6); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-linux-armv7: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,linux/arm/v7); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-linux-mipsle: seego - @CGO_ENABLED=1 GOOS=linux GOARCH=mipsle GOMIPS=softfloat; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,linux/mipsle); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-darwin-amd64: seego - @CGO_ENABLED=1 GOOS=darwin GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,darwin/amd64); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-darwin-arm64: seego - @CGO_ENABLED=1 GOOS=darwin GOARCH=arm64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,darwin/arm64); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-windows-amd64.exe: seego - @CGO_ENABLED=1 GOOS=windows GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,windows); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + dist/agentctl-freebsd-amd64: seego - @CGO_ENABLED=1 GOOS=freebsd GOARCH=amd64; $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl + $(call SetBuildVarsConditional,freebsd); $(seego) build $(CGO_FLAGS) -o $@ ./cmd/agentctl seego: tools/seego/Dockerfile - docker build -t grafana/agent/seego tools/seego - -# Makes seego if CROSS_BUILD is true. -check-seego: -ifeq ($(CROSS_BUILD),true) +ifeq ($(DRONE),false) ifeq ($(BUILD_IN_CONTAINER),true) - $(MAKE) seego + docker build -t grafana/agent/seego tools/seego endif endif + build-image/.uptodate: build-image/Dockerfile docker pull $(BUILD_IMAGE) || docker build -t $(BUILD_IMAGE) $(@D) touch $@ @@ -323,9 +383,7 @@ dist-packages-armv7: enforce-release-tag dist/agent-linux-armv7 dist/agentctl-li $(container_make) $@; else - -package_base = dist/grafana-agent-$(PACKAGE_VERSION)-$(PACKAGE_RELEASE) - +package_base = ./dist/grafana-agent-$(PACKAGE_VERSION)-$(PACKAGE_RELEASE) dist-packages-amd64: $(package_base).amd64.deb $(package_base).amd64.rpm dist-packages-arm64: $(package_base).arm64.deb $(package_base).arm64.rpm dist-packages-armv6: $(package_base).armv6.deb @@ -386,7 +444,7 @@ $(PACKAGE_PREFIX).armv7.rpm: $(RPM_DEPS) endif enforce-release-tag: - @sh -c '[ -n "${RELEASE_TAG}" ] || (echo \$$RELEASE_TAG environment variable not set; exit 1)' + sh -c '[ -n "${RELEASE_TAG}" ] || (echo \$$RELEASE_TAG environment variable not set; exit 1)' test-packages: enforce-release-tag seego dist-packages-amd64 packaging/centos-systemd/.uptodate packaging/debian-systemd/.uptodate ./tools/test-packages $(IMAGE_PREFIX) $(PACKAGE_VERSION) $(PACKAGE_RELEASE) @@ -398,3 +456,9 @@ clean-dist: publish: dist ./tools/release + +# Drone signs the yaml, you will need to specify DRONE_TOKEN, which can be found by logging into your profile in drone +.PHONY: drone +drone: + drone lint .drone/drone.yml --trusted + drone --server https://drone.grafana.net sign --save grafana/agent .drone/drone.yml diff --git a/cmd/agent/Dockerfile.buildx b/cmd/agent/Dockerfile.buildx index 4500a2446c16..d914f505078a 100644 --- a/cmd/agent/Dockerfile.buildx +++ b/cmd/agent/Dockerfile.buildx @@ -17,10 +17,7 @@ WORKDIR /src/agent ARG RELEASE_BUILD=true ARG IMAGE_TAG -# Rename seego's /go_wrapper.sh to /seego.sh for readability in the -# Makefile. -RUN cp /go_wrapper.sh /seego.sh -RUN make clean && IMAGE_TAG=${IMAGE_TAG} RELEASE_BUILD=${RELEASE_BUILD} BUILD_IN_CONTAINER=false bash ./tools/cross_build.bash agent +RUN make clean && IMAGE_TAG=${IMAGE_TAG} RELEASE_BUILD=${RELEASE_BUILD} BUILD_IN_CONTAINER=false make agent FROM debian:buster-slim diff --git a/cmd/agentctl/Dockerfile.buildx b/cmd/agentctl/Dockerfile.buildx index 0ec4a995a1a1..9838c7a6de06 100644 --- a/cmd/agentctl/Dockerfile.buildx +++ b/cmd/agentctl/Dockerfile.buildx @@ -17,10 +17,8 @@ WORKDIR /src/agent ARG RELEASE_BUILD=true ARG IMAGE_TAG -# Rename seego's /go_wrapper.sh to /seego.sh for readability in the # Makefile. -RUN cp /go_wrapper.sh /seego.sh -RUN make clean && IMAGE_TAG=${IMAGE_TAG} RELEASE_BUILD=${RELEASE_BUILD} BUILD_IN_CONTAINER=false bash ./tools/cross_build.bash agentctl +RUN make clean && IMAGE_TAG=${IMAGE_TAG} RELEASE_BUILD=${RELEASE_BUILD} BUILD_IN_CONTAINER=false make agentctl FROM debian:buster-slim diff --git a/packaging/windows/Dockerfile b/packaging/windows/Dockerfile index b74c81e477f8..07b8881d0776 100644 --- a/packaging/windows/Dockerfile +++ b/packaging/windows/Dockerfile @@ -1,10 +1,4 @@ FROM debian RUN apt-get update && \ apt-get install -y nsis -RUN mkdir app -WORKDIR /home -COPY logo.ico logo.ico -COPY install_script.nsis install_script.nsis -COPY agent-windows-amd64.exe agent-windows-amd64.exe -COPY LICENSE LICENSE -ENTRYPOINT makensis -V4 -DVERSION=$VERSION /home/install_script.nsis \ No newline at end of file +ENTRYPOINT makensis -V4 -DVERSION=$VERSION -DOUT="/home/dist/grafana-agent-installer.exe" /home/packaging/windows/install_script.nsis \ No newline at end of file diff --git a/packaging/windows/install_script.nsis b/packaging/windows/install_script.nsis index 6558b8ff775b..3c735d173207 100644 --- a/packaging/windows/install_script.nsis +++ b/packaging/windows/install_script.nsis @@ -16,7 +16,8 @@ InstallDir "$PROGRAMFILES64\${APPNAME}" # This will be in the installer/uninstaller's title bar Name "${APPNAME} ${VERSION}" Icon "logo.ico" -outFile "/app/grafana-agent-installer.exe" +outFile "${OUT}" + !include nsDialogs.nsh !include FileFunc.nsh diff --git a/tools/cross_build.bash b/tools/cross_build.bash deleted file mode 100755 index 30dd753100a8..000000000000 --- a/tools/cross_build.bash +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash -# -# cross_build.bash will set appropriate GOOS/GOARCH values given a TARGETPLATFORM -# variable. TARGETPLATFORM will accept values populated by docker buildx. -# -# $BUILDPLATFORM must be linux/amd64. -# -# Only the following values for $TARGETPLATFORM are supported: -# linux/amd64 -# linux/arm64 -# linux/arm/v7 - -main() { - target=$1 - - if [[ "$target" == "" ]]; then - echo ">>> usage: cross_build.bash [makefile target]" - exit 1 - fi - - if [[ "$BUILDPLATFORM" != "linux/amd64" ]]; then - echo ">>> ERROR: BUILDPLATFORM must be linux/amd64, got $BUILDPLATFORM" - exit 1 - fi - - case "$TARGETPLATFORM" in - linux/amd64) native_build $target ;; - linux/arm64) seego_build $target arm64 ;; - linux/arm/v6) seego_build $target arm 6 ;; - linux/arm/v7) seego_build $target arm 7 ;; - *) - echo ">>> ERROR: unsupported TARGETPLATFORM value $TARGETPLATFORM" - exit 1 - esac -} - -native_build() { - CROSS_BUILD=false make $1 -} - -seego_build() { - echo ">>> building $1 for $2" - CROSS_BUILD=true CGO_ENABLED=1 GOOS=linux GOARCH=$2 GOARM=$3 make $1 -} - -main $1 diff --git a/tools/seego/Dockerfile b/tools/seego/Dockerfile index 36c5b1879ac2..2bb4f3a8a771 100644 --- a/tools/seego/Dockerfile +++ b/tools/seego/Dockerfile @@ -9,3 +9,5 @@ RUN rm -rf /usr/local/go \ && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ && tar -C /usr/local -xzf golang.tar.gz \ && rm golang.tar.gz +RUN apt-get update +RUN apt-get install -y nsis \ No newline at end of file