Add support for building in docker (#759)

be able to build woodpecker on any environment

Co-authored-by: Zav Shotan <zshotan@bloomberg.net>
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
Zav Shotan 2022-02-10 09:12:47 -05:00 committed by GitHub
parent 3b4dc03486
commit 51904c9ee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View file

@ -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

13
docker/Dockerfile.make Normal file
View file

@ -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" ]