Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

area/circleci: Speed up circleci build process for branches and pr #16778

Merged
merged 38 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2dab761
speed up circleci build
briangann Apr 26, 2019
b88f7ce
add build-fast to jobs
briangann Apr 26, 2019
3008dd5
fix script
briangann Apr 26, 2019
2fb8544
remove build from jobs
briangann Apr 26, 2019
20db229
convert to functions and add args for different build types
briangann Apr 26, 2019
6003b2e
fix typo
briangann Apr 26, 2019
c1797cf
add frontend
briangann Apr 26, 2019
6bb6bb8
add yarn cache
briangann Apr 26, 2019
8aa92f9
split build fast into pieces
briangann Apr 26, 2019
b083aed
split build process
briangann Apr 26, 2019
a799a85
ensure dist exists for backend build
briangann Apr 26, 2019
fb28193
backend should persist bin
briangann Apr 26, 2019
354152d
add build process output
briangann Apr 26, 2019
49ecdc1
add debug to frontend output
briangann Apr 26, 2019
168137e
additional debug output for frontend build
briangann Apr 26, 2019
5b98c85
more debug output and set path for cache
briangann Apr 26, 2019
2ac4ca9
update frontend build artifacts
briangann Apr 26, 2019
29f18a6
fix frontend artifact path
briangann Apr 26, 2019
b3c94db
attach workspace in package step
briangann Apr 26, 2019
77fa9dd
package needs node_modules for grunt
briangann Apr 26, 2019
5ee3386
add node_moduels to persist
briangann Apr 26, 2019
027fdc1
omit latest
briangann Apr 26, 2019
da34183
set noninteractive flag for docker build
briangann Apr 26, 2019
d63cf47
add fast option to docker build
briangann Apr 26, 2019
3eaea9a
update path
briangann Apr 26, 2019
799011c
packaing needs grunt
briangann Apr 26, 2019
555f712
add checkout to package step
briangann Apr 26, 2019
df80fcf
fix cache
briangann Apr 27, 2019
f32b3d2
debug workspace
briangann Apr 27, 2019
8305054
update cache
briangann Apr 27, 2019
2bbee8d
debugging workspace
briangann Apr 27, 2019
225021d
more debugging
briangann Apr 27, 2019
70b649c
add build latest to packaging step
briangann Apr 27, 2019
7e3376a
fast build should not try to tag non-amd builds
briangann Apr 27, 2019
bfc55f6
remove debug steps, remove signing step for prs-and-branches
briangann Apr 27, 2019
6ce6f64
remove debug code
briangann Apr 27, 2019
4e8c04c
Merge branch 'master' of https://github.com/grafana/grafana into 2019…
briangann Apr 27, 2019
269c436
frontend also pulls phantomjs, include in workspace
briangann Apr 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 122 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,117 @@ jobs:
paths:
- dist/*

build-fast-backend:
docker:
- image: grafana/build-container:1.2.6
working_directory: /go/src/github.com/grafana/grafana
steps:
- checkout
- run:
name: prepare build tools
command: '/tmp/bootstrap.sh'
- run:
name: build grafana backend
command: './scripts/build/build.sh --fast --backend-only'
- persist_to_workspace:
root: .
paths:
- bin/*

build-fast-frontend:
docker:
- image: grafana/build-container:1.2.6
working_directory: /go/src/github.com/grafana/grafana
steps:
- checkout
- run:
name: prepare build tools
command: '/tmp/bootstrap.sh'
- restore_cache:
key: frontend-dependency-cache-{{ checksum "yarn.lock" }}
- run:
name: build grafana frontend
command: './scripts/build/build.sh --fast --frontend-only'
- save_cache:
key: frontend-dependency-cache-{{ checksum "yarn.lock" }}
paths:
- node_modules
- persist_to_workspace:
root: .
paths:
- public/build/*
- tools/phantomjs/*

build-fast-package:
docker:
- image: grafana/build-container:1.2.6
working_directory: /go/src/github.com/grafana/grafana
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
key: frontend-dependency-cache-{{ checksum "yarn.lock" }}
- run:
name: prepare build tools
command: '/tmp/bootstrap.sh'
- run:
name: package grafana
command: './scripts/build/build.sh --fast --package-only'
- run:
name: sha-sum packages
command: 'go run build.go sha-dist'
- run:
name: Test Grafana.com release publisher
command: 'cd scripts/build/release_publisher && go test .'
- persist_to_workspace:
root: /go/src/github.com/grafana/grafana
paths:
- dist/*

build-fast-save:
docker:
- image: grafana/build-container:1.2.6
working_directory: /go/src/github.com/grafana/grafana
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
- run:
name: debug cache
command: 'ls -al /go/src/github.com/grafana/grafana/node_modules'
- run:
name: prepare build tools
command: '/tmp/bootstrap.sh'
- run:
name: build grafana backend
command: './scripts/build/build.sh --fast --backend-only'
- run:
name: build grafana frontend
command: './scripts/build/build.sh --fast --frontend-only'
- save_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- /go/src/github.com/grafana/grafana/node_modules
- run:
name: package grafana
command: './scripts/build/build.sh --fast --package-only'
- run:
name: sign packages
command: './scripts/build/sign_packages.sh'
- run:
name: sha-sum packages
command: 'go run build.go sha-dist'
- run:
name: Test Grafana.com release publisher
command: 'cd scripts/build/release_publisher && go test .'
- persist_to_workspace:
root: .
paths:
- dist/*

grafana-docker-master:
machine:
image: circleci/classic:201808-01
Expand All @@ -224,7 +335,7 @@ jobs:
- run: docker info
- run: docker run --privileged linuxkit/binfmt:v0.6
- run: cp dist/grafana-latest.linux-*.tar.gz packaging/docker
- run: cd packaging/docker && ./build.sh "${CIRCLE_SHA1}"
- run: cd packaging/docker && ./build.sh --fast "${CIRCLE_SHA1}"

grafana-docker-release:
machine:
Expand Down Expand Up @@ -556,8 +667,15 @@ workflows:

build-branches-and-prs:
jobs:
- build:
- build-fast-backend:
filters: *filter-not-release-or-master
- build-fast-frontend:
filters: *filter-not-release-or-master
- build-fast-package:
filters: *filter-not-release-or-master
requires:
- build-fast-backend
- build-fast-frontend
- codespell:
filters: *filter-not-release-or-master
- backend-lint:
Expand All @@ -574,7 +692,7 @@ workflows:
filters: *filter-not-release-or-master
- grafana-docker-pr:
requires:
- build
- build-fast-package
- test-backend
- test-frontend
- codespell
Expand All @@ -585,7 +703,7 @@ workflows:
filters: *filter-not-release-or-master
- store-build-artifacts:
requires:
- build
- build-fast-package
- test-backend
- test-frontend
- codespell
Expand Down
1 change: 1 addition & 0 deletions packaging/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ FROM ${BASE_IMAGE}

ARG GF_UID="472"
ARG GF_GID="472"
ARG DEBIAN_FRONTEND=noninteractive

ENV PATH=/usr/share/grafana/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
GF_PATHS_CONFIG="/etc/grafana/grafana.ini" \
Expand Down
36 changes: 30 additions & 6 deletions packaging/docker/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/sh
BUILD_FAST=0

while [ "$1" != "" ]; do
case "$1" in
"--fast")
BUILD_FAST=1
echo "Fast build enabled"
shift
;;
* )
# unknown param causes args to be passed through to $@
break
;;
esac
done

_grafana_tag=${1:-}
_docker_repo=${2:-grafana/grafana}
Expand Down Expand Up @@ -27,19 +42,28 @@ docker_build () {
--no-cache=true .
}

docker_tag_linux_amd64 () {
repo=$1
tag=$2
docker tag "${_docker_repo}:${_grafana_version}" "${repo}:${tag}"
}

# Tag docker images of all architectures
docker_tag_all () {
repo=$1
tag=$2
docker tag "${_docker_repo}:${_grafana_version}" "${repo}:${tag}"
docker tag "${_docker_repo}-arm32v7-linux:${_grafana_version}" "${repo}-arm32v7-linux:${tag}"
docker tag "${_docker_repo}-arm64v8-linux:${_grafana_version}" "${repo}-arm64v8-linux:${tag}"
docker_tag_linux_amd64 $1 $2
if [ $BUILD_FAST = "0" ]; then
docker tag "${_docker_repo}-arm32v7-linux:${_grafana_version}" "${repo}-arm32v7-linux:${tag}"
docker tag "${_docker_repo}-arm64v8-linux:${_grafana_version}" "${repo}-arm64v8-linux:${tag}"
fi
}

docker_build "debian:stretch-slim" "grafana-latest.linux-x64.tar.gz" "${_docker_repo}:${_grafana_version}"
docker_build "arm32v7/debian:stretch-slim" "grafana-latest.linux-armv7.tar.gz" "${_docker_repo}-arm32v7-linux:${_grafana_version}"
docker_build "arm64v8/debian:stretch-slim" "grafana-latest.linux-arm64.tar.gz" "${_docker_repo}-arm64v8-linux:${_grafana_version}"

if [ $BUILD_FAST = "0" ]; then
docker_build "arm32v7/debian:stretch-slim" "grafana-latest.linux-armv7.tar.gz" "${_docker_repo}-arm32v7-linux:${_grafana_version}"
docker_build "arm64v8/debian:stretch-slim" "grafana-latest.linux-arm64.tar.gz" "${_docker_repo}-arm64v8-linux:${_grafana_version}"
fi
# Tag as 'latest' for official release; otherwise tag as grafana/grafana:master
if echo "$_grafana_tag" | grep -q "^v"; then
docker_tag_all "${_docker_repo}" "latest"
Expand Down
148 changes: 116 additions & 32 deletions scripts/build/build.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
#!/bin/bash

#
# This script is executed from within the container.
#

set -e

EXTRA_OPTS="$@"

##########
CCARMV6=/opt/rpi-tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
CCARMV7=arm-linux-gnueabihf-gcc
CCARM64=aarch64-linux-gnu-gcc
CCX64=/tmp/x86_64-centos6-linux-gnu/bin/x86_64-centos6-linux-gnu-gcc

##########
GOPATH=/go
REPO_PATH=$GOPATH/src/github.com/grafana/grafana
##########

BUILD_FAST=0
BUILD_BACKEND=1
BUILD_FRONTEND=1
BUILD_PACKAGE=1

while [ "$1" != "" ]; do
case "$1" in
"--fast")
BUILD_FAST=1
echo "Fast build enabled"
shift
;;
"--backend-only")
BUILD_FRONTEND=0
BUILD_PACKAGE=0
echo "Building only backend"
shift
;;
"--frontend-only")
BUILD_BACKEND=0
BUILD_PACKAGE=0
echo "Building only frontend"
shift
;;
"--package-only")
BUILD_BACKEND=0
BUILD_FRONTEND=0
echo "Building only packaging"
shift
;;
* )
# unknown param causes args to be passed through to $@
break
;;
esac
done

EXTRA_OPTS="$@"


cd /go/src/github.com/grafana/grafana
echo "current dir: $(pwd)"
Expand All @@ -31,31 +69,77 @@ fi
echo "Build arguments: $OPT"
echo "current dir: $(pwd)"

go run build.go -goarch armv6 -cc ${CCARMV6} ${OPT} build
go run build.go -goarch armv7 -cc ${CCARMV7} ${OPT} build
go run build.go -goarch arm64 -cc ${CCARM64} ${OPT} build

CC=${CCX64} go run build.go ${OPT} build

yarn install --pure-lockfile --no-progress

echo "Building frontend"
go run build.go ${OPT} build-frontend

if [ -d "dist" ]; then
rm -rf dist
function build_backend_linux_amd64() {
if [ ! -d "dist" ]; then
mkdir dist
fi
CC=${CCX64} go run build.go ${OPT} build
}

function build_backend() {
if [ ! -d "dist" ]; then
mkdir dist
fi

go run build.go -goarch armv6 -cc ${CCARMV6} ${OPT} build
go run build.go -goarch armv7 -cc ${CCARMV7} ${OPT} build
go run build.go -goarch arm64 -cc ${CCARM64} ${OPT} build
build_backend_linux_amd64
}

function build_frontend() {
if [ ! -d "dist" ]; then
mkdir dist
fi
yarn install --pure-lockfile --no-progress
echo "Building frontend"
go run build.go ${OPT} build-frontend
echo "FRONTEND: finished"
}

function package_linux_amd64() {
echo "Packaging Linux AMD64"
go run build.go -goos linux -pkg-arch amd64 ${OPT} package-only
go run build.go latest
echo "PACKAGE LINUX AMD64: finished"
}

function package_all() {
echo "Packaging ALL"
go run build.go -goos linux -pkg-arch armv6 ${OPT} -skipRpm package-only
go run build.go -goos linux -pkg-arch armv7 ${OPT} package-only
go run build.go -goos linux -pkg-arch arm64 ${OPT} package-only
package_linux_amd64
echo "PACKAGE ALL: finished"
}

function package_setup() {
echo "Packaging: Setup environment"
if [ -d "dist" ]; then
rm -rf dist
fi
mkdir dist
go run build.go -gen-version ${OPT} > dist/grafana.version
# Load ruby, needed for packing with fpm
source /etc/profile.d/rvm.sh
}

if [ $BUILD_FAST = "0" ]; then
build_backend
build_frontend
package_setup
package_all
else
if [ $BUILD_BACKEND = "1" ]; then
build_backend_linux_amd64
fi
if [ $BUILD_FRONTEND = "1" ]; then
build_frontend
fi
if [ $BUILD_PACKAGE = "1" ]; then
package_setup
package_linux_amd64
# last step
#go run build.go latest
fi
fi

mkdir dist
go run build.go -gen-version ${OPT} > dist/grafana.version

# Load ruby, needed for packing with fpm
source /etc/profile.d/rvm.sh

echo "Packaging"
go run build.go -goos linux -pkg-arch amd64 ${OPT} package-only
go run build.go -goos linux -pkg-arch armv6 ${OPT} -skipRpm package-only
go run build.go -goos linux -pkg-arch armv7 ${OPT} package-only
go run build.go -goos linux -pkg-arch arm64 ${OPT} package-only

go run build.go latest