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

Ci/public apt #2291

Merged
merged 6 commits into from
Nov 22, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ jobs:
GITHUB_HUNTER_USERNAME=${{ secrets.HUNTER_USERNAME }} \
GITHUB_HUNTER_TOKEN=${{ secrets.HUNTER_TOKEN }} \
BUILDER_IMAGE_TAG=${{ env.BUILDER_LATEST_TAG }} \
GIT_REF_NAME=${{ env.GIT_REF_NAME }} \
BUILD_TYPE=${{ matrix.options.build_type }}

- name: "Push Kagome APT Package"
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ make debug_docker
make clear
```

### Installation from APT Package

To install KAGOME releases using the provided package repository, follow these steps (tested on Ubuntu 24.04.1 LTS (Noble Numbat)):

Update your package lists and install necessary utilities:

```sh
apt update && apt install -y gpg curl
```

Add the repository’s GPG signing key:

```sh
curl -fsSL https://europe-north1-apt.pkg.dev/doc/repo-signing-key.gpg | gpg --dearmor -o /usr/share/keyrings/europe-north-1-apt-archive-keyring.gpg
```

Add the KAGOME package repository to your sources list:
```sh
echo "deb [signed-by=/usr/share/keyrings/europe-north-1-apt-archive-keyring.gpg] https://europe-north1-apt.pkg.dev/projects/kagome-408211 kagome main" > /etc/apt/sources.list.d/kagome.list
```

Update the package lists and install KAGOME:

```sh
apt update && apt install -y kagome
```

### Using KAGOME

#### Obtaining database snapshot (optional)
Expand Down
25 changes: 19 additions & 6 deletions get_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# SPDX-License-Identifier: Apache-2.0
#

sanitize_version() {
echo "$1" | sed -E 's/[^a-zA-Z0-9.+~:-]/-/g'
}

realpath() {
if [ -d "$1" ]; then
cd "$1" && pwd
Expand All @@ -13,26 +17,31 @@ realpath() {
fi
}

cd $(dirname "$(realpath "$0")")
cd "$(dirname "$(realpath "$0")")"

SANITIZED=false
if [ "$#" -gt 0 ] && [ "$1" = "--sanitized" ]; then
SANITIZED=true
fi

if [ -x "$(which git 2>/dev/null)" ] && [ -e ".git" ]; then
if [ -x "$(which sed 2>/dev/null)" ]; then
HEAD=$(git rev-parse --short HEAD)
COMMON=$(git merge-base HEAD master)

DESCR=$(git describe --tags --long ${COMMON})
DESCR=$(git describe --tags --long "${COMMON}")
if [ "$DESCR" = "" ]; then
DESCR=$HEAD-0-g$HEAD
fi

TAG_IN_MASTER=$(echo $DESCR | sed -E "s/v?(.*)-([0-9]+)-g[a-f0-9]+/\1/")
TAG_TO_FORK_DISTANCE=$(echo $DESCR | sed -E "s/v?(.*)-([0-9]+)-g[a-f0-9]+/\2/")
TAG_IN_MASTER=$(echo "$DESCR" | sed -E "s/v?(.*)-([0-9]+)-g[a-f0-9]+/\1/")
TAG_TO_FORK_DISTANCE=$(echo "$DESCR" | sed -E "s/v?(.*)-([0-9]+)-g[a-f0-9]+/\2/")

BRANCH=$(git branch --show-current)
if [ "$BRANCH" = "" ]; then
BRANCH=$HEAD
fi
FORK_TO_HEAD_DISTANCE=$(git rev-list --count ${COMMON}..HEAD)
FORK_TO_HEAD_DISTANCE=$(git rev-list --count "${COMMON}..HEAD")

RESULT=$TAG_IN_MASTER
if [ "$TAG_TO_FORK_DISTANCE" != "0" ]; then
Expand All @@ -52,4 +61,8 @@ else
RESULT="Unknown(no git)"
fi

echo $RESULT
if [ "$SANITIZED" = true ]; then
RESULT=$(sanitize_version "$RESULT")
fi

echo "$RESULT"
2 changes: 2 additions & 0 deletions housekeeping/docker/kagome-dev/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*-versions.txt
*_version.txt
commit_hash.txt


cumulus
polkadot

Expand Down
42 changes: 28 additions & 14 deletions housekeeping/docker/kagome-dev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ PACKAGE_ARCHITECTURE ?= amd64
# Debug, Release, RelWithDebInfo
BUILD_TYPE ?= Release

# Generated versions
OS_IMAGE ?= $(OS_IMAGE_NAME):$(OS_IMAGE_TAG)@sha256:$(OS_IMAGE_HASH)
OS_IMAGE_TAG_WITH_HASH := $(OS_IMAGE_TAG)@sha256:$(OS_IMAGE_HASH)
OS_IMAGE_SHORT_HASH := $(shell echo $(OS_IMAGE_HASH) | cut -c1-7)
BUILDER_IMAGE_TAG ?= $(OS_IMAGE_SHORT_HASH)_rust$(RUST_VERSION)_gcc$(GCC_VERSION)_llvm$(LLVM_VERSION)
BUILDER_LATEST_TAG ?= latest
TESTER_LATEST_TAG ?= latest
DOCKERHUB_BUILDER_PATH ?= $(DOCKERHUB_REGISTRY_PATH)_builder

# kagome_dev_docker_build Variables
BUILD_DIR ?= build
CACHE_DIR := $(shell pwd)/../../../../kagome/$(BUILD_DIR)/cache
Expand All @@ -38,12 +29,23 @@ GITHUB_HUNTER_TOKEN ?=
CTEST_OUTPUT_ON_FAILURE ?= 1
WERROR ?= OFF

# Generated versions
OS_IMAGE ?= $(OS_IMAGE_NAME):$(OS_IMAGE_TAG)@sha256:$(OS_IMAGE_HASH)
OS_IMAGE_TAG_WITH_HASH := $(OS_IMAGE_TAG)@sha256:$(OS_IMAGE_HASH)
OS_IMAGE_SHORT_HASH := $(shell echo $(OS_IMAGE_HASH) | cut -c1-7)
BUILDER_IMAGE_TAG ?= $(OS_IMAGE_SHORT_HASH)_rust$(RUST_VERSION)_gcc$(GCC_VERSION)_llvm$(LLVM_VERSION)
BUILDER_LATEST_TAG ?= latest
TESTER_LATEST_TAG ?= latest
DOCKERHUB_BUILDER_PATH ?= $(DOCKERHUB_REGISTRY_PATH)_builder
KAGOME_SANITIZED_VERSION = $(shell cd $(WORKING_DIR) && ./get_version.sh --sanitized)

# kagome_runtime_cache and kagome_image_build Variables
KAGOME_PACKAGE_VERSION ?=
#KAGOME_RUNTIME_PACKAGE_VERSION ?=

# upload_apt_package Variables
ARTIFACTS_REPO ?= kagome-apt
PUBLIC_ARTIFACTS_REPO ?= kagome
REGION ?= europe-north1

# CI Variables
Expand All @@ -55,11 +57,11 @@ export DOCKER_BUILDKIT=1
# BUILDKIT_PROGRESS - auto, plain, tty, rawjson
export BUILDKIT_PROGRESS=auto


get_versions:
@echo "full_commit_hash: `git rev-parse HEAD`" | tee commit_hash.txt
@echo "short_commit_hash: `git rev-parse HEAD | head -c 7`" | tee -a commit_hash.txt
@echo "kagome_version: `cd $(WORKING_DIR) && ./get_version.sh`" | tee kagome_version.txt
@echo "kagome_sanitized_version: $(KAGOME_SANITIZED_VERSION)" | tee -a kagome_version.txt

builder_image_tag:
@echo $(BUILDER_IMAGE_TAG)
Expand Down Expand Up @@ -133,8 +135,17 @@ kagome_dev_docker_build:
$(PACKAGE_ARCHITECTURE) \
kagome-dev \
/tmp/kagome \
'Kagome Dev Debian Package' \
'$(DEPENDENCIES)' ; \
'Kagome Dev Ubuntu Package' \
'$(DEPENDENCIES)' && \
if [ "$(IS_MAIN_OR_TAG)" = "true" ] && [ "$(GIT_REF_NAME)" != "master" ] && [ "$(BUILD_TYPE)" = "Release" ]; then \
./build_apt_package.sh \
\"$(KAGOME_SANITIZED_VERSION)-$(BUILD_TYPE)\" \
$(PACKAGE_ARCHITECTURE) \
kagome \
/tmp/kagome \
'Kagome Ubuntu Package' \
'$(DEPENDENCIES)' ; \
fi; \
" || DOCKER_EXEC_RESULT=$$? ; \
if [ $$DOCKER_EXEC_RESULT -ne 0 ]; then \
echo "Error: Docker exec failed with return code $$DOCKER_EXEC_RESULT"; \
Expand Down Expand Up @@ -244,7 +255,10 @@ upload_apt_package:
SHORT_COMMIT_HASH=$$(grep 'short_commit_hash:' commit_hash.txt | cut -d ' ' -f 2); \
gcloud config set artifacts/repository $(ARTIFACTS_REPO); \
gcloud config set artifacts/location $(REGION); \
gcloud artifacts apt upload $(ARTIFACTS_REPO) --source=./pkg/kagome-dev_$$(date +'%y.%m.%d')-$${SHORT_COMMIT_HASH}-$(BUILD_TYPE)_$(PACKAGE_ARCHITECTURE).deb
gcloud artifacts apt upload $(ARTIFACTS_REPO) --source=./pkg/kagome-dev_$$(date +'%y.%m.%d')-$${SHORT_COMMIT_HASH}-$(BUILD_TYPE)_$(PACKAGE_ARCHITECTURE).deb ; \
if [ "$(IS_MAIN_OR_TAG)" = "true" ] && [ "$(GIT_REF_NAME)" != "master" ] && [ "$(BUILD_TYPE)" = "Release" ]; then \
gcloud artifacts apt upload $(PUBLIC_ARTIFACTS_REPO) --source=./pkg/kagome_$(KAGOME_SANITIZED_VERSION)-$(BUILD_TYPE)_$(PACKAGE_ARCHITECTURE).deb ; \
fi;

runtime_cache:
CONTAINER_NAME=kagome_dev_runtime_cache_$$(openssl rand -hex 6); \
Expand Down Expand Up @@ -274,7 +288,7 @@ runtime_cache:
$(PACKAGE_ARCHITECTURE) \
kagome-dev-runtime \
/tmp/kagome_runtime \
'Kagome Runtime Dev Debian Package' \
'Kagome Runtime Dev Ubuntu Package' \
'kagome-dev' \
/tmp/kagome/runtimes-cache/ ; \
" || DOCKER_EXEC_RESULT=$$? ; \
Expand Down
2 changes: 1 addition & 1 deletion housekeeping/docker/kagome-dev/build_apt_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mkdir -p ./pkg/${DIR_NAME}${BINARY_INSTALL_DIR}
log "Working directory: $(pwd)/pkg/"

log "Copying artifacts..."
mv -f ${ARTIFACTS_DIR}/* ./pkg/${DIR_NAME}${BINARY_INSTALL_DIR}/
cp -rf ${ARTIFACTS_DIR}/* ./pkg/${DIR_NAME}${BINARY_INSTALL_DIR}/

log "Package: ${PACKAGE_NAME}"
log "Version: ${VERSION}"
Expand Down
2 changes: 1 addition & 1 deletion zombienet/docker/build_apt_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mkdir -p ./pkg/${DIR_NAME}/DEBIAN
mkdir -p ./pkg/${DIR_NAME}/usr/local/bin

log "Copying artifacts..."
mv -f ${ARTIFACTS_DIR}/* ./pkg/${DIR_NAME}/usr/local/bin/
cp -rf ${ARTIFACTS_DIR}/* ./pkg/${DIR_NAME}/usr/local/bin/

log "Creating control file..."
cat <<EOF > ./pkg/${DIR_NAME}/DEBIAN/control
Expand Down