diff --git a/Makefile b/Makefile index 6ac7fcd03..a9b38ebfb 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ ifneq ($(CI_COMMIT_TAG),) endif # append commit-sha to next version -BUILD_VERSION := $(VERSION) +BUILD_VERSION ?= $(VERSION) ifeq ($(BUILD_VERSION),next) CI_COMMIT_SHA ?= $(shell git rev-parse HEAD) BUILD_VERSION := $(shell echo "next-$(shell echo ${CI_COMMIT_SHA} | head -c 8)") @@ -18,6 +18,29 @@ endif LDFLAGS := -s -w -extldflags "-static" -X github.com/woodpecker-ci/woodpecker/version.Version=${BUILD_VERSION} +# If the first argument is "in_docker"... +ifeq (in_docker,$(firstword $(MAKECMDGOALS))) + # use the rest as arguments for "in_docker" + MAKE_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + # Ignore the next args + $(eval $(MAKE_ARGS):;@:) + + in_docker: + @[ "1" == "$(shell docker image ls woodpecker/make:local -a | wc -l)" ] && docker build -f ./docker/Dockerfile.make -t woodpecker/make:local . || echo reuse existing docker image + @echo run in docker: + @docker run -it \ + --user $(shell id -u):$(shell id -g) \ + -e VERSION="$(VERSION)" \ + -e BUILD_VERSION="$(BUILD_VERSION)" \ + -e CI_COMMIT_SHA="$(CI_COMMIT_SHA)" \ + -e GO_PACKAGES="$(GO_PACKAGES)" \ + -e TARGETOS="$(TARGETOS)" \ + -e TARGETARCH="$(TARGETARCH)" \ + -v $(PWD):/build --rm woodpecker/make:local make $(MAKE_ARGS) +else + +# Proceed with normal make + all: build vendor: @@ -31,6 +54,7 @@ format: clean: go clean -i ./... rm -rf build + @[ "1" != "$(shell docker image ls woodpecker/make:local -a | wc -l)" ] && docker image rm woodpecker/make:local || echo no docker image to clean .PHONY: lint lint: @@ -155,3 +179,5 @@ bundle: bundle-agent bundle-server bundle-cli .PHONY: version version: @echo ${BUILD_VERSION} + +endif diff --git a/docker/Dockerfile.make b/docker/Dockerfile.make new file mode 100644 index 000000000..861d1bf8c --- /dev/null +++ b/docker/Dockerfile.make @@ -0,0 +1,13 @@ +# docker build --rm -f docker/Dockerfile.server -t woodpeckerci/woodpecker-server . +FROM golang:1.16-alpine as golang_image +FROM node:16-alpine + +RUN apk add make gcc musl-dev + +# Build packages. +COPY --from=golang_image /usr/local/go /usr/local/go +ENV PATH=$PATH:/usr/local/go/bin + +WORKDIR /build + +CMD [ "sh" ]