-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Dockerfile,-kernel.json): Adding capabilities for containerized …
…ipykernel
- Loading branch information
Showing
5 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"argv": [ | ||
"/path/to/launch_kernel.sh", | ||
"{connection_file}" | ||
], | ||
"display_name": "gammapy-kernel", | ||
"language": "python", | ||
"metadata": { | ||
"debugger": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# Get the filename of the connection file | ||
connection_file=$(basename $1) | ||
container_name="gammapy_server" | ||
image_name=$GAMMAPY_KERNEL_IMAGE | ||
# Check if the server instance is currently running | ||
if [ $(apptainer instance list $container_name | wc | awk '{print $1}') -ge 2 ]; then | ||
echo "Server is running" | ||
else | ||
# if it isn't start an instance | ||
echo "Starting the server" | ||
# Bind the runtime-dir (where the connection files are) to /connections within the container | ||
apptainer instance start --bind `jupyter --runtime-dir`:/connections $image_name $container_name | ||
fi | ||
|
||
# Attach and run ipykernel_laucher | ||
apptainer exec instance://$container_name python -m ipykernel_launcher -f /connections/$connection_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# Get the filename of the connection file | ||
connection_file=$(basename $1) | ||
container_name="gammapy_server" | ||
image_name=$GAMMAPY_KERNEL_IMAGE | ||
|
||
# Check if the server is currently runnong | ||
if [ "$( docker container inspect -f '{{.State.Running}}' $container_name )" = "true" ]; then | ||
echo "Server is running" | ||
else | ||
# if not then start the server | ||
echo "Starting the server" | ||
# Get the path of where the connection files will be stored | ||
connection_path="$(jupyter --runtime-dir)" | ||
# Stop and remove the container if it already exists | ||
docker stop $container_name | ||
docker rm $container_name | ||
# Create a new container | ||
# Add it to the host network and mounting the connection_path | ||
docker create --name=$container_name -v $connection_path:/connections --network=host $image_name | ||
# Start this server instance | ||
docker start $container_name | ||
fi | ||
|
||
# Launch a ipykernel using the connection file that was passed as arg 1 | ||
docker exec $container_name python -m ipykernel_launcher -f /connections/$connection_file |