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

Add almalinux 9 dev container #254

Merged
merged 2 commits into from
Nov 1, 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 dev/almalinux-8/build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

ALMALINUX_VERSION=8

Expand Down
1 change: 1 addition & 0 deletions dev/almalinux-8/create-and-start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

IDENT=${1-"0"}
ALMALINUX_VERSION=8
Expand Down
30 changes: 30 additions & 0 deletions dev/almalinux-9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

FROM docker.io/vespaengine/vespa-build-almalinux-9:latest

# Install sshd, man-db, nice-to-have packages and system test dependencies
RUN dnf -y install \
bind-utils \
openssh-server \
xorg-x11-xauth \
rsync \
nmap-ncat \
vim \
wget \
emacs \
gcc-toolset-13-gdb \
man-db \
man-pages \
hunspell-en \
kdesdk-kcachegrind \
python3-pip \
graphviz && \
pip3 install --upgrade pip && \
pip3 install numpy xgboost scikit-learn && \
dnf clean all --enablerepo=\*

RUN useradd -M -d /opt/vespa -s /usr/sbin/nologin vespa

STOPSIGNAL SIGRTMIN+3

CMD [ "/usr/sbin/init" ]
9 changes: 9 additions & 0 deletions dev/almalinux-9/build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

ALMALINUX_VERSION=9

IMG="vespaengine/vespa-dev-almalinux-${ALMALINUX_VERSION}:latest"

echo BUILDING: docker build -t ${IMG} "$@" .
docker build -t ${IMG} "$@" .
52 changes: 52 additions & 0 deletions dev/almalinux-9/configure-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

