From 7c4b465d8c773b2e6282e78553c7c49e85e091d5 Mon Sep 17 00:00:00 2001 From: Andrew D. France Date: Tue, 22 Jul 2025 20:49:31 -0500 Subject: Added Jenkins files for local CI testing --- Dockerfile.jenkins | 29 +++++++++++++++++++++++++ Jenkinsfile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 17 +++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 Dockerfile.jenkins create mode 100644 Jenkinsfile create mode 100644 docker-compose.yml diff --git a/Dockerfile.jenkins b/Dockerfile.jenkins new file mode 100644 index 0000000..874941a --- /dev/null +++ b/Dockerfile.jenkins @@ -0,0 +1,29 @@ +# Dockerfile.jenkins +# Use the official Jenkins image as a base +FROM jenkins/jenkins:lts-jdk17 + +# Pass the Docker group ID from the host as a build argument +ARG DOCKER_GID + +# Switch to root user to install dependencies +USER root + +# Install Docker CLI so Jenkins can interact with the host's Docker daemon +RUN apt-get update && apt-get install -y lsb-release sudo +RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \ + https://download.docker.com/linux/debian/gpg +RUN echo "deb [arch=$(dpkg --print-architecture) \ + signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \ + https://download.docker.com/linux/debian \ + $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list +RUN apt-get update && apt-get install -y docker-ce-cli + +# Create a 'docker' group with the host's GID to match permissions +# This is the key step to prevent the container from exiting +RUN if [ -n "$DOCKER_GID" ]; then groupadd -g $DOCKER_GID docker; else groupadd -g 999 docker; fi + +# Add the 'jenkins' user to the docker group +RUN usermod -aG docker jenkins + +# Switch back to the jenkins user +USER jenkins diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..e8d568d --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,64 @@ +pipeline { + agent any + + stages { + stage('Build Docker Image') { + steps { + script { + echo 'Building the Docker image...' + // Build the Docker image from the Dockerfile in the current directory + // and tag it as 'lush-arch-test' + sh 'docker build -t lush-arch-test .' + } + } + } + stage('Run Tests in Container') { + steps { + script { + echo 'Running tests inside the Docker container...' + // Run the container with the 'lush-arch-test' image. + // The CMD in the Dockerfile will be executed. + // --rm automatically removes the container when it exits. + sh 'docker run --rm lush-arch-test' + } + } + } + stage('Run Owner-Provided Test Script') { + steps { + script { + echo 'Running the Lua 5.2 compatibility test script...' + // First, create the test script file + sh ''' + cat <<'EOF' > test_52.lua + -- Lua 5.2-specific features + local _ENV = { print = print, x = 123 } -- lexical environments + function show_x() + print("x =", x) + end + show_x() + -- Bitwise ops (added in 5.2) + local a, b = 0x5, 0x3 + print("Bitwise AND:", a & b) + -- load() replaces loadstring() (binary and text) + local f = load("return 10 + 20") + print("Loaded result:", f()) + -- table.pack / table.unpack + local t = table.pack(1, 2, 3, nil, 5) + print("Packed length:", t.n) + print("Unpacked values:", table.unpack(t)) + EOF + ''' + // Run the container and execute the owner's test script + sh 'docker run --rm -v $(pwd)/test_52.lua:/app/test_52.lua lush-arch-test ./bin/Debug/lush/lush test_52.lua' + } + } + } + } + post { + always { + echo 'Pipeline finished.' + // Clean up the created docker image to save space + sh 'docker rmi lush-arch-test || true' + } + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..77dfb90 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +# docker-compose.yml +services: + jenkins: + build: + context: . + dockerfile: Dockerfile.jenkins + args: + # Pass the host's docker group ID to the build + DOCKER_GID: ${DOCKER_GID} + user: "${UID}:${GID}" # Run the container as the current host user + ports: + - "8080:8080" + - "50000:50000" + container_name: jenkins + volumes: + - ./jenkins_home:/var/jenkins_home + - /var/run/docker.sock:/var/run/docker.sock -- cgit v1.2.3-59-g8ed1b