-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
137 lines (106 loc) · 3.88 KB
/
Makefile
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Makefile for managing Docker operations
# export all vars so docker-compose can use them
export
# Dynamically find the most recently run container and its image
# CURRENT_CONTAINER := $(shell docker ps -l -q)
# CURRENT_IMAGE := $(shell docker inspect --format='{{.Config.Image}}' $(CURRENT_CONTAINER))
# Customize these variables for your project
LOCAL_ARCH := $(shell uname -m)
GCLOUD_ARCH := amd64
IMAGE_NAME := langroid-fastapi-server
G_IMAGE_NAME := langroid-fastapi-server
# Use CURRENT_IMAGE if available, otherwise fallback to a default
CONTAINER_NAME := langroid-container
GCLOUD_PROJECT_ID := langroid
GCLOUD_REGISTRY_PREFIX := gcr.io
GCLOUD_IMAGE_NAME := $(GCLOUD_REGISTRY_PREFIX)/$(GCLOUD_PROJECT_ID)/$(G_IMAGE_NAME)
GCLOUD_RUN_SERVICE := langroid-fastapi-server
GCLOUD_REGION := us-east4
BUCKET_NAME := fastapi-server-$(GCLOUD_PROJECT_ID)
DOCKERFILE_PATH := fastapi_server/Dockerfile
REGION := us-east4
PORT := 90
TAG := latest
clear:
# @echo "Removing all Docker containers..."
# @docker rm -f $(docker ps -aq) || true
# @echo "Removing all Docker images..."
# @docker rmi -f $(docker images -a -q) || true
# @echo "pruning all Docker volumes..."
# @docker container prune -f
# @echo "pruning all Docker networks..."
# @docker network prune -f
# @echo "pruning system..."
# @docker system prune -f
@echo "Removing unused volumes..."
@docker volume prune -f
@echo "Removing unused networks..."
@docker network prune -f
@echo "Docker clean up complete."
# use
build:
docker-compose build
rbuild:
docker-compose build --no-cache
up:
export DEBUG=False RELOAD=true; \
docker-compose up -d
down:
docker-compose down
debug:
@docker logs $$(docker ps -a -q -l)
tail:
docker-compose logs -f
server:
docker build --platform linux/$(LOCAL_ARCH) -t $(IMAGE_NAME):$(TAG) -f $(DOCKERFILE_PATH) .
run:
docker run --env-file .env -d -p $(PORT):$(PORT) $(IMAGE_NAME):$(TAG)
# Stop the Docker container
stop:
docker stop $(CONTAINER_NAME)
docker rm $(CONTAINER_NAME)
stats:
docker stats $(CONTAINER_NAME)
# Shortcut to stop (if running) and then start the container
restart: stop run
# Start a shell session in a new container from the image
sh:
@docker exec -it $$(docker ps -q | head -n1) sh
# Start a Python console in a new container from the image
py:
docker run -it --rm --name $(CONTAINER_NAME)_python $(IMAGE_NAME) python
glist-cont-imgs:
gcloud container images list --repository=$(GCLOUD_IMAGE_NAME)
gserver:
export DEBUG=false RELOAD=false; \
docker build --platform=linux/$(GCLOUD_ARCH) -t $(GCLOUD_IMAGE_NAME):$(TAG) -f $(DOCKERFILE_PATH) .
gpush:
docker push $(GCLOUD_IMAGE_NAME):$(TAG)
gdeploy:
gcloud run deploy $(GCLOUD_RUN_SERVICE) --image $(GCLOUD_IMAGE_NAME):$(TAG) \
--platform managed --region $(GCLOUD_REGION) \
--project $(GCLOUD_PROJECT_ID) --allow-unauthenticated \
--timeout 1000s --port $(PORT) --memory 32Gi --cpu 8
gtail:
gcloud beta logging tail
--log-filter="resource.type=\"cloud_run_revision\" AND resource.labels.service_name=\"$(GCLOUD_RUN_SERVICE)\""
--project=$(GCLOUD_PROJECT_ID)
gbucket:
gsutil mb -p $(GCLOUD_PROJECT_ID) -c standard -l $(GCLOUD_REGION) -b on gs://$(BUCKET_NAME)/
gsh:
docker run -it --entrypoint /bin/sh $(GCLOUD_IMAGE_NAME):$(TAG)
gstop:
gcloud run services update $(GCLOUD_RUN_SERVICE) --region=(GCLOUD_REGION) --no-traffic
# Help
help:
@echo "Makefile commands:"
@echo "server - Build the server, i.e. Docker image."
@echo "run - Run the Docker container."
@echo "stop - Stop and remove the Docker container."
@echo "restart - Restart the Docker container."
@echo "help - Print this help message."
@echo "gserver - Build the server for Google Cloud."
@echo "gpush - Push the server to Google Cloud."
@echo "sh - Start a shell session in a new container from the image."
@echo "py - Start a Python console in a new container from the image."
.PHONY: server run stop restart help gbucket