Commit a149c70b authored by Steve Azzopardi's avatar Steve Azzopardi

Merge branch 'prepare-build-current-docker-make-target' into 'master'

Allow to build development version of DEB, RPM and Docker with make

See merge request !824
parents 743ba641 6e838d93
# This image is used to create bleeding edge docker image and is not compatible with any other image
FROM golang:1.8.7
# Copy sources
COPY . /go/src/gitlab.com/gitlab-org/gitlab-runner
WORKDIR /go/src/gitlab.com/gitlab-org/gitlab-runner
# Fetch tags (to have proper versioning)
RUN git fetch --tags || true
# Build development version
ENV BUILD_PLATFORMS -osarch=linux/amd64
RUN make && \
ln -s $(pwd)/out/binaries/gitlab-runner-linux-amd64 /usr/bin/gitlab-ci-multi-runner && \
ln -s $(pwd)/out/binaries/gitlab-runner-linux-amd64 /usr/bin/gitlab-runner
# Install runner
RUN packaging/root/usr/share/gitlab-runner/post-install
# Preserve runner's data
VOLUME ["/etc/gitlab-runner", "/home/gitlab-runner"]
# init sets up the environment and launches gitlab-runner
CMD ["run", "--user=gitlab-runner", "--working-directory=/home/gitlab-runner"]
ENTRYPOINT ["/usr/bin/gitlab-runner"]
NAME ?= gitlab-runner
PACKAGE_NAME ?= $(NAME)
export PACKAGE_NAME ?= $(NAME)
export VERSION := $(shell ./ci/version)
REVISION := $(shell git rev-parse --short=8 HEAD || echo unknown)
BRANCH := $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed 's|refs/remotes/origin/||' | sed 's|refs/heads/||' | sort | head -n 1)
......@@ -68,6 +68,8 @@ MOCKERY_FLAGS = -note="This comment works around https://github.com/vektra/mocke
all: deps helper-docker build
include Makefile.runner_helper.mk
include Makefile.build.mk
include Makefile.package.mk
help:
# Commands:
......@@ -104,21 +106,6 @@ deps: $(DEVELOPMENT_TOOLS)
codequality:
./scripts/codequality analyze --dev
build: $(GOX)
# Building $(NAME) in version $(VERSION) for $(BUILD_PLATFORMS)
gox $(BUILD_PLATFORMS) \
-ldflags "$(GO_LDFLAGS)" \
-output="out/binaries/$(NAME)-{{.OS}}-{{.Arch}}" \
$(PKG)
build_simple: $(GOPATH_SETUP)
# Building $(NAME) in version $(VERSION) for current platform
go build \
-ldflags "$(GO_LDFLAGS)" \
-o "out/binaries/$(NAME)" \
$(PKG)
build_current: helper-docker build_simple
check_race_conditions:
@./scripts/check_race_conditions $(OUR_PACKAGES)
......@@ -190,102 +177,11 @@ build-and-deploy-binary:
make build BUILD_PLATFORMS="-os=linux -arch=amd64"
scp out/binaries/$(PACKAGE_NAME)-linux-amd64 $(SERVER):/usr/bin/gitlab-runner
package: package-deps package-prepare package-deb package-rpm
package-deps:
# Installing packaging dependencies...
which fpm 1>/dev/null || gem install rake fpm --no-ri --no-rdoc
package-prepare:
chmod 755 packaging/root/usr/share/gitlab-runner/
chmod 755 packaging/root/usr/share/gitlab-runner/*
package-deb: package-deps package-prepare
# Building Debian compatible packages...
make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64
make package-deb-fpm ARCH=386 PACKAGE_ARCH=i386
make package-deb-fpm ARCH=arm PACKAGE_ARCH=armel
make package-deb-fpm ARCH=arm PACKAGE_ARCH=armhf
package-rpm: package-deps package-prepare
# Building RedHat compatible packages...
make package-rpm-fpm ARCH=amd64 PACKAGE_ARCH=amd64
make package-rpm-fpm ARCH=386 PACKAGE_ARCH=i686
make package-rpm-fpm ARCH=arm PACKAGE_ARCH=arm
make package-rpm-fpm ARCH=arm PACKAGE_ARCH=armhf
package-deb-fpm:
@mkdir -p out/deb/
fpm -s dir -t deb -n $(PACKAGE_NAME) -v $(VERSION) \
-p out/deb/$(PACKAGE_NAME)_$(PACKAGE_ARCH).deb \
--deb-priority optional --category admin \
--force \
--deb-compression bzip2 \
--after-install packaging/scripts/postinst.deb \
--before-remove packaging/scripts/prerm.deb \
--url https://gitlab.com/gitlab-org/gitlab-runner \
--description "GitLab Runner" \
-m "GitLab Inc. <support@gitlab.com>" \
--license "MIT" \
--vendor "GitLab Inc." \
--conflicts $(PACKAGE_NAME)-beta \
--conflicts gitlab-ci-multi-runner \
--conflicts gitlab-ci-multi-runner-beta \
--provides gitlab-ci-multi-runner \
--replaces gitlab-ci-multi-runner \
--depends ca-certificates \
--depends git \
--depends curl \
--depends tar \
--deb-suggests docker-engine \
-a $(PACKAGE_ARCH) \
packaging/root/=/ \
out/binaries/$(NAME)-linux-$(ARCH)=/usr/lib/gitlab-runner/gitlab-runner \
out/helper-images/=/usr/lib/gitlab-runner/helper-images/
@if [ -n "$(GPG_KEYID)" ]; then \
dpkg-sig -g "--no-tty --digest-algo 'sha512' --passphrase '$(GPG_PASSPHRASE)'" \
-k $(GPG_KEYID) --sign builder "out/deb/$(PACKAGE_NAME)_$(PACKAGE_ARCH).deb" ;\
fi
package-rpm-fpm:
@mkdir -p out/rpm/
fpm -s dir -t rpm -n $(PACKAGE_NAME) -v $(VERSION) \
-p out/rpm/$(PACKAGE_NAME)_$(PACKAGE_ARCH).rpm \
--rpm-compression bzip2 --rpm-os linux \
--force \
--after-install packaging/scripts/postinst.rpm \
--before-remove packaging/scripts/prerm.rpm \
--url https://gitlab.com/gitlab-org/gitlab-runner \
--description "GitLab Runner" \
-m "GitLab Inc. <support@gitlab.com>" \
--license "MIT" \
--vendor "GitLab Inc." \
--conflicts $(PACKAGE_NAME)-beta \
--conflicts gitlab-ci-multi-runner \
--conflicts gitlab-ci-multi-runner-beta \
--provides gitlab-ci-multi-runner \
--replaces gitlab-ci-multi-runner \
--depends git \
--depends curl \
--depends tar \
-a $(PACKAGE_ARCH) \
packaging/root/=/ \
out/binaries/$(NAME)-linux-$(ARCH)=/usr/lib/gitlab-runner/gitlab-runner \
out/helper-images/=/usr/lib/gitlab-runner/helper-images/
@if [ -n "$(GPG_KEYID)" ] ; then \
echo "yes" | setsid rpm \
--define "_gpg_name $(GPG_KEYID)" \
--define "_signature gpg" \
--define "__gpg_check_password_cmd /bin/true" \
--define "__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --digest-algo 'sha512' --passphrase '$(GPG_PASSPHRASE)' --no-secmem-warning -u '%{_gpg_name}' --sign --detach-sign --output %{__signature_filename} %{__plaintext_filename}" \
--addsign out/rpm/$(PACKAGE_NAME)_$(PACKAGE_ARCH).rpm ;\
fi
packagecloud: packagecloud-deps packagecloud-deb packagecloud-rpm
packagecloud-deps:
# Installing packagecloud dependencies...
gem install package_cloud --version "~> 0.3.0" --no-ri --no-rdoc
gem install package_cloud --version "~> 0.3.0" --no-document
packagecloud-deb:
# Sending Debian compatible packages...
......@@ -350,6 +246,7 @@ prepare_index:
# Preparing index file
@./ci/prepare_index
release_docker_images: export RUNNER_BINARY := out/binaries/gitlab-runner-linux-amd64
release_docker_images:
# Releasing Docker images
@./ci/release_docker_images
......
export RUNNER_BINARY ?= out/binaries/$(NAME)
build: $(GOX)
# Building $(NAME) in version $(VERSION) for $(BUILD_PLATFORMS)
gox $(BUILD_PLATFORMS) \
-ldflags "$(GO_LDFLAGS)" \
-output="out/binaries/$(NAME)-{{.OS}}-{{.Arch}}" \
$(PKG)
build_simple: $(GOPATH_SETUP)
# Building $(NAME) in version $(VERSION) for current platform
go build \
-ldflags "$(GO_LDFLAGS)" \
-o "$(RUNNER_BINARY)" \
$(PKG)
build_current: helper-docker build_simple
build_current_docker: export CI_COMMIT_REF_SLUG=$(shell echo $(BRANCH) | cut -c -63 | sed -E 's/[^a-z0-9-]+/-/g' | sed -E 's/^-*([a-z0-9-]+[a-z0-9])-*$$/\1/g')
build_current_docker: build_current_deb
make release_docker_images RUNNER_BINARY=$(RUNNER_BINARY)
build_current_deb: build_current package-deps package-prepare
make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64 RUNNER_BINARY=$(RUNNER_BINARY)
build_current_rpm: build_current package-deps package-prepare
make package-rpm-fpm ARCH=amd64 PACKAGE_ARCH=amd64 RUNNER_BINARY=$(RUNNER_BINARY)
package: package-deps package-prepare package-deb package-rpm
package-deps:
# Installing packaging dependencies...
which fpm 1>/dev/null || gem install rake fpm --no-document
package-prepare:
chmod 755 packaging/root/usr/share/gitlab-runner/
chmod 755 packaging/root/usr/share/gitlab-runner/*
package-deb: package-deps package-prepare
# Building Debian compatible packages...
make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64 RUNNER_BINARY=out/binaries/$(NAME)-linux-amd64
make package-deb-fpm ARCH=386 PACKAGE_ARCH=i386 RUNNER_BINARY=out/binaries/$(NAME)-linux-386
make package-deb-fpm ARCH=arm PACKAGE_ARCH=armel RUNNER_BINARY=out/binaries/$(NAME)-linux-arm
make package-deb-fpm ARCH=arm PACKAGE_ARCH=armhf RUNNER_BINARY=out/binaries/$(NAME)-linux-arm
package-rpm: package-deps package-prepare
# Building RedHat compatible packages...
make package-rpm-fpm ARCH=amd64 PACKAGE_ARCH=amd64 RUNNER_BINARY=out/binaries/$(NAME)-linux-amd64
make package-rpm-fpm ARCH=386 PACKAGE_ARCH=i686 RUNNER_BINARY=out/binaries/$(NAME)-linux-386
make package-rpm-fpm ARCH=arm PACKAGE_ARCH=arm RUNNER_BINARY=out/binaries/$(NAME)-linux-arm
make package-rpm-fpm ARCH=arm PACKAGE_ARCH=armhf RUNNER_BINARY=out/binaries/$(NAME)-linux-arm
package-deb-fpm:
@./ci/package deb
package-rpm-fpm:
@./ci/package rpm
#!/usr/bin/env bash
set -eo pipefail
check_macos_package() {
local binary="${1}"
local package="${2}"
if ! which "${binary}" >/dev/null 2>&1; then
echo
echo -e "\\033[31;1m"
echo "Seems that you're using Mac OS. In case of troubles with packaging ensure"
echo "that ${package} is installed. You can do this e.g. with 'brew install ${package}'"
echo -e "\\033[0m"
echo
fi
}
create_package() {
local packageType=${1}
shift
local customOptions
read -r -a customOptions <<< "${@}"
local uname_s
uname_s=$(uname -s)
if [[ "${uname_s}" == "Darwin" ]]; then
check_macos_package "gtar" "gnu-tar"
check_macos_package "rpmbuild" "rpm"
fi
mkdir -p "out/${packageType}/"
fpm \
--package "out/${packageType}/${PACKAGE_NAME}_${PACKAGE_ARCH}.${packageType}" \
--force \
--input-type dir \
--output-type "${packageType}" \
\
--name "${PACKAGE_NAME}" \
--description "GitLab Runner" \
--version "${VERSION}" \
--url https://gitlab.com/gitlab-org/gitlab-runner \
--maintainer "GitLab Inc. <support@gitlab.com>" \
--license "MIT" \
--vendor "GitLab Inc." \
--architecture "${PACKAGE_ARCH}" \
\
--conflicts "${PACKAGE_NAME}-beta" \
--conflicts gitlab-ci-multi-runner \
--conflicts gitlab-ci-multi-runner-beta \
--provides gitlab-ci-multi-runner \
--replaces gitlab-ci-multi-runner \
\
--depends git \
--depends curl \
--depends tar \
\
${customOptions[@]} \
\
--after-install "packaging/scripts/postinst.${packageType}" \
--before-remove "packaging/scripts/prerm.${packageType}" \
\
packaging/root/=/ \
"${RUNNER_BINARY}=/usr/lib/gitlab-runner/gitlab-runner" \
out/helper-images/=/usr/lib/gitlab-runner/helper-images/
}
create_deb() {
local options=()
options+=("--depends ca-certificates")
options+=("--category admin")
options+=("--deb-priority optional")
options+=("--deb-compression bzip2")
options+=("--deb-suggests docker-engine")
create_package deb "${options[@]}"
if [ -n "${GPG_KEYID}" ]; then
dpkg-sig \
-g "--no-tty --digest-algo 'sha512' --passphrase '${GPG_PASSPHRASE}'" \
-k "${GPG_KEYID}" \
--sign builder
"out/deb/${PACKAGE_NAME}_${PACKAGE_ARCH}.deb"
fi
}
create_rpm() {
local options=()
options+=("--rpm-compression bzip2")
options+=("--rpm-os linux")
create_package rpm "${options[@]}"
if [ -n "${GPG_KEYID}" ] ; then
echo "yes" | setsid rpm \
--define "_gpg_name ${GPG_KEYID}" \
--define "_signature gpg" \
--define "__gpg_check_password_cmd /bin/true" \
--define "__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --digest-algo 'sha512' --passphrase '${GPG_PASSPHRASE}' --no-secmem-warning -u '%{_gpg_name}' --sign --detach-sign --output %{__signature_filename} %{__plaintext_filename}" \
--addsign "out/rpm/${PACKAGE_NAME}_${PACKAGE_ARCH}.rpm"
fi
}
case "${1}" in
deb)
create_deb
;;
rpm)
create_rpm
;;
*)
echo "Usage: ${0} (deb|rpm)"
;;
esac
......@@ -2,6 +2,15 @@
set -eo pipefail
DOCKER_MACHINE_VERSION=${DOCKER_MACHINE_VERSION:-0.14.0}
DOCKER_MACHINE_CHECKSUM=${DOCKER_MACHINE_CHECKSUM:-a4c69bffb78d3cfe103b89dae61c3ea11cc2d1a91c4ff86e630c9ae88244db02}
DUMB_INIT_VERSION=${DUMB_INIT_VERSION:-1.0.2}
DUMB_INIT_CHECKSUM=${DUMB_INIT_CHECKSUM:-a8defac40aaca2ca0896c7c5adbc241af60c7c3df470c1a4c469a860bd805429}
GIT_LFS_VERSION=${GIT_LFS_VERSION:-2.7.1}
GIT_LFS_CHECKSUM=${GIT_LFS_CHECKSUM:-c8952ee72af214e3669f834d829e8a0a3becd160dead18237f99e40d75a3e920}
RUNNER_BINARY=${RUNNER_BINARY:-out/binaries/gitlab-runner-linux-amd64}
IS_LATEST=${IS_LATEST:-}
ref_tag=${CI_COMMIT_TAG}
......@@ -92,14 +101,15 @@ logout() {
_docker logout "${1}"
}
echo "${DOCKER_MACHINE_CHECKSUM} /usr/bin/docker-machine" > dockerfiles/checksums
echo -n > dockerfiles/checksums
echo "${DOCKER_MACHINE_CHECKSUM} /usr/bin/docker-machine" >> dockerfiles/checksums
echo "${DUMB_INIT_CHECKSUM} /usr/bin/dumb-init" >> dockerfiles/checksums
echo "${GIT_LFS_CHECKSUM} /usr/bin/git-lfs" >> dockerfiles/checksums
cat dockerfiles/checksums
cp out/deb/gitlab-runner_amd64.deb dockerfiles/ubuntu/
cp out/deb/gitlab-runner_amd64.deb dockerfiles/ubuntu/gitlab-runner_amd64.deb
cp dockerfiles/checksums dockerfiles/ubuntu
cp out/binaries/gitlab-runner-linux-amd64 dockerfiles/alpine
cp ${RUNNER_BINARY} dockerfiles/alpine/gitlab-runner-linux-amd64
cp dockerfiles/checksums dockerfiles/alpine
build "gitlab/gitlab-runner:ubuntu-${ref_tag}" dockerfiles/ubuntu
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment