Skip to content

Commit

Permalink
Build witness server linux packages
Browse files Browse the repository at this point in the history
Publish witness server docker images

rm test
  • Loading branch information
legleux authored and oleks-rip committed Jan 9, 2024
1 parent 0f8bc4a commit 8cfe062
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/actions/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM debian:11-slim

COPY xbridge_witnessd /opt/xbwd/bin/xbridge_witnessd
17 changes: 17 additions & 0 deletions .github/actions/package/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Package xbwd'
description: "Create packages of xchain witness server"
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build packages
shell: bash
run: ./Builds/CMake/packaging/build_packages.sh

- name: Upload packages
uses: actions/upload-artifact@v3
with:
name: xbwd_packages
path: packages
114 changes: 114 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: "Package xbridge_witnessd"
on:
push:
branches: ['main', 'release', 'develop', '*-rc*', '*-b*']
pull_request:
workflow_dispatch:

jobs:
package:
name: Build packages
runs-on: ubuntu-latest
container:
image: rippleci/xbwd-builder
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build packages
uses: ./.github/actions/package

- name: Save server
uses: actions/upload-artifact@v3
with:
name: xbwd
path: build/xbridge_witnessd

deploy_image:
runs-on: ubuntu-latest
name: Publish Docker images
needs: package
env:
# The repo on Docker Hub the image will get pushed to. GHCR will be set by ${{ github.repository_owner }}
DOCKERHUB_REPO: legleux
# The the "latest" image will be built from this branch
LATEST_BRANCH: main
IMAGE_NAME: xbwd
DH_CREDS: "${{ secrets.DOCKERHUB_USER }} ${{ secrets.DOCKERHUB_PW }}"
GH_CREDS: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: xbwd

- name: Set tags
id: tag_name
shell: bash
run: |
SHA=${GITHUB_SHA::7}
BASE_IMAGE_NAME=${IMAGE_NAME}:${SHA}
echo "BASE_IMAGE_NAME=${BASE_IMAGE_NAME}" >> $GITHUB_OUTPUT
BRANCH=${GITHUB_REF#refs/heads/}
DH_TAGS="${SHA} ${BRANCH}"
GH_TAGS="${SHA} ${BRANCH}"
DH_IMAGE_NAME=${DOCKERHUB_REPO}/${IMAGE_NAME}
echo "DH_IMAGE_NAME=${DH_IMAGE_NAME}" >> $GITHUB_OUTPUT
GH_IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}"
echo "GH_IMAGE_NAME=${GH_IMAGE_NAME}" >> $GITHUB_OUTPUT
if [[ $BRANCH == $LATEST_BRANCH ]]; then
echo "Tagging $BRANCH as 'latest'"
DH_TAGS+=" latest"
GH_TAGS+=" latest"
fi
echo "DH_TAGS=${DH_TAGS}" >> $GITHUB_OUTPUT
echo "GH_TAGS=${GH_TAGS}" >> $GITHUB_OUTPUT
- name: Build Docker image
shell: bash
run: |
IMAGE=${{ steps.tag_name.outputs.BASE_IMAGE_NAME }}
chmod +x xbridge_witnessd
docker build . -t ${IMAGE} --file .github/actions/image/Dockerfile
docker run --rm ${IMAGE} /opt/xbwd/bin/xbridge_witnessd --version
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PW }}

- name: Push to dockerhub
shell: bash
run: |
for tag in ${{ steps.tag_name.outputs.DH_TAGS }}; do
echo "Tagging ${{ steps.tag_name.outputs.BASE_IMAGE_NAME}} to ${{ steps.tag_name.outputs.DH_IMAGE_NAME }}:${tag} for Docker Hub"
docker tag ${{ steps.tag_name.outputs.BASE_IMAGE_NAME}} ${{ steps.tag_name.outputs.DH_IMAGE_NAME }}:${tag}
echo "Pushing ${{ steps.tag_name.outputs.DH_IMAGE_NAME}}:${tag} to Docker Hub"
docker push ${{ steps.tag_name.outputs.DH_IMAGE_NAME}}:${tag}
done
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push to ghcr
shell: bash
run: |
for tag in ${{ steps.tag_name.outputs.GH_TAGS }}; do
echo "Tagging ${{ steps.tag_name.outputs.BASE_IMAGE_NAME}} to ${{ steps.tag_name.outputs.GH_IMAGE_NAME }}:${tag} for GHCR"
docker tag ${{ steps.tag_name.outputs.BASE_IMAGE_NAME}} ${{ steps.tag_name.outputs.GH_IMAGE_NAME }}:${tag}
echo "Pushing ${{ steps.tag_name.outputs.GH_IMAGE_NAME }}:${tag} to GHCR"
docker push ${{ steps.tag_name.outputs.GH_IMAGE_NAME }}:${tag}
done
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
build
.nih_c
.vs
__pycache__
packages

