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

Improve build system #50

Merged
merged 4 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pipeline {
CWD = sh(script: 'pwd', , returnStdout: true).trim()
}
steps {
sh "docker run --name sysdig-inspect-builder -v ${CWD}:/usr/bin/sysdig-inspect -v /var/run/docker.sock:/var/run/docker.sock -e 'INSTALL_DEPS=true' -e 'PUBLISH_ARTIFACTS=true' -e 'GIT_BRANCH=${env.BRANCH_NAME}' -e 'USER_TRACKING_KEY=${env.INSPECT_USER_TRACKING_KEY}' ${env.BUILDER}"
sh "docker run --name sysdig-inspect-builder -v ${CWD}:/usr/bin/sysdig-inspect -v /var/run/docker.sock:/var/run/docker.sock -e 'INSTALL_DEPS=true' -e 'PUBLISH_ARTIFACTS=true' -e 'GIT_BRANCH=${env.BRANCH_NAME}' -e 'BUILD_NUMBER=${env.BUILD_NUMBER}' -e 'USER_TRACKING_KEY=${env.INSPECT_USER_TRACKING_KEY}' ${env.BUILDER}"
}
}

Expand Down
64 changes: 16 additions & 48 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ SYSDIG_VERSION="0.24.1"
# - ENVIRONMENT (default: development)
# - USER_TRACKING_KEY (default: empty)
# - BUILD_NUMBER
# - JOB_NAME
# - GIT_BRANCH (default: dev)
# - GIT_COMMIT (default: empty)
# - AT

