Fix dev container

Revert some of the changes done as part of
12196656d4 and refine the scripts.
This commit is contained in:
Sébastien Deleuze
2024-12-30 14:58:30 +01:00
parent cf33bc0043
commit 2f7c21ad21
9 changed files with 205 additions and 1 deletions

15
images/Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM ubuntu:focal
ADD setup.sh /setup.sh
ADD get-crac-jdk-url.sh /get-crac-jdk-url.sh
ADD get-docker-url.sh /get-docker-url.sh
ADD get-ytt-url.sh /get-ytt-url.sh
ADD get-docker-compose-url.sh /get-docker-compose-url.sh
ADD get-gradle-url.sh /get-gradle-url.sh
RUN ./setup.sh
ENV JAVA_HOME /opt/crac-jdk
ENV PATH $JAVA_HOME/bin:/opt/ytt/bin:/opt/docker-compose/bin:/opt/gradle/bin:$PATH
ENV GRADLE_OPTS -Dorg.gradle.project.buildDir=/tmp/gradle-build
RUN git config --global --add safe.directory /workspace
ADD docker-lib.sh /docker-lib.sh

97
images/docker-lib.sh Executable file
View File

@@ -0,0 +1,97 @@
# Based on: https://github.com/concourse/docker-image-resource/blob/master/assets/common.sh
DOCKER_LOG_FILE=${DOCKER_LOG_FILE:-/tmp/docker.log}
SKIP_PRIVILEGED=${SKIP_PRIVILEGED:-false}
STARTUP_TIMEOUT=${STARTUP_TIMEOUT:-120}
sanitize_cgroups() {
mkdir -p /sys/fs/cgroup
mountpoint -q /sys/fs/cgroup || \
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
mount -o remount,rw /sys/fs/cgroup
sed -e 1d /proc/cgroups | while read sys hierarchy num enabled; do
if [ "$enabled" != "1" ]; then
# subsystem disabled; skip
continue
fi
grouping="$(cat /proc/self/cgroup | cut -d: -f2 | grep "\\<$sys\\>")" || true
if [ -z "$grouping" ]; then
# subsystem not mounted anywhere; mount it on its own
grouping="$sys"
fi
mountpoint="/sys/fs/cgroup/$grouping"
mkdir -p "$mountpoint"
# clear out existing mount to make sure new one is read-write
if mountpoint -q "$mountpoint"; then
umount "$mountpoint"
fi
mount -n -t cgroup -o "$grouping" cgroup "$mountpoint"
if [ "$grouping" != "$sys" ]; then
if [ -L "/sys/fs/cgroup/$sys" ]; then
rm "/sys/fs/cgroup/$sys"
fi
ln -s "$mountpoint" "/sys/fs/cgroup/$sys"
fi
done
if ! test -e /sys/fs/cgroup/systemd ; then
mkdir /sys/fs/cgroup/systemd
mount -t cgroup -o none,name=systemd none /sys/fs/cgroup/systemd
fi
}
start_docker() {
mkdir -p /var/log
mkdir -p /var/run
if [ "$SKIP_PRIVILEGED" = "false" ]; then
sanitize_cgroups
# check for /proc/sys being mounted readonly, as systemd does
if grep '/proc/sys\s\+\w\+\s\+ro,' /proc/mounts >/dev/null; then
mount -o remount,rw /proc/sys
fi
fi
local mtu=$(cat /sys/class/net/$(ip route get 8.8.8.8|awk '{ print $5 }')/mtu)
local server_args="--mtu ${mtu}"
local registry=""
server_args="${server_args}"
if [ -n "$1" ]; then
server_args="${server_args} --registry-mirror https://$1"
fi
try_start() {
dockerd --data-root /scratch/docker ${server_args} >$DOCKER_LOG_FILE 2>&1 &
echo $! > /tmp/docker.pid
sleep 1
echo waiting for docker to come up...
until docker info >/dev/null 2>&1; do
sleep 1
if ! kill -0 "$(cat /tmp/docker.pid)" 2>/dev/null; then
return 1
fi
done
}
export server_args DOCKER_LOG_FILE
declare -fx try_start
if ! timeout ${STARTUP_TIMEOUT} bash -ce 'while true; do try_start && break; done'; then
echo Docker failed to start within ${STARTUP_TIMEOUT} seconds.
return 1
fi
}

