-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmakefile
More file actions
65 lines (54 loc) · 2.45 KB
/
makefile
File metadata and controls
65 lines (54 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
DOCKER_IMAGE_NAME = quant-stack
DOCKER_CONTAINER_NAME = quant-container
JUPYTER_PASSWORD ?= password
NOTEBOOK_DIR ?= $(PWD)/notebook
ARCH := $(shell uname -m)
# get value of GITHUB_TOKEN and PRIVATE_REPO from .env file
ifneq (,$(wildcard .env))
include .env
export
endif
build:
ifeq ($(ARCH),arm64)
#Mac M2 (ARM)
docker buildx build --platform linux/amd64 -t $(DOCKER_IMAGE_NAME) --build-arg GITHUB_TOKEN=$(GITHUB_TOKEN) --build-arg PRIVATE_REPO=$(PRIVATE_REPO) .
else
#Mac Intel (x86_64)
docker build -t $(DOCKER_IMAGE_NAME) --build-arg GITHUB_TOKEN=$(GITHUB_TOKEN) --build-arg PRIVATE_REPO=$(PRIVATE_REPO) .
endif
run:
ifeq ($(ARCH),arm64)
@echo "Launching container $(DOCKER_CONTAINER_NAME) on Mac ARM (M1/M2)..."
@HASHED_PASSWORD=$$(docker run --rm $(DOCKER_IMAGE_NAME) python -c "from jupyter_server.auth import passwd; print(passwd('$(JUPYTER_PASSWORD)'))") && \
docker run --platform linux/amd64 -d --name $(DOCKER_CONTAINER_NAME) -p 8889:8888 -v $(NOTEBOOK_DIR):/app/ -e JUPYTER_PASSWORD="$$HASHED_PASSWORD" $(DOCKER_IMAGE_NAME)
else
@echo "Launching container $(DOCKER_CONTAINER_NAME)..."
@HASHED_PASSWORD=$$(docker run --rm $(DOCKER_IMAGE_NAME) python -c "from jupyter_server.auth import passwd; print(passwd('$(JUPYTER_PASSWORD)'))") && \
docker run -d --name $(DOCKER_CONTAINER_NAME) -p 8889:8888 -v $(NOTEBOOK_DIR):/app/ -e JUPYTER_PASSWORD="$$HASHED_PASSWORD" $(DOCKER_IMAGE_NAME)
endif
stop:
@echo "Stopping and removing container $(DOCKER_CONTAINER_NAME)..."
docker stop $(DOCKER_CONTAINER_NAME)
docker rm $(DOCKER_CONTAINER_NAME)
clean:
@echo "Removing image $(DOCKER_IMAGE_NAME)..."
docker rmi $(DOCKER_IMAGE_NAME)
logs:
@echo "Displaying logs for container $(DOCKER_CONTAINER_NAME)..."
docker logs $(DOCKER_CONTAINER_NAME)
shell:
@echo "Opening a shell in container $(DOCKER_CONTAINER_NAME)..."
docker exec -it $(DOCKER_CONTAINER_NAME) /bin/bash
docker-prune:
@echo "Full Docker cleanup (containers, images, volumes, unused networks)..."
docker system prune -a --volumes -f
help:
@echo "Available commands:"
@echo " make build : Build the Docker image"
@echo " make run : Launch the container"
@echo " make stop : Stop and remove the container"
@echo " make clean : Remove the Docker image"
@echo " make logs : Display container logs"
@echo " make shell : Open a shell in the container"
@echo " make docker-prune : Full Docker cleanup (dangerous, removes everything not used)"
.PHONY: build run stop clean logs shell help