diff options
| -rw-r--r-- | Dockerfile.jenkins | 29 | ||||
| -rw-r--r-- | Jenkinsfile | 64 | ||||
| -rw-r--r-- | docker-compose.yml | 17 |
3 files changed, 110 insertions, 0 deletions
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
|