8
images/get-crac-jdk-url.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -e
case $ARCH in
aarch64) echo "https://download.bell-sw.com/java/17.0.13+13/bellsoft-jdk17.0.13+13-linux-aarch64-crac.tar.gz" ;;
*) echo "https://download.bell-sw.com/java/17.0.13+13/bellsoft-jdk17.0.13+13-linux-amd64-crac.tar.gz" ;;
esac

View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -e
VERSION="2.20.2"
echo "https://github.com/docker/compose/releases/download/v$VERSION/docker-compose-linux-$ARCH"

5
images/get-docker-url.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -e
VERSION="24.0.5"
echo "https://download.docker.com/linux/static/stable/$ARCH/docker-$VERSION.tgz"

5
images/get-gradle-url.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -e
VERSION="8.7"
echo "https://services.gradle.org/distributions/gradle-$VERSION-bin.zip"

9
images/get-ytt-url.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -e
VERSION=0.41.1
case $ARCH in
aarch64) FILE="ytt-linux-arm64" ;;
*) FILE="ytt-linux-amd64" ;;
esac
echo https://github.com/vmware-tanzu/carvel-ytt/releases/download/v$VERSION/$FILE

60
images/setup.sh Executable file
View File

@@ -0,0 +1,60 @@
#!/bin/bash
set -ex
export ARCH=$(uname -m)
###########################################################
# UTILS
###########################################################
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install --no-install-recommends -y tzdata ca-certificates net-tools libxml2-utils git curl libudev1 libxml2-utils iptables iproute2 jq unzip build-essential libz-dev libfreetype-dev nano libarchive-tools
ln -fs /usr/share/zoneinfo/UTC /etc/localtime
dpkg-reconfigure --frontend noninteractive tzdata
rm -rf /var/lib/apt/lists/*
curl https://raw.githubusercontent.com/spring-io/concourse-java-scripts/v0.0.4/concourse-java.sh > /opt/concourse-java.sh
mkdir -p /opt/ytt/bin
YTT_URL=$( ./get-ytt-url.sh )
curl --location $YTT_URL > /opt/ytt/bin/ytt
chmod +x /opt/ytt/bin/ytt
###########################################################
# CRaC JDK
###########################################################
CRAC_JDK_URL=$( ./get-crac-jdk-url.sh )
mkdir -p /opt/crac-jdk
cd /opt/crac-jdk
curl -L ${CRAC_JDK_URL} | tar zx --strip-components=1
test -f /opt/crac-jdk/bin/java
test -f /opt/crac-jdk/bin/javac
echo 'ulimit -n 1024' >> /root/.bashrc
###########################################################
# DOCKER
###########################################################
cd /
DOCKER_URL=$( ./get-docker-url.sh )
curl -L ${DOCKER_URL} | tar zx
mv /docker/* /bin/
chmod +x /bin/docker*
###########################################################
# DOCKER COMPOSE
###########################################################
mkdir -p /opt/docker-compose/bin
DOCKER_COMPOSE_URL=$( ./get-docker-compose-url.sh )
curl --location $DOCKER_COMPOSE_URL > /opt/docker-compose/bin/docker-compose
chmod +x /opt/docker-compose/bin/docker-compose
###########################################################
# GRADLE
###########################################################
GRADLE_URL=$( /get-gradle-url.sh )
mkdir -p /opt/gradle
cd /opt/gradle
curl -L $GRADLE_URL | bsdtar --strip-components=1 -xvf-
chmod +x /opt/gradle/bin/gradle

View File

@@ -49,6 +49,6 @@ done
docker image ls | grep spring-lifecycle-smoke-tests-dev >/dev/null 2>&1 || export REBUILD=true
test "$REBUILD" = false || docker build \
-t spring-lifecycle-smoke-tests-dev -f $HOST_WORK_DIR/ci/images/ci-image/Dockerfile $HOST_WORK_DIR/ci/images
-t spring-lifecycle-smoke-tests-dev -f $HOST_WORK_DIR/images/Dockerfile $HOST_WORK_DIR/images
docker run -it --rm --entrypoint /bin/bash --privileged -v $HOME/.m2:/root/.m2:ro -v $HOST_WORK_DIR:$CONTAINER_WORK_DIR:delegated -w $CONTAINER_WORK_DIR spring-lifecycle-smoke-tests-dev -c 'source /docker-lib.sh && start_docker && bash'