setup_env() {
echo "Prepare environment..."
Expand Down Expand Up @@ -61,44 +58,35 @@ setup_env() {
then
GIT_BRANCH=dev
fi
if [ -z ${GIT_COMMIT} ]
if [ -z ${BUILD_NUMBER} ]
then
GIT_COMMIT=
BUILD_NUMBER=42
fi

set -u

INSPECT_VERSION=`cat VERSION`

# Disabling interactive progress bar, and spinners gains 2x performances
# as stated on https://twitter.com/gavinjoyce/status/691773956144119808
npm config set progress false
npm config set spin false

GIT_BRANCHNAME=$(echo ${GIT_BRANCH} | cut -d"/" -f2)

if [ "${GIT_BRANCHNAME}" = "master" ]; then
ENVIRONMENT=production
DOCKER_IMAGE_TAG=sysdig/sysdig-inspect:${INSPECT_VERSION}
else
DOCKER_IMAGE_TAG=sysdig/sysdig-inspect:${INSPECT_VERSION}-${GIT_BRANCHNAME}
fi
}

before_build() {
if [ -z ${GIT_COMMIT} ]; then
echo "Skip status check update"
INSPECT_USER_VERSION=`cat VERSION`
if [ "${ENVIRONMENT}" = "production" ]; then
INSPECT_VERSION=${INSPECT_USER_VERSION}
else
echo "Updating commit status check..."
INSPECT_VERSION=${INSPECT_USER_VERSION}.${BUILD_NUMBER}
fi

GH_STATUS="pending"
GH_DESCRIPTION="Build #${BUILD_NUMBER} started..."
GH_CONTEXT="jenkins/sysdig-inspect"
# Disabling interactive progress bar, and spinners gains 2x performances
# as stated on https://twitter.com/gavinjoyce/status/691773956144119808
npm config set progress false
npm config set spin false

curl 'https://api.github.com/repos/draios/sysdig-inspect/statuses/'"${GIT_COMMIT}"'?access_token='"${AT}"'' \
-H 'Content-Type: application/json' \
-X POST \
-d '{"state": "'"${GH_STATUS}"'", "context": "'"${GH_CONTEXT}"'", "description": "'"${GH_DESCRIPTION}"'", "target_url": "'"${GH_URL}"'"}'
if [ "${ENVIRONMENT}" = "production" ]; then
DOCKER_IMAGE_TAG=sysdig/sysdig-inspect:${INSPECT_VERSION}
else
DOCKER_IMAGE_TAG=sysdig/sysdig-inspect:${INSPECT_VERSION}-${GIT_BRANCHNAME}
fi
}

Expand Down Expand Up @@ -195,7 +183,7 @@ build() {
cp electron-out/Sysdig\ Inspect-darwin-x64.zip out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.zip
if [ "${BUILD_MAC_INSTALLER}" = "true" ]; then
mkdir -p out/mac/installers
cp electron-out/make/Sysdig\ Inspect-${INSPECT_VERSION}.dmg out/mac/installers/sysdig-inspect-${INSPECT_VERSION}-mac.dmg
cp electron-out/make/Sysdig\ Inspect-${INSPECT_USER_VERSION}.dmg out/mac/installers/sysdig-inspect-${INSPECT_VERSION}-mac.dmg
fi
fi
}
Expand All @@ -213,31 +201,11 @@ cleanup() {
fi
}

after_build() {
if [ -z ${GIT_COMMIT} ]; then
echo "Skip status check update"
else
echo "Updating commit status check..."

GH_STATUS="success"
GH_DESCRIPTION="Build #${BUILD_NUMBER} succeeded"
GH_URL="https://ci.draios.com/view/sysdig-inspect/job/${JOB_NAME}/${BUILD_NUMBER}/"
GH_CONTEXT="jenkins/sysdig-inspect"

curl 'https://api.github.com/repos/draios/sysdig-inspect/statuses/'"${GIT_COMMIT}"'?access_token='"${AT}"'' \
-H 'Content-Type: application/json' \
-X POST \
-d '{"state": "'"${GH_STATUS}"'", "context": "'"${GH_CONTEXT}"'", "description": "'"${GH_DESCRIPTION}"'", "target_url": "'"${GH_URL}"'"}'
fi
}

set -ex
setup_env
before_build
cleanup
install_dependencies
build
after_build
set +ex

echo "Done!"
91 changes: 72 additions & 19 deletions build/publish.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash

# Env parameters
# - BUILD_LINUX (default: true)
# - BUILD_CONTAINER (default: true)
# - BUILD_MAC (default: true)
# - BUILD_MAC_INSTALLER (default: false)
# - ENVIRONMENT (default: development)
# - GIT_BRANCH (default: dev)

setup_env() {
Expand All @@ -11,18 +16,51 @@ setup_env() {
#
# Set default variables
#
if [ -z ${BUILD_LINUX} ]
then
BUILD_LINUX=true
fi
if [ -z ${BUILD_CONTAINER} ]
then
BUILD_CONTAINER=true
fi
if [ -z ${BUILD_MAC} ]
then
BUILD_MAC=true
fi
if [ -z ${BUILD_MAC_INSTALLER} ]
then
BUILD_MAC_INSTALLER=false
fi
if [ -z ${ENVIRONMENT} ]
then
ENVIRONMENT=development
fi
if [ -z ${GIT_BRANCH} ]
then
GIT_BRANCH=dev
fi
if [ -z ${BUILD_NUMBER} ]
then
BUILD_NUMBER=42
fi

set -u

INSPECT_VERSION=`cat VERSION`

GIT_BRANCHNAME=$(echo ${GIT_BRANCH} | cut -d"/" -f2)

if [ "${GIT_BRANCHNAME}" = "master" ]; then
ENVIRONMENT=production
fi

INSPECT_USER_VERSION=`cat VERSION`
if [ "${ENVIRONMENT}" = "production" ]; then
INSPECT_VERSION=${INSPECT_USER_VERSION}
else
INSPECT_VERSION=${INSPECT_USER_VERSION}.${BUILD_NUMBER}
fi

if [ "${ENVIRONMENT}" = "production" ]; then
DOCKER_IMAGE_TAG=sysdig/sysdig-inspect:${INSPECT_VERSION}
else
DOCKER_IMAGE_TAG=sysdig/sysdig-inspect:${INSPECT_VERSION}-${GIT_BRANCHNAME}
Expand All @@ -32,30 +70,45 @@ setup_env() {
publish_artifacts() {
echo "Uploading artifacts to S3 dev..."

# Linux DEB package
aws s3 cp out/linux/installers/sysdig-inspect_${INSPECT_VERSION}_amd64.deb s3://download.draios.com/dev/sysdig-inspect/${GIT_BRANCHNAME}/sysdig-inspect_${INSPECT_VERSION}_amd64.deb --acl public-read
if [ "${GIT_BRANCH}" = "master" ]; then
aws s3 cp out/linux/installers/sysdig-inspect_${INSPECT_VERSION}_amd64.deb s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect_${INSPECT_VERSION}_amd64.deb --acl public-read
aws s3 cp out/linux/installers/sysdig-inspect_${INSPECT_VERSION}_amd64.deb s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect_latest_amd64.deb --acl public-read
if [ "${BUILD_LINUX}" = "true" ]; then
# Linux DEB package
aws s3 cp out/linux/installers/sysdig-inspect_${INSPECT_USER_VERSION}_amd64.deb s3://download.draios.com/dev/sysdig-inspect/${GIT_BRANCHNAME}/sysdig-inspect_${INSPECT_VERSION}_amd64.deb --acl public-read
if [ "${ENVIRONMENT}" = "production" ]; then
aws s3 cp out/linux/installers/sysdig-inspect_${INSPECT_USER_VERSION}_amd64.deb s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect_${INSPECT_VERSION}_amd64.deb --acl public-read
aws s3 cp out/linux/installers/sysdig-inspect_${INSPECT_USER_VERSION}_amd64.deb s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect_latest_amd64.deb --acl public-read
fi

# Linux RPM package
aws s3 cp out/linux/installers/sysdig-inspect-${INSPECT_USER_VERSION}.x86_64.rpm s3://download.draios.com/dev/sysdig-inspect/${GIT_BRANCHNAME}/sysdig-inspect-${INSPECT_VERSION}.x86_64.rpm --acl public-read
if [ "${ENVIRONMENT}" = "production" ]; then
aws s3 cp out/linux/installers/sysdig-inspect-${INSPECT_USER_VERSION}.x86_64.rpm s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-${INSPECT_VERSION}.x86_64.rpm --acl public-read
aws s3 cp out/linux/installers/sysdig-inspect-${INSPECT_USER_VERSION}.x86_64.rpm s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-latest.x86_64.rpm --acl public-read
fi
fi

# Linux RPM package
aws s3 cp out/linux/installers/sysdig-inspect-${INSPECT_VERSION}.x86_64.rpm s3://download.draios.com/dev/sysdig-inspect/${GIT_BRANCHNAME}/sysdig-inspect-${INSPECT_VERSION}.x86_64.rpm --acl public-read
if [ "${GIT_BRANCH}" = "master" ]; then
aws s3 cp out/linux/installers/sysdig-inspect-${INSPECT_VERSION}.x86_64.rpm s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-${INSPECT_VERSION}.x86_64.rpm --acl public-read
aws s3 cp out/linux/installers/sysdig-inspect-${INSPECT_VERSION}.x86_64.rpm s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-latest.x86_64.rpm --acl public-read
if [ "${BUILD_MAC}" = "true" ]; then
# MAC zip bundle
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.zip s3://download.draios.com/dev/sysdig-inspect/${GIT_BRANCHNAME}/app/mac/sysdig-inspect-${INSPECT_VERSION}-mac.zip --acl public-read
if [ "${ENVIRONMENT}" = "production" ]; then
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.zip s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-${INSPECT_VERSION}-mac.zip --acl public-read
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.zip s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-latest-mac.zip --acl public-read
fi
fi

# MAC zip bundle
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.zip s3://download.draios.com/dev/sysdig-inspect/${GIT_BRANCHNAME}/app/mac/sysdig-inspect-${INSPECT_VERSION}-mac.zip --acl public-read
if [ "${GIT_BRANCH}" = "master" ]; then
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.zip s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-${INSPECT_VERSION}-mac.zip --acl public-read
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.zip s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-latest-mac.zip --acl public-read
if [ "${BUILD_MAC_INSTALLER}" = "true" ]; then
# MAC zip bundle
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.dmg s3://download.draios.com/dev/sysdig-inspect/${GIT_BRANCHNAME}/app/mac/sysdig-inspect-${INSPECT_VERSION}-mac.dmg --acl public-read
if [ "${GIT_BRANCH}" = "master" ]; then
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.dmg s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-${INSPECT_VERSION}-mac.dmg --acl public-read
aws s3 cp out/mac/binaries/sysdig-inspect-${INSPECT_VERSION}-mac.dmg s3://download.draios.com/stable/sysdig-inspect/sysdig-inspect-latest-mac.dmg --acl public-read
fi
fi

echo "Publishing image to Docker hub..."
if [ "${BUILD_CONTAINER}" = "true" ]; then
echo "Publishing image to Docker hub..."

docker push ${DOCKER_IMAGE_TAG}
docker push ${DOCKER_IMAGE_TAG}
fi
}

cleanup() {
Expand Down