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

Refactor run-nodered script #816

Merged
merged 10 commits into from
Oct 30, 2024
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ endif()
# FIXME (aw): this should be optional
add_subdirectory(config)

# install docker related files
install(
DIRECTORY "cmake/assets/docker"
DESTINATION "${CMAKE_INSTALL_DATADIR}/everest"
)

ev_install_project()

# configure clang-tidy if requested
Expand Down
5 changes: 0 additions & 5 deletions cmake/assets/docker/Dockerfile

This file was deleted.

20 changes: 17 additions & 3 deletions cmake/assets/run_nodered_template.sh.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
cd @EVEREST_DOCKER_DIR@
docker build -t everest-nodered .
docker run --rm --network host --name everest_nodered --mount type=bind,source=@FLOW_FILE@,target=/data/flows.json everest-nodered
# In the following a volume is created to contain the nodered config, this is done to
# allow starting the nodered container from inside a devcontainer

Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does using a volume allow to start the node-red container from inside a dev container?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workspace inside the devcontainer is mounted to an other path. So you would need to know about the host path of the flow file.

docker run is executed on host with host paths

docker cp is executed with container's paths

This way it is possible to copy a file with only knowing the devcontainer paths into a docker volume which then can be mounted by name into the nodered container

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, well this is really ugly. These docker inside docker scenarios are quite special, not sure whether we should support these - they might break quite easily. This script here basically only works, if the devcontainer has been launched correctly - which is an assumption I wouldn't necessarily make.
Does this script work, when executed from the host (i.e. outside of the container?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not real docker inside docker, because it is more like remote controlling the hosts docker socket.
This script is designed to work inside and outside the devcontainer. Of course it needs to be rebuild when changed because of paths

# Create docker volume to contain nodered config
docker volume create everest-nodered-config-volume

# Create temporarily container to copy nodered config into the created volume
docker run --name everest-nodered-config-container -v everest-nodered-config-volume:/data debian:12-slim chown -R 1000:1000 /data

# Copy nodered config to the created volume with the temporarily created container
docker cp @FLOW_FILE@ everest-nodered-config-container:/data/flows.json

# Remove temporarily container
docker rm everest-nodered-config-container

# Start nodered container with the volume mounted to /data
docker run --rm --network host --name everest_nodered --mount type=volume,source=everest-nodered-config-volume,target=/data ghcr.io/everest/everest-dev-environment/nodered:docker-images-v0.1.0
3 changes: 0 additions & 3 deletions cmake/config-run-nodered-script.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ function(generate_nodered_run_script)
set(SCRIPT_OUTPUT_FILE "${SCRIPT_OUTPUT_PATH}/nodered-${OPTNS_OUTPUT}.sh")
endif()

# other necessary variables
set(EVEREST_DOCKER_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/everest/docker")

configure_file("${EVEREST_CONFIG_ASSET_DIR}/run_nodered_template.sh.in" ${SCRIPT_OUTPUT_FILE})

endfunction()
Loading