This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Containerize RGW with minimal dependencies
- Add script to setup and manage the build environment. - Add script to build the radosgw binary. - Add script to build the s3gw container. Fixes: https://github.com/aquarist-labs/s3gw-core/issues/9 Signed-off-by: Volker Theile <[email protected]>
- Loading branch information
Showing
7 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
end_of_line = lf | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM opensuse/tumbleweed | ||
|
||
ENV CEPH_DIR=/srv/ceph | ||
|
||
RUN zypper -n install bash make nano vim git ccache cmake ninja | ||
COPY build-radosgw.sh /usr/bin/build-radosgw.sh | ||
|
||
VOLUME ["/srv/ceph"] | ||
ENTRYPOINT ["/usr/bin/build-radosgw.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
This README will guide you through the several steps to build the `s3gw` | ||
container image. | ||
|
||
# Prerequisite | ||
The build scripts expect the following directory hierarchy. | ||
|
||
``` | ||
| | ||
|- ceph/ | ||
| |- build/ | ||
| ... | ||
| | ||
|- s3gw-core/ | ||
|- build/ | ||
... | ||
``` | ||
|
||
If the Ceph Git repository is stored in a different path, then this | ||
can be customized via the `CEPH_DIR` environment variable. | ||
|
||
# Build the build environment | ||
To isolate the build system from your host, we provide a build environment | ||
based on openSUSE Tumbleweed. This containerized build environment will | ||
contain all necessary dependencies. | ||
|
||
## Install management tool | ||
To create the buidl environment, make sure to install all necessary | ||
tools. This can be done by running the command: | ||
|
||
``` | ||
$ cd ~/git/s3gw-core | ||
$ sudo buildenvadm.sh install | ||
``` | ||
|
||
## Create the build environment | ||
To create the containerized build environment run the following | ||
command: | ||
|
||
``` | ||
$ cd ~/git/s3gw-core | ||
$ buildenvadm.sh create | ||
``` | ||
|
||
The source code of Ceph will be mounted to `/srv/ceph` and the | ||
s3gw-core code is available at `/srv/s3gw-core`. | ||
|
||
## Start the build environment | ||
To start the build environment, run the following command: | ||
|
||
``` | ||
$ cd ~/git/s3gw-core | ||
$ buildenvadm.sh start | ||
``` | ||
|
||
You will be redirected to the `/srv/s3gw-core/build` directory within | ||
the containerized build environment. | ||
|
||
# Building radosgw binary | ||
If the binary is not compiled yet, simply run the following commands: | ||
|
||
``` | ||
# cd ~/git/s3gw-core | ||
# cd build | ||
# ./build-radosgw.sh | ||
``` | ||
|
||
If you are not running openSUSE Tumbleweed on your host, you can use | ||
the `Dockerfile.build-s3gw` file to setup a container that will | ||
automatically build the binary when the container is started. | ||
|
||
``` | ||
$ cd ~/git/s3gw-core/build | ||
$ podman build --tag build-s3gw -f ./Dockerfile.build-s3gw | ||
``` | ||
|
||
To trigger a build run, execute the following commands: | ||
``` | ||
$ cd ~/git/s3gw-core/build | ||
$ podman run --replace --name build-s3gw -v ../../ceph:/srv/ceph/ localhost/build-s3gw | ||
``` | ||
|
||
# Build the container image | ||
If the Ceph `radosgw` binary is compiled, the container image can be build | ||
with the following commands: | ||
|
||
``` | ||
# cd ~/git/s3gw-core | ||
# cd build | ||
# ./build-container.sh | ||
``` | ||
|
||
The container build script expects the `radosgw` binary at the relative | ||
path `../ceph/build/bin`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
BASE_IMAGE=${BASE_IMAGE:-"registry.opensuse.org/opensuse/tumbleweed:latest"} | ||
IMAGE_NAME=${IMAGE_NAME:-"s3gw"} | ||
CEPH_DIR=$(realpath ${CEPH_DIR:-"../../ceph/"}) | ||
INSTALL_PACKAGES=${INSTALL_PACKAGES:-"libblkid1 libexpat1 libtcmalloc4 libfmt8 libibverbs1 librdmacm1 liboath0 libicu70"} | ||
|
||
registry= | ||
registry_args= | ||
|
||
check_deps() { | ||
if [ ! $(which buildah) ]; then | ||
echo 'Unable to find "buildah". Please make sure it is installed.' | ||
exit 1 | ||
fi | ||
} | ||
|
||
build_container_image() { | ||
echo "Building container image ..." | ||
echo "BASE_IMAGE=${BASE_IMAGE}" | ||
echo "IMAGE_NAME=${IMAGE_NAME}" | ||
echo "CEPH_DIR=${CEPH_DIR}" | ||
|
||
tmpfile=$(mktemp) | ||
cat > ${tmpfile} << EOF | ||
ctr=\$(buildah from ${BASE_IMAGE}) | ||
buildah run \${ctr} /bin/sh -c 'zypper -n install ${INSTALL_PACKAGES}' | ||
mnt=\$(buildah mount \${ctr}) | ||
mkdir -p \${mnt}/data/ | ||
cp --verbose ${CEPH_DIR}/build/bin/radosgw \${mnt}/usr/bin/radosgw | ||
cp --verbose --no-dereference ${CEPH_DIR}/build/lib/*.so* \${mnt}/usr/lib64/ | ||
buildah unmount \${ctr} | ||
buildah config --volume /data/ \${ctr} | ||
buildah config --env ID=s3gw \${ctr} | ||
buildah config --env EXTRA_ARGS= \${ctr} | ||
buildah config --entrypoint "radosgw -d --no-mon-config --rgw-backend-store dbstore --id \${ID} --rgw-data /data/ --run-dir /run/ \${EXTRA_ARGS}" \${ctr} | ||
buildah commit --rm \${ctr} ${IMAGE_NAME} | ||
EOF | ||
buildah unshare sh ${tmpfile} | ||
rm -f ${tmpfile} | ||
|
||
if [ -n "${registry}" ]; then | ||
buildah push ${registry_args} localhost/${IMAGE_NAME} \ | ||
${registry}/${IMAGE_NAME} | ||
fi | ||
} | ||
|
||
while [ $# -ge 1 ]; do | ||
case $1 in | ||
--registry) | ||
registry=$2 | ||
shift | ||
;; | ||
--no-registry-tls) | ||
registry_args="--tls-verify=false" | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
check_deps | ||
build_container_image | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
CEPH_DIR=$(realpath ${CEPH_DIR:-"../../ceph/"}) | ||
CEPH_CMAKE_ARGS="-DENABLE_GIT_VERSION=ON -DWITH_PYTHON3=3 -DWITH_CCACHE=ON ${CEPH_CMAKE_ARGS}" | ||
CEPH_CMAKE_ARGS="-DWITH_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ${CEPH_CMAKE_ARGS}" | ||
CEPH_CMAKE_ARGS="-DWITH_RADOSGW_AMQP_ENDPOINT=OFF -DWITH_RADOSGW_KAFKA_ENDPOINT=OFF ${CEPH_CMAKE_ARGS}" | ||
CEPH_CMAKE_ARGS="-DWITH_RADOSGW_SELECT_PARQUET=OFF -DWITH_RADOSGW_MOTR=OFF ${CEPH_CMAKE_ARGS}" | ||
CEPH_CMAKE_ARGS="-DWITH_RADOSGW_DBSTORE=ON ${CEPH_CMAKE_ARGS}" | ||
NPROC=${NPROC:-$(nproc --ignore=2)} | ||
|
||
build_radosgw_binary() { | ||
echo "Building radosgw binary ..." | ||
echo "CEPH_DIR=${CEPH_DIR}" | ||
echo "NPROC=${NPROC}" | ||
|
||
cd ${CEPH_DIR} | ||
|
||
./install-deps.sh || true | ||
|
||
if [ -d "build" ]; then | ||
cd build/ | ||
cmake -DBOOST_J=${NPROC} ${CEPH_CMAKE_ARGS} .. | ||
else | ||
./do_cmake.sh ${CEPH_CMAKE_ARGS} | ||
cd build/ | ||
fi | ||
|
||
ninja -j${NPROC} bin/radosgw | ||
} | ||
|
||
build_radosgw_binary | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
BASE_IMAGE=${BASE_IMAGE:-"registry.opensuse.org/opensuse/tumbleweed:latest"} | ||
IMAGE_NAME=${IMAGE_NAME:-"s3gw-build-env"} | ||
CEPH_DIR=$(realpath ${CEPH_DIR:-"../ceph/"}) | ||
WORKING_DIR=$(pwd) | ||
CCACHE_DIR= | ||
|
||
usage() { | ||
cat <<EOF | ||
Manage the build environment. | ||
Usage: | ||
$(basename $0) [options] [command] | ||
Available Commands: | ||
create Create but do not start the build environment | ||
remove Remove the build environment | ||
start Start the build environment | ||
install Install all dependencies to create the build environment | ||
Options: | ||
-h, --help Show this message. | ||
EOF | ||
} | ||
|
||
check_deps() { | ||
if [ ! $(which buildah) ]; then | ||
echo 'Unable to find "buildah". Please make sure it is installed.' | ||
exit 1 | ||
fi | ||
if [ ! $(which podman) ]; then | ||
echo 'Unable to find "podman". Please make sure it is installed.' | ||
exit 1 | ||
fi | ||
} | ||
|
||
create() { | ||
ctr=$(buildah from ${BASE_IMAGE}) | ||
buildah run ${ctr} /bin/sh -c 'zypper -n install bash make nano vim git ccache cmake ninja' | ||
buildah run ${ctr} /bin/sh -c ' | ||
cat <<EOF >> ~/.inputrc | ||
"\C-[OA": history-search-backward | ||
"\C-[[A": history-search-backward | ||
"\C-[OB": history-search-forward | ||
"\C-[[B": history-search-forward | ||
EOF | ||
' | ||
buildah config --workingdir '/srv/s3gw-core/build/' ${ctr} | ||
buildah commit --rm ${ctr} ${IMAGE_NAME} | ||
} | ||
|
||
remove() { | ||
podman rm --ignore ${IMAGE_NAME} | ||
podman image rm ${IMAGE_NAME} | ||
} | ||
|
||
start() { | ||
EXTRA_ARGS= | ||
if [ -z "${CCACHE_DIR}" ]; then | ||
if [ -d ~/.ccache/ ]; then | ||
CCACHE_DIR=~/.ccache/s3gw-core | ||
mkdir -p ${CCACHE_DIR} | ||
fi | ||
fi | ||
if [ -n "${CCACHE_DIR}" ]; then | ||
echo "Using CCACHE_DIR=${CCACHE_DIR}" | ||
EXTRA_ARGS="--volume $(realpath ${CCACHE_DIR}):/root/.ccache/ ${EXTRA_ARGS}" | ||
fi | ||
podman run \ | ||
--interactive \ | ||
--tty \ | ||
--replace \ | ||
--privileged \ | ||
--volume ${WORKING_DIR}:/srv/s3gw-core/ \ | ||
--volume ${CEPH_DIR}:/srv/ceph/ \ | ||
--hostname ${IMAGE_NAME} \ | ||
--name ${IMAGE_NAME} \ | ||
${EXTRA_ARGS} \ | ||
${IMAGE_NAME} \ | ||
/bin/bash | ||
} | ||
|
||
install() { | ||
. /etc/os-release | ||
|
||
case "${ID}" in | ||
debian|ubuntu) | ||
dirname=Debian_${VERSION_ID} | ||
[ "${ID}" = "ubuntu" ] && dirname=xUbuntu_${VERSION_ID} | ||
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/${dirname}/ /" | sudo tee /etc/apt/sources.list.d/opensuse_devel_kubic_libcontainers_stable.list | ||
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/${dirname}/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/opensuse_devel_kubic_libcontainers_stable.gpg > /dev/null | ||
sudo apt-get -y update | ||
sudo apt-get -y install buildah podman | ||
;; | ||
opensuse*|suse|sles) | ||
sudo zypper -n install buildah podman | ||
;; | ||
esac | ||
} | ||
|
||
while getopts ":?h" option | ||
do | ||
case ${option} in | ||
h|help|?) | ||
usage >&2 | ||
exit 2 | ||
;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND-1)) | ||
|
||
case $@ in | ||
create) | ||
check_deps | ||
create | ||
;; | ||
remove) | ||
check_deps | ||
remove | ||
;; | ||
start) | ||
check_deps | ||
start | ||
;; | ||
install) | ||
install | ||
;; | ||
*) | ||
usage >&2 | ||
exit 2 | ||
;; | ||
esac | ||
|
||
exit 0 |