# Conan presets
CMakeUserPresets.json

# pyenv virtualenv
.python-version

.vscode/
15 changes: 15 additions & 0 deletions Builds/CMake/XBridgeWitnessVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[===================================================================[
read version from source
#]===================================================================]

file (STRINGS src/xbwd/app/BuildInfo.cpp BUILD_INFO)
foreach (line_ ${BUILD_INFO})
if (line_ MATCHES "versionString[ ]*=[ ]*\"(.+)\"")
set (xbwd_version ${CMAKE_MATCH_1})
endif ()
endforeach ()
if (xbwd_version)
message (STATUS "XBridgeWitness version: ${xbwd_version}")
else ()
message (FATAL_ERROR "unable to determine XBridgeWitness version")
endif ()
66 changes: 66 additions & 0 deletions Builds/CMake/packaging/build_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -ex

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
src_dir=${SCRIPT_DIR}/../../..
bin_dir="${src_dir}/build"
pkg_dir="${src_dir}/packages"
build_config=Release
conan_packages_to_build="missing"
#conan_profile="default"
nproc=$(($(nproc) - 2))

if [ $nproc -lt 3 ]; then
nproc=$(nproc)
fi
exe="xbridge_witnessd"

. /etc/os-release
if [ $ID = centos ]; then
source /opt/rh/devtoolset-11/enable
source /opt/rh/rh-python38/enable
conan_packages_to_build="" # blank bc all dependencies need to be built for CentOS 7 currently
#conan_profile="centos" # TODO: Make a "centos" profile and upload the bin pkgs
#conan remote add --insert 0 conan-non-prod http://18.143.149.228:8081/artifactory/api/conan/conan-non-prod || true
fi

conan profile new default --detect
conan profile update settings.compiler.cppstd=20 default
conan profile update settings.compiler.libcxx=libstdc++11 default

conan install ${src_dir} \
--output-folder "${bin_dir}" \
--install-folder "${bin_dir}" \
--build ${conan_packages_to_build} \
--settings build_type=${build_config}

cmake \
-S "${src_dir}" \
-B "${bin_dir}" \
-DCMAKE_BUILD_TYPE=${build_config} \
-DPKG=deb \
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake

cmake \
--build "${bin_dir}" \
--parallel $nproc \
--target ${exe} \
--target package

cmake \
-S "${src_dir}" \
-B "${bin_dir}" \
-DCMAKE_BUILD_TYPE=${build_config} \
-DPKG=rpm \
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake

cmake \
--build "${bin_dir}" \
--parallel $nproc \
--target package

if [ $build_config = "Release" ]; then
strip ${bin_dir}/${exe}
fi

rm -rf ${pkg_dir}/_CPack_Packages
23 changes: 23 additions & 0 deletions Builds/CMake/packaging/deb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://github.com/seelabs/xbridge_witness")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "rippled")
set(CPACK_DEBIAN_PACKAGE_DEBUG ON)
set(CPACK_SYSTEM_NAME "amd64")
set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CPACK_SYSTEM_NAME})
set(CPACK_DEBIAN_PACKAGE_RELEASE 1)
set(RIPPLED_VERSION ${CPACK_PACKAGE_VERSION})
message("CPACK_PACKAGE_VERSION: ${CPACK_PACKAGE_VERSION}")
string(REPLACE "-" ";" VERSION_LIST ${CPACK_PACKAGE_VERSION})
message("VERSION_LIST: ${VERSION_LIST}")
list(GET VERSION_LIST 0 CPACK_PACKAGE_VERSION)
list (LENGTH VERSION_LIST _len)

if (${_len} GREATER 1)
list(GET VERSION_LIST 1 PRE_VERSION)
message("PRE_VERSION: ${PRE_VERSION}")
set(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}~${PRE_VERSION}")
else()
set(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
endif()
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${CPACK_SYSTEM_NAME}")
23 changes: 23 additions & 0 deletions Builds/CMake/packaging/package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include(GNUInstallDirs)
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR "Ripple")
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/xbwd")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "xchain witness")
include(XBridgeWitnessVersion)
set(CPACK_PACKAGE_VERSION "${xbwd_version}")
set(CPACK_PACKAGE_VENDOR "Ripple")
set(CPACK_PACKAGE_CONTACT "Ripple Labs Inc. <[email protected]>")
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_SOURCE_DIR}/packages)

if(${PKG} STREQUAL deb)
include(packaging/deb)
elseif(${PKG} STREQUAL rpm)
include(packaging/rpm)
else()
message(ERROR "No package type provided!")
endif()
message("Building ${PKG} package.")

set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_BINARY_DIR})

include(CPack)
26 changes: 26 additions & 0 deletions Builds/CMake/packaging/rpm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_policy(SET CMP0057 NEW)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_DEBUG ON)

