diff --git a/.devcontainer/append_to_bashrc.txt b/.devcontainer/append_to_bashrc.txt index dcc9f26..6fc9bf6 100644 --- a/.devcontainer/append_to_bashrc.txt +++ b/.devcontainer/append_to_bashrc.txt @@ -1,5 +1,7 @@ # Custom Alias alias src='source /opt/ros/jazzy/setup.bash && source /home/ws/install/setup.bash' +alias build='/home/ws/docker/build.sh' +alias test='build && sudo /home/act -j test-locally' # Integrate entrypoint.sh -source /home/ws/.devcontainer/entrypoint.sh \ No newline at end of file +source /home/ws/docker/entrypoint.sh \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 322825d..7780743 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,50 +1,53 @@ { - "name": "ROS 2 Development Container HelMoRo", - "privileged": true, - "remoteUser": "htkz", - "build": { - "dockerfile": "../docker/Dockerfile", - "context": "..", - "target": "dev", - "args": { - "USERNAME": "htkz" - } - }, - "workspaceFolder": "/home/ws", - "workspaceMount": "source=${localWorkspaceFolder},target=/home/ws,type=bind", - "customizations": { - "vscode": { - "extensions":[ - "ms-vscode.cpptools", - "ms-vscode.cpptools-themes", - "donjayamanne.python-extension-pack", - "eamodio.gitlens", - "ms-iot.vscode-ros", - "ms-azuretools.vscode-docker", - "ms-vscode.cmake-tools", - "github.vscode-github-actions" - ] - } - }, - "containerEnv": { - "DISPLAY": "unix:0", - "ROS_AUTOMATIC_DISCOVERY_RANGE": "LOCALHOST", - "ROS_DOMAIN_ID": "42", - "NVIDIA_DRIVER_CAPABILITIES": "all" - }, - "runArgs": [ - "--net=host", - "--pid=host", - "--ipc=host", - "-e", "DISPLAY=${env:DISPLAY}", - "--gpus=all", - "--runtime=nvidia" - ], - "mounts": [ - "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached", - "source=/dev/dri,target=/dev/dri,type=bind,consistency=cached", - "source=/dev/input,target=/dev/input,type=bind,consistency=delegated", - "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" - ], - "postCreateCommand": "sudo chown -R $(whoami) /home/ws/ && python3 /home/ws/.devcontainer/append_to_bashrc.py" + "name": "ROS 2 Development Container HelMoRo", + "privileged": true, + "remoteUser": "htkz", + "build": { + "dockerfile": "../docker/Dockerfile", + "context": "..", + "target": "dev", + "args": { + "USERNAME": "htkz" + }, + "options": [ + "--tag", "helmoro_dev" + ] + }, + "workspaceFolder": "/home/ws", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/ws,type=bind", + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cpptools-themes", + "donjayamanne.python-extension-pack", + "eamodio.gitlens", + "ms-iot.vscode-ros", + "ms-azuretools.vscode-docker", + "ms-vscode.cmake-tools", + "github.vscode-github-actions" + ] + } + }, + "containerEnv": { + "DISPLAY": "unix:0", + "ROS_AUTOMATIC_DISCOVERY_RANGE": "LOCALHOST", + "ROS_DOMAIN_ID": "42", + "NVIDIA_DRIVER_CAPABILITIES": "all" + }, + "runArgs": [ + "--net=host", + "--pid=host", + "--ipc=host", + "-e", "DISPLAY=${env:DISPLAY}", + "--gpus=all", + "--runtime=nvidia" + ], + "mounts": [ + "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached", + "source=/dev/dri,target=/dev/dri,type=bind,consistency=cached", + "source=/dev/input,target=/dev/input,type=bind,consistency=delegated", + "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" + ], + "postCreateCommand": "sudo chown -R $(whoami) /home/ws/ && sudo chown -R $(whoami) /var/run/docker.sock && python3 /home/ws/.devcontainer/append_to_bashrc.py" } \ No newline at end of file diff --git a/.github/workflows/ci-local.yml b/.github/workflows/ci-local.yml new file mode 100644 index 0000000..462b376 --- /dev/null +++ b/.github/workflows/ci-local.yml @@ -0,0 +1,50 @@ +name: Build Image and Run Tests with act + +on: + push: + branches: + - '!**' # Exclude all branches from triggering this workflow + +jobs: + test-locally: + runs-on: ubuntu-latest + env: + IMAGE_NAME: test-image + CONTAINER_NAME: test-container + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Xvfb + run: sudo apt-get update && sudo apt-get install -y xvfb + + - name: Build Docker image and use local cache + run: docker build --file docker/Dockerfile --tag ${{ env.IMAGE_NAME }} --target prod . + + - name: Start container + run: docker run --name ${{ env.CONTAINER_NAME }} --net host -v /tmp/.X11-unix:/tmp/.X11-unix -v /var/run/docker.sock:/var/run/docker.sock --detach ${{ env.IMAGE_NAME }} tail -f /dev/null + + - name: Run test + shell: bash + run: | + set -e + echo "Starting virtual display (Xvfb)..." + Xvfb :99 -screen 0 1024x768x24 & + export DISPLAY=:99 + export ROS_DOMAIN_ID=42 + + echo "Start testing..." + docker exec -e DISPLAY=$DISPLAY -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID ${{ env.CONTAINER_NAME }} bash -c " + source ./entrypoint.sh && + colcon test --executor sequential && + colcon test-result --verbose + " + + - name: Export logs to runner + shell: bash + run: docker cp ${{ env.CONTAINER_NAME }}:/home/ws/log ./log + if: always() # export logs even if tests fail + - name: Stop and remove container + run: docker stop -t 0 ${{ env.CONTAINER_NAME }} && docker rm ${{ env.CONTAINER_NAME }} + if: always() diff --git a/docker/Dockerfile b/docker/Dockerfile index 227f101..c68dd39 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -74,6 +74,12 @@ RUN apt-get update && apt-get install -y \ ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp ENV RMW_CYCLONEDDS_URI=file:///home/ws/config/cyclonedds.xml +# Install act for local github actions execution +RUN mkdir -p /home/ws \ + && wget https://github.com/nektos/act/releases/download/v0.2.78/act_Linux_x86_64.tar.gz \ + && tar -xzf act_Linux_x86_64.tar.gz -C /home act \ + && rm act_Linux_x86_64.tar.gz + # ******************************************************** # * Set up the user * # ********************************************************