Skip to content

Commit 696f23e

Browse files
authored
Merge pull request #23 from networmix/consolidate-env
Consolidated dev and run environments
2 parents 5f22ad0 + db5fd06 commit 696f23e

File tree

6 files changed

+70
-152
lines changed

6 files changed

+70
-152
lines changed

Dockerfile

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
# Use the official Python image from the Docker Hub
12
FROM python:3.10
23

3-
# Add Tini
4-
ENV TINI_VERSION v0.19.0
4+
# Add Tini, a minimal init system for containers
5+
ENV TINI_VERSION=v0.19.0
56
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
67
RUN chmod +x /tini
78

8-
# The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT,
9-
# COPY and ADD instructions that follow it in the Dockerfile.
10-
# If the WORKDIR doesn’t exist, it will be created even if it’s not used
11-
# in any subsequent Dockerfile instruction.
9+
# Set the working directory inside the container
1210
WORKDIR /root/env
1311

14-
# Prevent running interactive config
15-
ENV DEBIAN_FRONTEND noninteractive
12+
# Prevent running interactive config during package installation
13+
ENV DEBIAN_FRONTEND=noninteractive
1614

15+
# Install system dependencies and remove the package list
16+
RUN apt-get update && \
17+
apt-get install -y \
18+
libgeos-dev \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
# Copy the requirements file into the container
1722
COPY requirements.txt ./
1823

24+
# Install Python dependencies
1925
RUN pip install --no-cache-dir --upgrade pip && \
2026
pip install --no-cache-dir -r requirements.txt
2127

22-
RUN pip install jupyter
23-
RUN pip install networkx
24-
RUN pip install pandas
25-
RUN pip install seaborn
26-
RUN pip install basemap-data-hires
27-
RUN pip install basemap
28+
# Create a mount point for external volumes
29+
VOLUME /root/env
30+
31+
# Set the entrypoint to Tini
32+
ENTRYPOINT ["/tini", "-g", "--"]
2833

29-
ENTRYPOINT ["/tini", "-g", "--"]
34+
# Default command to run when the container starts
35+
CMD ["/bin/bash"]

dev/Dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

dev/buildenv.sh

Lines changed: 0 additions & 86 deletions
This file was deleted.

dev/requirements.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

requirements.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@ geopy
22
networkx
33
numpy
44
pandas
5-
matplotlib
5+
matplotlib
6+
build
7+
twine
8+
pytest
9+
pytest-cov
10+
pytest-benchmark
11+
pytest-mock
12+
pylint
13+
black
14+
jupyter
15+
seaborn
16+
basemap-data-hires
17+
basemap

run.sh

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
set -e
44

5-
IMAGE_TAG=ngraph
5+
DEFAULT_IMAGE_TAG=ngraph
6+
IMAGE_TAG=${2:-$DEFAULT_IMAGE_TAG}
7+
DEFAULT_CONTAINER_NAME=ngraph_jupyter
8+
CONTAINER_NAME=${3:-$DEFAULT_CONTAINER_NAME}
69
IMAGE_ID=$(docker images --format "{{.ID}}" $IMAGE_TAG)
710

8-
USAGE="Usage: $0 COMMAND IMAGE_TAG\n"
9-
USAGE+=" COMMAND is what you expect script to do:\n"
11+
USAGE="Usage: $0 COMMAND [IMAGE_TAG] [CONTAINER_NAME]\n"
12+
USAGE+=" COMMAND is what you expect the script to do:\n"
1013
USAGE+=" build - Builds an image from a Dockerfile.\n"
11-
USAGE+=" run - Runs a container.\n"
12-
USAGE+=" killall - Stops and removes all running containers.\n"
13-
USAGE+=" forcecleanall - Clean-up Docker.\n"
14+
USAGE+=" run - Runs a container and starts Jupyter.\n"
15+
USAGE+=" shell - Attaches to the shell of a running container.\n"
16+
USAGE+=" killall - Stops and removes all running containers based on the image tag.\n"
17+
USAGE+=" forcecleanall - WARNING: Stops and removes all containers and images. This action cannot be undone.\n"
18+
USAGE+=" IMAGE_TAG is the optional Docker image tag (default: $DEFAULT_IMAGE_TAG).\n"
19+
USAGE+=" CONTAINER_NAME is the optional Docker container name (default: $DEFAULT_CONTAINER_NAME).\n"
1420

