Skip to content

Commit

Permalink
New Makefile commands for testing Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-zeller committed Jun 30, 2024
1 parent 43641b3 commit bc41aad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
17 changes: 13 additions & 4 deletions binder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
# Dockerfile instead.

# To test, use
# docker build -t my-image binder
# make docker-image
# and then
# make docker-run (for a jupyter notebook)
# make docker-shell (for a bash shell)

# For more infp, see
# For more info, see
# https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html
# https://github.com/binder-examples/minimal-dockerfile

# This Dockerfile is meant to be used in the mybinder environment,
# but it can also serve as a base to deploy docker images.

# From minimal-dockerfile
# FROM python:3.10-slim
# From docker2repo
Expand All @@ -25,7 +31,7 @@ RUN apt-get update
RUN apt-get install -y git python3 pip npm gcc

# Some version info
RUN echo "This is ${PROJECT} with $(python3 --version)"
RUN echo "This is ${PROJECT} with $(python3 --version)" 1>&2

# Install jupyter
RUN pip install --no-cache --upgrade pip && \
Expand Down Expand Up @@ -54,6 +60,9 @@ WORKDIR ${PROJECT}
# Install the required Linux packages
RUN apt-get install -y $(grep -v '^#' binder/apt.txt); exit 0

# Expose port 8888, so it can be reached from the outside (for local testing)
EXPOSE 8888

# From here on, we are a user
USER ${NB_USER}

Expand All @@ -69,5 +78,5 @@ ENV PATH="/home/${NB_USER}/.local/bin:$PATH"
RUN pip install -r requirements.txt; exit 0
RUN pip install -r binder/requirements.txt; exit 0

# Run the postBuild script
# Run the postBuild script (to sign notebooks and more)
RUN bash binder/postBuild
38 changes: 26 additions & 12 deletions notebooks/shared/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1260,18 +1260,32 @@ binder/binder.log: .FORCE
repo2docker -v '.:.' --Repo2Docker.platform=linux/amd64 . 2>&1 | tee $@


## Docker services (experimental)
docker:
docker pull $(PROJECT)/student
-docker run -d -p 8888:8888 --name fuzzing-book-instance $(PROJECT)/student

docker-start:
docker start fuzzing-book-instance
sleep 2
@URL=$$(docker exec -it fuzzing-book-instance jupyter notebook list | grep http | awk '{ print $$1 }'); echo $$URL; open $$URL

docker-stop:
docker stop fuzzing-book-instance
## Running Jupyter in docker
.PHONY: docker docker-image docker-push docker-release docker-shell docker-run
DOCKER_USERNAME = zeller24
GIT_HASH = $(shell git log --format="%h" -n 1)
DOCKER_TAG = $(DOCKER_USERNAME)/$(PROJECT)
DOCKERFILE = binder/Dockerfile
JUPYTER_TOKEN=$(PROJECT)
JUPYTER_PORT=8888

docker-image: $(DOCKERFILE) $(SOURCES)
docker build --tag $(DOCKER_TAG) binder

docker-shell: docker-image
docker run -it --rm $(DOCKER_TAG) bash

docker-run docker:
(sleep 2; open http://127.0.0.1:$(JUPYTER_PORT)/lab?token=$(JUPYTER_TOKEN)) &
docker run -it --rm -p $(JUPYTER_PORT):$(JUPYTER_PORT) -e JUPYTER_TOKEN=$(JUPYTER_TOKEN) $(DOCKER_TAG) jupyter lab --ip=0.0.0.0 --port=$(JUPYTER_PORT) --no-browser

docker-push:
docker push $(DOCKER_TAG)

docker-release:
docker pull $(DOCKER_TAG)
docker tag $(DOCKER_TAG):$(GIT_HASH) $(DOCKER_TAG):latest
docker push $(DOCKER_TAG):latest


## Getting rid of stray processes and workspaces
Expand Down

0 comments on commit bc41aad

Please sign in to comment.