Skip to content

Commit

Permalink
Merge pull request #756 from mdelapenya/dockerise-build
Browse files Browse the repository at this point in the history
feat: support building a release in a dockerised environment
  • Loading branch information
mdelapenya authored Oct 11, 2021
2 parents 888b7da + b6e6df8 commit e08130b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ pipeline {
}
}
}
stage('Release Test') {
options { skipDefaultCheckout() }
steps {
cleanup()
dir("${BASE_DIR}"){
withGoEnv(){
sh(label: 'Create release artifacts', script: 'make docker-release')
}
}
}
post {
success {
dir("${BASE_DIR}"){
sh(label: 'Check release artifacts', script: 'make test-release')
}
}
}
}
}
post {
cleanup {
Expand Down
36 changes: 36 additions & 0 deletions .ci/scripts/test-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -euo pipefail

FLEET_SERVER_VERSION=${1:?"Fleet Server version is needed"}

PLATFORM_FILES=(darwin-arm64.tar.gz darwin-x86_64.tar.gz linux-arm64.tar.gz linux-x86_64.tar.gz linux-x86.tar.gz windows-x86_64.zip windows-x86.zip)

#make release

FILE_PREFIX="build/distributions/fleet-server-${FLEET_SERVER_VERSION}-"

RED='\033[0;31m'
GREEN='\033[0;32m'
NO_COLOR='\033[0m'

echo -e "Checking fleet-server-${FLEET_SERVER_VERSION} binaries created after a release:"

for PLATFORM_FILE in "${PLATFORM_FILES[@]}"
do
file="${FILE_PREFIX}${PLATFORM_FILE}"
if [ ! -f "${file}" ]; then
echo -e "${RED}!! ${PLATFORM_FILE}: The file was not created.${NO_COLOR}"
exit 1
else
echo -e "- ${PLATFORM_FILE} ${GREEN}OK${NO_COLOR}"
fi

fileSha512="${file}.sha512"
if [ ! -f "${fileSha512}" ]; then
echo -e "${RED}!! ${fileSha512}: The file was not created.${NO_COLOR}"
exit 1
else
echo -e "- ${PLATFORM_FILE}.sha512 ${GREEN}OK${NO_COLOR}"
fi
done
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ci
.github
build
8 changes: 8 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG GO_VERSION
FROM golang:${GO_VERSION}-stretch

RUN apt-get update && apt-get install -y zip

WORKDIR /go/src/github.com/elastic/fleet-server

ENTRYPOINT [ "make", "release" ]
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL=/bin/bash
GO_VERSION=$(shell cat '.go-version')
DEFAULT_VERSION=$(shell awk '/const defaultVersion/{print $$NF}' main.go | tr -d '"')
TARGET_ARCH_386=x86
TARGET_ARCH_amd64=x86_64
Expand All @@ -11,6 +12,7 @@ BUILDMODE_windows_amd64=-buildmode=pie
BUILDMODE_darwin_amd64=-buildmode=pie
BUILDMODE_darwin_arm64=-buildmode=pie

BUILDER_IMAGE=docker.elastic.co/observability-ci/fleet-server-builder:latest

ifdef VERSION_QUALIFIER
DEFAULT_VERSION:=${DEFAULT_VERSION}-${VERSION_QUALIFIER}
Expand Down Expand Up @@ -100,6 +102,10 @@ test: prepare-test-context ## - Run all tests
@./dev-tools/run_with_go_ver $(MAKE) test-int
@$(MAKE) junit-report

.PHONY: test-release
test-release: ## - Check that all release binaries are created
./.ci/scripts/test-release.sh $(DEFAULT_VERSION)

.PHONY: test-unit
test-unit: prepare-test-context ## - Run unit tests only
set -o pipefail; go test -v -race ./... | tee build/test-unit.out
Expand Down Expand Up @@ -140,6 +146,13 @@ else
@cd build/distributions && shasum -a 512 fleet-server-$(VERSION)-$(OS)-$(ARCH).tar.gz > fleet-server-$(VERSION)-$(OS)-$(ARCH).tar.gz.sha512
endif

build-releaser: ## - Build a Docker image to run make package including all build tools
docker build -t $(BUILDER_IMAGE) -f Dockerfile.build --build-arg GO_VERSION=$(GO_VERSION) .

.PHONY: docker-release
docker-release: build-releaser ## - Builds a release for all platforms in a dockerised environment
docker run --rm --volume $(PWD):/go/src/github.com/elastic/fleet-server $(BUILDER_IMAGE)

.PHONY: release
release: $(PLATFORM_TARGETS) ## - Builds a release. Specify exact platform with PLATFORMS env.

Expand Down

0 comments on commit e08130b

Please sign in to comment.