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

Reproduce the Jenkins CI linux build locally #923

Open
5 of 7 tasks
j-rivero opened this issue May 16, 2023 · 4 comments
Open
5 of 7 tasks

Reproduce the Jenkins CI linux build locally #923

j-rivero opened this issue May 16, 2023 · 4 comments

Comments

@j-rivero
Copy link
Contributor

j-rivero commented May 16, 2023

It should be possible trying to reproduce a Linux build on Jenkins in a local system in a non very difficult way. They mainly consist in a Docker enviroment + build.sh script and a custom way of running them in using docker run parameters.

Roadmap:

  • Export Dockerfile and build.sh from each Linux build Export Dockerfile/build.sh as artifacts from each build  #279
  • Find a way to jump into the container if something fails to facilitate debugging Refactor build.sh initial lines and include SHELL_ON_ERRORS #1191
  • Fix hard-coded paths and values in Dockerfile and build.sh so a local system can run them without modifications. Goal is also to be able to run them using rocker and all the user developer tools via --home.
  • Use an easy way for running docker build + docker run with all the arguments setup correctly.
  • Find a quick way of setting the whole thing just by passing a Jenkins URL. Probably a gzdev small module.

Known problems:

  • build.sh: needs shebang to be run from plain ./ Add the /bin/bash shebang to build.sh #1177
  • ccache is disable by now
  • debbuilds:
    • /home/jenkins/workspace/xxx-debbuilder/build does not exist
    • /home/jenkins/workspace/sdformat15-debbuilder/pkgs not a directory but a file
@j-rivero
Copy link
Contributor Author

j-rivero commented May 16, 2023

Use an easy way for running docker build + docker run with all the arguments setup correctly.

docker build uses $USER/$GUI/$UID variables from active session. Can not find a way of using devcontainer.json file to include them.

Using docker compose it is also not fully clean since UID/GUI seems not easy to deal with:

services:
  jenkins-build:
    image: buildoo/jenkinsbuild
    build:
      context: .
      dockerfile: Dockerfile
      args:
        GID: ${GID}
        USERID: ${USERID}
        USER: ${USER}

Via:

USERID=$(id -u) GID=$(id -g) docker compose build
USERID=$(id -u) GID=$(id -g) docker compose run --rm -e DISPLAY=unix${DISPLAY} -v /sys:/sys:ro -v /tmp/.X11-unix:/tmp/.X11-unix:rw -e TERM=xterm-256color -v /dev/log:/dev/log:ro -v /run/log:/run/log:ro jenkins-build

@j-rivero
Copy link
Contributor Author

j-rivero commented May 16, 2024

While debugging an -install- type of job, I've been developing the compose configuration to something that is usable to reproduce the build locally for an X kind of job:

services:
  jenkins-build:
    image: buildoo/jenkinsbuild
    build:
      context: .
      dockerfile: Dockerfile
      args:
        GID: ${GID}
        USERID: ${USERID}
        USER: ${USER}
  run-jenkins-build:
    image: buildoo/jenkinsbuild
    stdin_open: true 
    tty: true
    environment:
        - DISPLAY=unix${DISPLAY}
        - TERM=xterm-256color
        - GID=${GID}
        - USERID=${USERID}
        - USER=${USER}
    volumes:
        - /sys:/sys:ro
        - /tmp/.X11-unix:/tmp/.X11-unix:rw
        - /dev/log:/dev/log:ro
        - /run/log:/run/log:ro
    entrypoint: ['./build.sh']

Via:

USERID=$(id -u) GID=$(id -g) docker compose build
USERID=$(id -u) GID=$(id -g) docker compose run --rm run-jenkins-build

That will reproduce the build of for example https://build.osrfoundation.org/job/ros_gzharmonic_bridge-install-pkg_iron-ci-jammy-amd64 . To obtain a debugging shell in the fail of the build.sh command, we will need to add to that script the bash trap:

trap "/bin/bash" 0 INT QUIT ABRT PIPE TERM

@j-rivero
Copy link
Contributor Author

j-rivero commented Aug 1, 2024

The noble images could be currently broken since they have a default ubuntu user with UID 1000. This could match the local user UID hence broken.

@j-rivero
Copy link
Contributor Author

j-rivero commented Nov 4, 2024

After #1191, the SHELL_ON_ERRORS var is ready, the code could be something like:

services:
  jenkins-build:
    image: buildoo/jenkinsbuild
    build:
      context: .
      dockerfile: Dockerfile
      args:
        GID: ${GID}
        USERID: ${USERID}
        USER: ${USER}
  run-jenkins-build:
    image: buildoo/jenkinsbuild
    stdin_open: true 
    tty: true
    environment:
        - DISPLAY=unix${DISPLAY}
        - TERM=xterm-256color
        - GID=${GID}
        - USERID=${USERID}
        - USER=${USER}
        - SHELL_ON_ERRORS=true
        - CCACHE_ENABLE=false
    volumes:
        - /sys:/sys:ro
        - /tmp/.X11-unix:/tmp/.X11-unix:rw
        - /dev/log:/dev/log:ro
        - /run/log:/run/log:ro
    entrypoint: ['./build.sh']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant