CI: build all distros and upload to S3

This commit is contained in:
Dmitry Maksyoma 2021-03-18 23:19:28 +13:00
parent 56fd118c43
commit f758fc5021
5 changed files with 165 additions and 10 deletions

View File

@ -0,0 +1,20 @@
#!/usr/bin/ruby
package_name = ARGV.first
DEB_PACKAGE_REGEX = %r!(?<os>[^/]+)/kasmvncserver_.+?_(?<arch>.+?).(?<format>deb)!
RPM_PACKAGE_REGEX = %r!(?<os>[^/]+)/kasmvncserver-.+?\.(?<arch>[^.]+).(?<format>rpm)!
if matches = package_name.match(DEB_PACKAGE_REGEX)
else matches = package_name.match(RPM_PACKAGE_REGEX)
end
os = matches["os"]
arch = matches["arch"]
package_format = matches["format"]
puts <<-EXPORT
export PACKAGE_OS=#{os}
export OS_ARCH=#{arch}
export PACKAGE_FORMAT=#{package_format}
EXPORT

25
.ci/next_release_version Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
set -e
version_from_tags() {
git tag | sort -r | head -1 | sed -e 's/^v//' -e 's/\-.\+//' | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'
}
branch_name="$1"
if [ -z "$branch_name" ]; then
echo >&2 "Usage: `basename $0` <branch_name>"
exit 1
fi
if echo "$branch_name" | grep -Pq '^release/([\d.]+)$'; then
RELEASE_BRANCH=1
fi
if [ -n "$RELEASE_BRANCH" ]; then
RELEASE_VERSION=$(echo "$branch_name" | sed 's!release/!!');
else
RELEASE_VERSION="$(version_from_tags)"
fi
echo "$RELEASE_VERSION"

40
.ci/upload.sh Normal file
View File

@ -0,0 +1,40 @@
#!/bin/bash
function prepare_upload_filename() {
local package="$1";
.ci/detect_os_arch_package_format "$package" > /tmp/os_arch_package_format;
source /tmp/os_arch_package_format;
detect_release_branch
if [ -n "$RELEASE_BRANCH" ]; then
export upload_filename="kasmvncserver_${PACKAGE_OS}_${RELEASE_VERSION}_${OS_ARCH}.${PACKAGE_FORMAT}";
else
export SANITIZED_BRANCH="$(echo $CI_COMMIT_REF_NAME | sed 's/\//_/g')";
export upload_filename="kasmvncserver_${PACKAGE_OS}_${RELEASE_VERSION}_${SANITIZED_BRANCH}_${CI_COMMIT_SHA:0:6}_${OS_ARCH}.${PACKAGE_FORMAT}";
fi
};
function upload_to_s3() {
local package="$1";
local upload_filename="$2";
# Transfer to S3
python3 amazon-s3-bitbucket-pipelines-python/s3_upload.py "${S3_BUCKET}" "$package" "${S3_BUILD_DIRECTORY}/${upload_filename}";
# Use the Gitlab API to tell Gitlab where the artifact was stored
export S3_URL="https://${S3_BUCKET}.s3.amazonaws.com/${S3_BUILD_DIRECTORY}/${upload_filename}";
export BUILD_STATUS="{\"key\":\"doc\", \"state\":\"SUCCESSFUL\", \"name\":\"${upload_filename}\", \"url\":\"${S3_URL}\"}";
curl --request POST --header "PRIVATE-TOKEN:${GITLAB_API_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/statuses/${CI_COMMIT_SHA}?state=success&name=build-url&target_url=${S3_URL}";
};
function prepare_to_run_scripts_and_s3_uploads() {
export DEBIAN_FRONTEND=noninteractive;
apt-get update;
apt-get install -y ruby2.7 git;
apt-get install -y python3 python3-pip python3-boto3 curl pkg-config libxmlsec1-dev;
git clone https://bitbucket.org/awslabs/amazon-s3-bitbucket-pipelines-python.git;
};
detect_release_branch() {
if echo $CI_COMMIT_REF_NAME | grep -Pq '^release/([\d.]+)$'; then
export RELEASE_BRANCH=1;
fi
}

View File

@ -4,9 +4,11 @@ services:
variables:
GITLAB_SHARED_DIND_DIR: /builds/$CI_PROJECT_PATH/shared
GIT_FETCH_EXTRA_FLAGS: --tags
stages:
- build
- upload
.prepare_build: &prepare_build
- ls -l
@ -19,22 +21,90 @@ stages:
- cp -r builder/build/* output/
- rm output/*.tar.gz
build_deb:
build_ubuntu_bionic:
stage: build
before_script:
- *prepare_build
after_script:
- *prepare_artfacts
script:
- echo "Always build Ubuntu 18"
- bash builder/build-distro ubuntu bionic
- if echo "$CI_COMMIT_BRANCH" | grep -Eq '(release|testing)'; then
echo "Build all distros";
bash builder/build-distro ubuntu focal;
bash builder/build-distro debian buster;
bash builder/build-distro debian bullseye;
bash builder/build-distro kali kali-rolling;
fi
- bash builder/build-package ubuntu bionic
artifacts:
paths:
- output/
build_ubuntu_focal:
stage: build
before_script:
- *prepare_build
after_script:
- *prepare_artfacts
script:
- bash builder/build-package ubuntu focal;
artifacts:
paths:
- output/
build_debian_buster:
stage: build
before_script:
- *prepare_build
after_script:
- *prepare_artfacts
script:
- bash builder/build-package debian buster;
artifacts:
paths:
- output/
build_debian_bullseye:
stage: build
before_script:
- *prepare_build
after_script:
- *prepare_artfacts
script:
- bash builder/build-package debian bullseye;
artifacts:
paths:
- output/
build_kali_rolling:
stage: build
before_script:
- *prepare_build
after_script:
- *prepare_artfacts
script:
- bash builder/build-package kali kali-rolling;
artifacts:
paths:
- output/
build_centos7:
stage: build
before_script:
- *prepare_build
after_script:
- *prepare_artfacts
script:
- bash builder/build-package centos core
artifacts:
paths:
- output/
upload:
stage: upload
image: ubuntu:focal
before_script:
- . .ci/upload.sh
script:
- export S3_BUILD_DIRECTORY="kasmvnc/${CI_COMMIT_SHA}"
- prepare_to_run_scripts_and_s3_uploads
- export RELEASE_VERSION=$(.ci/next_release_version "$CI_COMMIT_REF_NAME")
- for package in `find output/ -type f -name 'kasmvncserver_*.deb' -or -name '*.rpm'`; do
prepare_upload_filename "$package";
echo;
echo "File to upload $upload_filename";
upload_to_s3 "$package" "$upload_filename";
done