if [ $# -lt 2 ]; then
echo "Usage: $0 <container-engine> <container-name>"
exit 1
fi

engine=$1
container_name=$2

# Add yourself as user
$engine exec -it $container_name bash -c "groupadd -g $(id -g) $(id -gn)"
$engine exec -it $container_name bash -c "useradd -g $(id -g) -u $(id -u) $(id -un)"
$engine exec -it $container_name bash -c "echo '$(id -un) ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"

# Ensure home directory has correct owner and group
$engine exec -it $container_name bash -c "chown $(id -u):$(id -g) /home/$(id -un)"

# Ensure home directory has correct permissions
$engine exec -it $container_name bash -c "chmod 755 /home/$(id -un)"

# Copy authorized keys
$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c "mkdir -p /home/$(id -un)/.ssh"

if test -f $HOME/.ssh/authorized_keys; then
$engine cp -a $HOME/.ssh/authorized_keys $container_name:/home/$(id -un)/.ssh/
elif test -f $HOME/.ssh/id_rsa.pub; then
$engine cp -a $HOME/.ssh/id_rsa.pub $container_name:/home/$(id -un)/.ssh/authorized_keys
elif test -f $HOME/.ssh/id_ed25519.pub; then
$engine cp -a $HOME/.ssh/id_ed25519.pub $container_name:/home/$(id -un)/.ssh/authorized_keys
else
echo "ERROR: No authorized keys found in $HOME/.ssh"
exit 1
fi

# Set environment variables
$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c \
"printf \"%s\n\" \
'export LC_CTYPE=en_US.UTF-8' \
'export LC_ALL=en_US.UTF-8' \
'export VESPA_HOME=\$HOME/vespa' \
'PATH=\$PATH:\$HOME/bin:\$VESPA_HOME/bin:\$HOME/git/system-test/bin:/opt/vespa-deps/bin' \
'export PATH' \
'export MAVEN_OPTS=\"-Xms128m -Xmx1024m\"' \
'alias ctest=ctest3' \
> ~/.docker_profile"
$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c \
"grep -q '.docker_profile' ~/.bash_profile || echo 'test -f ~/.docker_profile && source ~/.docker_profile || true' >> ~/.bash_profile"

# Adjust ccache max size
$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c "ccache -M 20G"
107 changes: 107 additions & 0 deletions dev/almalinux-9/create-and-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

IDENT=${1-"0"}
ALMALINUX_VERSION=9
FORWARD_SSH_PORT=$((3900 + 10 * ${ALMALINUX_VERSION} + ${IDENT}))

cname="vespa-almalinux-${ALMALINUX_VERSION}"
container_name="${cname}-dev-${IDENT}"

img="docker.io/vespaengine/vespa-dev-almalinux-${ALMALINUX_VERSION}:latest"
docker pull $img

vol="volume-${container_name}"
docker volume ls | grep -q $vol || docker volume create $vol

network_name=vespa-testing
docker network ls | grep -q $network_name || docker network create $network_name

myuname=$(id -un)

echo "Creating docker container ${container_name}"
docker create \
--privileged \
-p 127.0.0.1:${FORWARD_SSH_PORT}:22 \
-v ${vol}:/home/${myuname} \
--name ${container_name} \
--network ${network_name} \
--hostname ${container_name}.vespa.local \
${img}

docker start ${container_name}

if [ -f etc.ssh.tar ]; then
docker exec -i ${container_name} tar -C / -xvpf - < etc.ssh.tar
fi

# Add your user if it does not exist already
docker exec -it ${container_name} bash -c "grep -q '^${myuname}:' /etc/passwd || useradd -s /bin/bash ${myuname}"

# Ensure your user has "sudo" rights
docker exec -it ${container_name} bash -c "echo ${myuname} 'ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"

# Ensure home directory has correct owner and group
docker exec -it ${container_name} bash -c "chown -R ${myuname}:${myuname} /home/${myuname}"

# Ensure home directory has correct permissions
docker exec -it ${container_name} bash -c "chmod 755 /home/${myuname}"

# Copy authorized keys
docker exec -u "${myuname}" -it ${container_name} bash -c "mkdir -p /home/${myuname}/.ssh"

if test -f $HOME/.ssh/authorized_keys; then
docker cp -a $HOME/.ssh/authorized_keys ${container_name}:/home/${myuname}/.ssh/
elif test -f $HOME/.ssh/id_rsa.pub; then
docker cp -a $HOME/.ssh/id_rsa.pub ${container_name}:/home/${myuname}/.ssh/authorized_keys
elif test -f $HOME/.ssh/id_ed25519.pub; then
docker cp -a $HOME/.ssh/id_ed25519.pub ${container_name}:/home/${myuname}/.ssh/authorized_keys
else
echo "ERROR: No authorized keys found in $HOME/.ssh"
exit 1
fi
docker exec -it ${container_name} bash -c "chown ${myuname}:${myuname} /home/${myuname}/.ssh/authorized_keys"

echo "Creating .docker_profile with appropriate environment variables"
# Set environment variables
docker exec -u "${myuname}" -it ${container_name} bash -c \
"printf \"%s\n\" \
'export VESPA_HOME=\$HOME/vespa' \
'PATH=\$PATH:\$HOME/bin:\$VESPA_HOME/bin:\$HOME/git/system-test/bin:/opt/vespa-deps/bin' \
'export PATH' \
'export JAVA_HOME='\`echo /usr/lib/jvm/java-17-openjdk-*\` \
'export MAVEN_OPTS=\"-Xms128m -Xmx1024m\"' \
> ~/.docker_profile; cat ~/.docker_profile"

docker exec -u "${myuname}" -it ${container_name} bash -c \
"grep -q '.docker_profile' ~/.bash_profile || echo 'test -f ~/.docker_profile && source ~/.docker_profile || true' >> ~/.bash_profile"

# Ensure home directory has correct owner and group (again)
docker exec -it ${container_name} bash -c "chown -R ${myuname}:${myuname} /home/${myuname}"

# Adjust ccache max size
docker exec -u "${myuname}" -it ${container_name} bash -c "ccache -M 20G"

if grep -q "Host $container_name" ~/.ssh/config; then
echo "Host $container_name already exists in ~/.ssh/config - not adding it again"
else
echo "Adding Host $container_name in your ~/.ssh/config redirecting via 127.0.0.1"
(
echo ""
echo "Host $container_name"
echo " Hostname 127.0.0.1"
echo " Port ${FORWARD_SSH_PORT}"
) >> ~/.ssh/config
fi

echo "Trying to connect to $container_name via ssh..."
gothn=$(ssh -o 'StrictHostKeyChecking accept-new' $container_name hostname)
if [ "$gothn" = ${container_name}.vespa.local ]; then
echo "SSH connection OK"
if ! [ -f etc.ssh.tar ]; then
echo "Saving generated host keys"
ssh $container_name sudo tar -C / -cf - '/etc/ssh/ssh_host_*' > etc.ssh.tar
fi
fi
echo "Logging in on new docker container $container_name ..."
ssh $container_name