fierce-greece-10087
12/06/2024, 11:25 AMpants
build set up that I'm now satisfied with and I'd like to integrate it into our GitLab CI
pipelines. My intuition was to prepare a docker image, which would contain pants and docker-in-docker support, so I can do both package build, as well as docker image builds with this image. Is there already such an image somewhere? I found this, but it's 7 years old. Does what I'm trying to do even make sense or is there a better way? Any suggestions from those of you that are running pants in GitLab CI
pipelines? Thanks.curved-manchester-66006
12/06/2024, 2:05 PMMy intuition was to prepare a docker image, which would contain pants and docker-in-docker support, so I can do both package build, as well as docker image builds with this image. Is there already such an image somewhere?This is what we do internally. We have a bootstrapped "builder" image that we use for CI and devcontainers.
plain-author-67175
12/07/2024, 6:48 AMplain-author-67175
12/07/2024, 6:55 AMFROM docker:${DOCKER_DIND_VERSION} AS dind
FROM base AS ci
ARG BUILDARCH
ARG TINI_VERSION
ARG WORKING_DIR
# Install docker CLI and plugins
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update \
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
musl kmod iptables iproute2
RUN sudo groupadd docker && sudo usermod -aG docker <user>
COPY --from=dind /usr/local/bin/. /usr/local/bin/
COPY --from=dind /usr/libexec/docker/cli-plugins /usr/libexec/docker/cli-plugins
ADD <https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${BUILDARCH}> /tini
RUN sudo chmod +x /tini
# Install pants
ENV PATH="/home/<user>/.local/bin:$PATH"
RUN --mount=type=bind,source=get-pants.sh,target=${WORKING_DIR}/get-pants.sh \
--mount=type=bind,source=pants.toml,target=${WORKING_DIR}/pants.toml \
./get-pants.sh && pants version 2>&1 1> /dev/null || true
COPY --chmod=0755 <<'EOF' /usr/local/bin/entrypoint.sh
#!/bin/bash
set -e
start_dockerd() {
sudo mkdir -p /var/lib/docker-vfs
sudo mount -t tmpfs -o size=200G tmpfs /var/lib/docker-vfs
retries=0
max_retries=5
# Initialize an array for DNS entries
DNS_ENTRIES=()
# Populate the DNS_ENTRIES array if CUSTOM_DNS is non-empty
if [ -n "$CUSTOM_DNS" ]; then
IFS=',' read -r -a dns_array <<< "$CUSTOM_DNS"
for dns in "${dns_array[@]}"; do
DNS_ENTRIES+=(--dns="$dns")
done
fi
# Add CA cert to store if provided
if [ -n "$CUSTOM_CA_CERT" ]; then
sudo mkdir -p /usr/local/share/ca-certificates/
sudo cp $CUSTOM_CA_CERT /usr/local/share/ca-certificates/custom-ca.crt
sudo update-ca-certificates
fi
while true; do
echo "Starting Docker daemon (attempt $((retries + 1)))"
sleep 1
# Redirect stdout and stderr for this attempt
exec 3>&1 4>&2
exec > >(sudo tee /var/log/dockerd.log > /dev/null) 2>&1
sudo /usr/local/bin/dockerd-entrypoint.sh --data-root=/var/lib/docker-vfs --tls=false "${DNS_ENTRIES[@]}" &
BG_PID=$!
# Reset stdout and stderr after the invocation
exec 1>&3 2>&4
# Wait for the Docker socket to become available
echo -n "Waiting for Docker daemon..."
sleep 1
while ! docker info &>/dev/null; do
if ! ps -p $BG_PID > /dev/null; then
echo ""
echo "Docker daemon failed to start. Check /var/log/dockerd.log for details."
echo "********************************************************************************"
cat /var/log/dockerd.log
echo "********************************************************************************"
if [[ $retries -ge $max_retries ]]; then
echo ""
echo "Reached maximum retries. Docker daemon failed to start."
exit 1
fi
retries=$((retries + 1))
echo ""
echo "Retrying starting Docker daemon..."
break # Break from the inner loop to restart the daemon
fi
echo -n "."
sleep 0.1
done
if docker info &>/dev/null; then
echo ""
echo "Docker daemon started successfully."
break # Exit the outer loop if docker started successfully
fi
done
}
stop_dockerd() {
kill $BG_PID
wait $BG_PID 2>/dev/null
}
trap stop_dockerd EXIT
start_dockerd
exec "$@"
EOF
ENTRYPOINT ["/tini", "--", "/usr/local/bin/entrypoint.sh"]
CMD ["/bin/bash"]
fierce-greece-10087
12/08/2024, 7:58 PM