Skip to content
Snippets Groups Projects
Verified Commit 9c69fc27 authored by Konrad Botor's avatar Konrad Botor
Browse files

Added GitLab CI job for building and publishing the official image - ref. hive#434

parent dde14177
No related branches found
No related tags found
2 merge requests!827Merge develop changes to master,!588CI job that builds and pushes an official Hivemind image
......@@ -54,5 +54,3 @@ local.db
*.db
envfile
/deploy
Dockerfile
......@@ -98,6 +98,7 @@ envfile
venv/
ENV/
.venv/
.hivemind-venv/
# Spyder project settings
.spyderproject
......
stages:
- build
- sync-e2e-benchmark
- publish
- collector
- cleanup
include:
- project: hive/haf
ref: 7d52319046375526badc926587c26ba0431f388d # develop
file: /scripts/ci-helpers/prepare_data_image_job.yml
variables:
# HIVEMIND
RUNNER_HIVEMIND_SERVER_HTTP_PORT: 8080
......@@ -25,6 +21,11 @@ variables:
DATA_CACHE_MAINNET: /cache/replay_data_hivemind_${CI_PIPELINE_ID}
BLOCK_LOG_SOURCE_DIR_5M: /blockchain/block_log_5m
include:
- project: hive/haf
ref: 7d52319046375526badc926587c26ba0431f388d # develop
file: /scripts/ci-helpers/prepare_data_image_job.yml
workflow:
# do not create pipeline twice when merge requests is open on current branch
rules:
......@@ -165,7 +166,7 @@ workflow:
localhost \
$RUNNER_HIVEMIND_SERVER_HTTP_PORT \
$RUNNER_BENCHMARK_ITERATIONS \
$RUNNER_PYTEST_WORKERS
$RUNNER_PYTEST_WORKERS
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<| BASH SCRIPTS |<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
......@@ -178,6 +179,15 @@ prepare_haf_image:
SUBMODULE_DIR: "$CI_PROJECT_DIR/haf"
REGISTRY_USER: "$HAF_IMG_BUILDER_USER"
REGISTRY_PASS: "$HAF_IMG_BUILDER_PASSWORD"
before_script:
- git config --global --add safe.directory $CI_PROJECT_DIR/haf
tags: *shared_tags
prepare_hivemind_image:
stage: build
extends: .docker_image_builder_job_template
script:
- *instance-build-script
tags: *shared_tags
prepare_haf_data:
......@@ -281,6 +291,13 @@ sync_e2e_benchmark:
tags:
- hive-builder-4
publish_instance_image:
stage: publish
extends: .publish_docker_image_template
script:
- scripts/ci/build_and_publish_instance.sh
tags: *shared_tags
Trigger benchmark-results-collector:
stage: collector
needs: [ 'sync_e2e_benchmark' ]
......
......@@ -13,6 +13,7 @@ pip3 install pyyaml
# Do actual installation in the source directory
pushd "$SRCROOT"
git status
pip3 install .
# immediately initialize atomic package to avoid spawning compiler at final image
......
#! /bin/bash
SCRIPT_DIR=$(dirname "$(realpath "$0")")
SRC_DIR="$SCRIPT_DIR/../.."
print_help () {
echo "Usage: $0 OPTION[=VALUE]..."
echo
echo "Script for building Docker image of Hivemin instance and pushing it to GitLab registry and to Docker Hub"
echo "All options (except '--help') are required"
echo "OPTIONS:"
echo " --registry-user=USERNAME Docker registry user"
echo " --registry-password=PASS Docker registry user"
echo " --registry=URL Docker registry URL, eg. 'registry.gitlab.syncad.com'"
echo " --image-tag=TAG Docker image tag, in CI the same as Git tag"
echo " --image-name-prefix=PREFIX Docker image name prefix, eg. 'registry.gitlab.syncad.com/hive/hivemind'"
echo " --docker-hub-user=USERNAME Docker Hub username"
echo " --docker-hub-password=PASS Docker Hub password"
echo " -?/--help Display this help screen and exit"
echo
}
set -e
while [ $# -gt 0 ]; do
case "$1" in
--registry-user=*)
arg="${1#*=}"
CI_REGISTRY_USER="$arg"
;;
--registry-password=*)
arg="${1#*=}"
CI_REGISTRY_PASSWORD="$arg"
;;
--registry=*)
arg="${1#*=}"
CI_REGISTRY="$arg"
;;
--image-tag=*)
arg="${1#*=}"
CI_COMMIT_TAG="$arg"
;;
--image-name-prefix=*)
arg="${1#*=}"
CI_REGISTRY_IMAGE="$arg"
;;
--docker-hub-user=*)
arg="${1#*=}"
DOCKER_HUB_USER="$arg"
;;
--docker-hub-password=*)
arg="${1#*=}"
DOCKER_HUB_PASSWORD="$arg"
;;
--help)
print_help
exit 0
;;
-?)
print_help
exit 0
;;
*)
echo "ERROR: '$1' is not a valid option/positional argument"
echo
print_help
exit 2
;;
esac
shift
done
[[ -z "$CI_REGISTRY_USER" ]] && echo "Option '--registry-user' must be set" && print_help && exit 1
[[ -z "$CI_REGISTRY_PASSWORD" ]] && echo "Option '--registry-password' must be set" && print_help && exit 1
[[ -z "$CI_REGISTRY" ]] && echo "Option '--registry' must be set" && print_help && exit 1
[[ -z "$CI_COMMIT_TAG" ]] && echo "Option '--image-tag' must be set" && print_help && exit 1
[[ -z "$CI_REGISTRY_IMAGE" ]] && echo "Option '--image-name-prefix' must be set" && print_help && exit 1
[[ -z "$DOCKER_HUB_USER" ]] && echo "Option '--docker-hub-user' must be set" && print_help && exit 1
[[ -z "$DOCKER_HUB_PASSWORD" ]] && echo "Option '--docker-hub-password' must be set" && print_help && exit 1
CI_PROJECT_NAME="${CI_REGISTRY_IMAGE##*/}"
echo "Logging to Docker Hub and $CI_REGISTRY"
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_PASSWORD"
echo "Building an instance image in the source directory $SRC_DIR"
# Turn PEP 440-compliant version number into a Docker-compliant tag
#shellcheck disable=SC2001
TAG=$(echo "$CI_COMMIT_TAG" | sed 's/[!+]/-/g')
"$SRC_DIR/scripts/ci/build_instance.sh" \
"instance-$TAG" \
"$SRC_DIR" \
"$CI_REGISTRY_IMAGE/"
echo "Tagging the image built in the previous step as hiveio/$CI_PROJECT_NAME:$TAG"
docker tag "$CI_REGISTRY_IMAGE/instance:instance-$TAG" "hiveio/$CI_PROJECT_NAME:$TAG"
docker images
echo "Pushing the instance image to the Docker Hub and GitLab registries"
docker push "$CI_REGISTRY_IMAGE/instance:instance-$TAG"
docker push "hiveio/$CI_PROJECT_NAME:$TAG"
#! /bin/bash
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
SCRIPTSDIR="$SCRIPTPATH/.."
SCRIPTSDIR="$(dirname "$(realpath "$0")")/.."
LOG_FILE=build_instance.log
export LOG_FILE=build_instance.log
# shellcheck source=../haf/scripts/common.sh
source "$SCRIPTSDIR/../haf/scripts/common.sh"
BUILD_IMAGE_TAG=""
REGISTRY=""
SRCROOTDIR=""
IMAGE_TAG_PREFIX=""
print_help () {
echo "Usage: $0 <image_tag> <src_dir> <registry_url> [OPTION[=VALUE]]..."
......@@ -45,23 +43,22 @@ while [ $# -gt 0 ]; do
shift
done
TST_IMGTAG=${BUILD_IMAGE_TAG:?"Missing arg #1 to specify built image tag"}
TST_SRCDIR=${SRCROOTDIR:?"Missing arg #2 to specify source directory"}
TST_REGISTRY=${REGISTRY:?"Missing arg #3 to specify target container registry"}
[[ -z "$BUILD_IMAGE_TAG" ]] && echo "Variable BUILD_IMAGE_TAG must be set" && exit 1
[[ -z "$SRCROOTDIR" ]] && echo "Variable SRCROOTDIR must be set" && exit 1
[[ -z "$REGISTRY" ]] && echo "Variable REGISTRY must be set" && exit 1
echo "Moving into source root directory: ${SRCROOTDIR}"
pushd "$SRCROOTDIR"
pushd "$SRCROOTDIR" || exit 1
pwd
"$SRCROOTDIR/scripts/ci/fix_ci_tag.sh"
export DOCKER_BUILDKIT=1
docker build --platform=amd64 --target=instance \
--build-arg CI_REGISTRY_IMAGE=$REGISTRY \
-t ${REGISTRY}${IMAGE_TAG_PREFIX}instance${BUILD_IMAGE_TAG} -f Dockerfile .
popd
BUILD_OPTIONS=("--platform=amd64" "--target=instance" "--progress=plain")
docker buildx build "${BUILD_OPTIONS[@]}" \
--build-arg CI_REGISTRY_IMAGE="$REGISTRY" \
--tag "${REGISTRY}instance${BUILD_IMAGE_TAG}" \
--file Dockerfile .
popd || exit 1
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment