mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 11:21:02 +00:00
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:
parent
3b4dc03486
commit
51904c9ee1
2 changed files with 40 additions and 1 deletions
28
Makefile
28
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
|
||||
|
|
13
docker/Dockerfile.make
Normal file
13
docker/Dockerfile.make
Normal 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" ]
|
Loading…
Reference in a new issue