1521
if [[ $# -lt 1 ]]; then
1622
echo>&2 "ERROR: Must specify the command"
@@ -21,7 +27,7 @@ fi
2127
[[ $(uname) -eq "Darwin" ]] && MODHACK="-v /lib/modules:/lib/modules:ro" || MODHACK=""
2228

2329
function build {
24-
echo "Building docker container"
30+
echo "Building docker container with tag $IMAGE_TAG"
2531
docker build . -t $IMAGE_TAG
2632

2733
IMAGE_ID=$(docker images --format "{{.ID}}" $IMAGE_TAG)
@@ -30,18 +36,24 @@ function build {
3036
}
3137

3238
function run {
33-
name=ngraph_jupyter
34-
echo "Starting a container with the name $name using $IMAGE_TAG image..."
35-
CONTAINER_ID=$(docker create --rm -it --name $name -v "$PWD":/root/env -p 8787:8787 --entrypoint=/bin/bash --privileged $MODHACK --cap-add ALL $IMAGE_TAG)
39+
echo "Starting a container with the name $CONTAINER_NAME using $IMAGE_TAG image..."
40+
CONTAINER_ID=$(docker create --rm -it --name $CONTAINER_NAME -v "$PWD":/root/env -p 8787:8787 --entrypoint=/bin/bash --privileged $MODHACK --cap-add ALL $IMAGE_TAG)
3641
docker start $CONTAINER_ID
37-
echo "Started $CONTAINER_ID with the name $name"
42+
echo "Started $CONTAINER_ID with the name $CONTAINER_NAME"
3843
docker exec -it $CONTAINER_ID pip install -e .
3944
echo "Starting Jupyter in a container. Open http://127.0.0.1:8787/ in your browser."
4045
docker exec -it $CONTAINER_ID jupyter notebook --port=8787 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token='' /root/env
4146
return 0
4247
}
4348

49+
function shell {
50+
echo "Attaching to the shell of the running container $CONTAINER_NAME..."
51+
docker exec -it $CONTAINER_NAME /bin/bash
52+
return 0
53+
}
54+
4455
function killall {
56+
echo "Stopping and removing all running containers based on the image tag $IMAGE_TAG..."
4557
for container_id in $(docker ps -q --filter "ancestor=$IMAGE_TAG"); do
4658
echo "$(docker kill $container_id) - stopped and removed"
4759
done
@@ -50,6 +62,13 @@ function killall {
5062
}
5163

5264
function forcecleanall {
65+
echo "WARNING: This will stop and remove all containers and images. This action cannot be undone."
66+
read -p "Are you sure you want to proceed? (Y/N): " confirm
67+
if [[ $confirm != [Yy] ]]; then
68+
echo "Aborting forcecleanall."
69+
return 1
70+
fi
71+
5372
for container in $(docker container ls --format "{{.ID}}"); do docker container kill $container; done
5473
for container in $(docker container ls -a --format "{{.ID}}"); do docker container rm $container; done
5574
for image in $(docker images --format "{{.ID}}"); do docker image rm --force $image; done
@@ -68,6 +87,11 @@ case $1 in
6887
run "$@"
6988
;;
7089

90+
shell)
91+
echo "Executing SHELL command..."
92+
shell "$@"
93+
;;
94+
7195
killall)
7296
echo "Executing KILLALL command..."
7397
killall "$@"
@@ -83,4 +107,4 @@ case $1 in
83107
printf "$USAGE" >&2
84108
exit 2
85109
;;
86-
esac
110+
esac

0 commit comments

Comments
 (0)