set(CPACK_SYSTEM_NAME "x86_64")
set(CPACK_RPM_INSTALL_WITH_EXEC ON)
set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX /src_dir)
set(CPACK_RPM_DEBUGINFO_PACKAGE ON)
set(CPACK_RPM_PACKAGE_DEBUG ON)
set(CPACK_BUILD_SOURCE_DIRS ${CMAKE_SOURCE_DIR}/src/xbwd)
set(CPACK_RPM_PACKAGE_RELEASE_DIST "el7")
set(RIPPLED_VERSION ${CPACK_PACKAGE_VERSION})
string(REPLACE "-" ";" VERSION_LIST ${CPACK_PACKAGE_VERSION})
list(GET VERSION_LIST 0 CPACK_RPM_PACKAGE_VERSION)

message("CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION}")
message("VERSION_LIST ${VERSION_LIST}")
list (LENGTH VERSION_LIST _len)
if (${_len} GREATER 1)
list(GET VERSION_LIST 1 PRE_VERSION)
message("PRE_VERSION: ${PRE_VERSION}")
set(CPACK_RPM_PACKAGE_RELEASE "0.1${CPACK_RPM_PACKAGE_RELEASE}.${PRE_VERSION}")
else()
set(CPACK_RPM_PACKAGE_RELEASE "1${CPACK_RPM_PACKAGE_RELEASE}")
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
endif()
15 changes: 15 additions & 0 deletions Builds/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM centos:7 as builder

ARG CMAKE_VERSION=3.27.7
ARG GIT_VERSION=2.42.0
# https://github.com/docker/buildx/issues/379
RUN ulimit -n 1024000 && yum update -y

COPY ./setup_centos.sh /tmp/setup_centos.sh
RUN /tmp/setup_centos.sh

COPY ./build_git.sh /tmp/build_git.sh
RUN /tmp/build_git.sh ${GIT_VERSION}

COPY ./install_cmake.sh /tmp/install_cmake.sh
RUN /tmp/install_cmake.sh ${CMAKE_VERSION}
22 changes: 22 additions & 0 deletions Builds/docker/build_git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -ex
GIT_VERSION=${GIT_VERSION:-"2.42.0"}
tar_file=${GIT_VERSION}.tar.gz
curl -OJL https://github.com/git/git/archive/refs/tags/v${tar_file}
tar zxvf git-${tar_file} && rm git-${tar_file}

cd git-${GIT_VERSION}

. /etc/os-release
if [ $ID = centos ]; then
source /opt/rh/devtoolset-11/enable
fi

make configure
./configure
make git -j$(nproc)
make install git
cd ..
rm -rf git-${GIT_VERSION}
git --version | cut -d ' ' -f3
14 changes: 14 additions & 0 deletions Builds/docker/install_cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -ex

CMAKE_VERSION=${CMAKE_VERSION:-"3.27.7"}

IFS='.' read -ra CMAKE_VERSION_ARRAY <<< $CMAKE_VERSION
read -r CMAKE_MAJ_VERSION CMAKE_MIN_VERSION CMAKE_PATCH_VERSIONc <<< ${CMAKE_VERSION_ARRAY[@]}
CMAKE_SCRIPT="cmake-${CMAKE_VERSION}-linux-x86_64.sh"

curl -OJL "https://cmake.org/files/v${CMAKE_MAJ_VERSION}.${CMAKE_MIN_VERSION}/${CMAKE_SCRIPT}"
chmod +x "${CMAKE_SCRIPT}"

./"${CMAKE_SCRIPT}" --skip-license --prefix=/usr/local
rm "${CMAKE_SCRIPT}"
21 changes: 21 additions & 0 deletions Builds/docker/setup_centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -ex

# https://github.com/docker/buildx/issues/379
ulimit -n 1024000

yum update -y
yum upgrade -y
yum install -y epel-release centos-release-scl
yum install -y \
cmake wget \
rpm-build gnupg \
rh-python38 \
devtoolset-11 \
libstdc++-static \
automake pkgconfig gettext libcurl-devel
yum clean all
rm -rf /var/cache/yum

source /opt/rh/rh-python38/enable
pip install "conan<2"
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ add_executable (${PROJECT_NAME}
${UNIT_TESTS}
)

install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)

target_compile_options(${PROJECT_NAME} PUBLIC "-fstack-protector-strong")
if (is_linux)
target_link_options(${PROJECT_NAME} PUBLIC "LINKER:-z,relro,-z,now")
Expand Down Expand Up @@ -259,3 +261,5 @@ endif ()
get_target_property(FMT_INC_DIRS fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
list (GET FMT_INC_DIRS 0 FMT_INC_DIR)
target_include_directories(${PROJECT_NAME} BEFORE PRIVATE ${FMT_INC_DIR})

include(packaging/package)
Loading

0 comments on commit 8cfe062

Please sign in to comment.