2023-05-18 18:09:58 +00:00
|
|
|
#do not call this makefile it is included in the main Makefile
|
2023-05-18 18:09:55 +00:00
|
|
|
.PHONY: docker docker.jupyter docker.run docker.force_build docker.clean \
|
|
|
|
docker.test docker.lint docker.lint.mypy docker.lint.black \
|
|
|
|
docker.lint.isort docker.lint.flake
|
2023-05-18 18:09:58 +00:00
|
|
|
|
2023-05-18 18:09:57 +00:00
|
|
|
# read python version from .env file ignoring comments
|
2023-05-18 18:09:58 +00:00
|
|
|
PYTHON_VERSION := $(shell grep PYTHON_VERSION docker/.env | cut -d '=' -f2)
|
2023-05-18 18:09:57 +00:00
|
|
|
POETRY_EXTRA_PACKAGES := $(shell grep '^[^#]*POETRY_EXTRA_PACKAGES' docker/.env | cut -d '=' -f2)
|
2023-05-18 18:09:55 +00:00
|
|
|
POETRY_DEPENDENCIES := $(shell grep 'POETRY_DEPENDENCIES' docker/.env | cut -d '=' -f2)
|
2023-05-18 18:09:58 +00:00
|
|
|
|
|
|
|
|
2023-05-18 18:09:57 +00:00
|
|
|
DOCKER_SRC := $(shell find docker -type f)
|
2023-05-18 18:09:58 +00:00
|
|
|
DOCKER_IMAGE_NAME = langchain/dev
|
|
|
|
|
|
|
|
# SRC is all files matched by the git ls-files command
|
|
|
|
SRC := $(shell git ls-files -- '*' ':!:docker/*')
|
|
|
|
|
|
|
|
# set DOCKER_BUILD_PROGRESS=plain to see detailed build progress
|
|
|
|
DOCKER_BUILD_PROGRESS ?= auto
|
|
|
|
|
|
|
|
# extra message to show when entering the docker container
|
|
|
|
DOCKER_MOTD := docker/assets/etc/motd
|
|
|
|
|
|
|
|
ROOTDIR := $(shell git rev-parse --show-toplevel)
|
|
|
|
|
2023-05-18 18:09:55 +00:00
|
|
|
DOCKER_LINT_CMD = docker run --rm -i -u lchain -v $(ROOTDIR):/src $(DOCKER_IMAGE_NAME):$(GIT_HASH)
|
|
|
|
|
2023-05-18 18:09:58 +00:00
|
|
|
docker: docker.run
|
|
|
|
|
|
|
|
docker.run: docker.build
|
|
|
|
@echo "Docker image: $(DOCKER_IMAGE_NAME):$(GIT_HASH)"
|
2023-05-18 18:09:57 +00:00
|
|
|
docker run --rm -it -u lchain -v $(ROOTDIR):/src $(DOCKER_IMAGE_NAME):$(GIT_HASH)
|
2023-05-18 18:09:58 +00:00
|
|
|
|
|
|
|
docker.jupyter: docker.build
|
2023-05-18 18:09:57 +00:00
|
|
|
docker run --rm -it -v $(ROOTDIR):/src $(DOCKER_IMAGE_NAME):$(GIT_HASH) jupyter notebook
|
2023-05-18 18:09:58 +00:00
|
|
|
|
|
|
|
docker.build: $(SRC) $(DOCKER_SRC) $(DOCKER_MOTD)
|
|
|
|
ifdef $(DOCKER_BUILDKIT)
|
2023-05-18 18:09:57 +00:00
|
|
|
docker buildx build --build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
|
|
|
|
--build-arg POETRY_EXTRA_PACKAGES=$(POETRY_EXTRA_PACKAGES) \
|
2023-05-18 18:09:55 +00:00
|
|
|
--build-arg POETRY_DEPENDENCIES=$(POETRY_DEPENDENCIES) \
|
2023-05-18 18:09:58 +00:00
|
|
|
--progress=$(DOCKER_BUILD_PROGRESS) \
|
2023-05-18 18:09:57 +00:00
|
|
|
$(BUILD_FLAGS) -f docker/Dockerfile -t $(DOCKER_IMAGE_NAME):$(GIT_HASH) .
|
2023-05-18 18:09:58 +00:00
|
|
|
else
|
2023-05-18 18:09:57 +00:00
|
|
|
docker build --build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
|
|
|
|
--build-arg POETRY_EXTRA_PACKAGES=$(POETRY_EXTRA_PACKAGES) \
|
2023-05-18 18:09:55 +00:00
|
|
|
--build-arg POETRY_DEPENDENCIES=$(POETRY_DEPENDENCIES) \
|
2023-05-18 18:09:57 +00:00
|
|
|
$(BUILD_FLAGS) -f docker/Dockerfile -t $(DOCKER_IMAGE_NAME):$(GIT_HASH) .
|
2023-05-18 18:09:58 +00:00
|
|
|
endif
|
2023-05-18 18:09:57 +00:00
|
|
|
docker tag $(DOCKER_IMAGE_NAME):$(GIT_HASH) $(DOCKER_IMAGE_NAME):latest
|
|
|
|
@touch $@ # this prevents docker from rebuilding dependencies that have not
|
|
|
|
@ # changed. Remove the file `docker/docker.build` to force a rebuild.
|
2023-05-18 18:09:58 +00:00
|
|
|
|
|
|
|
docker.force_build: $(DOCKER_SRC)
|
2023-05-18 18:09:57 +00:00
|
|
|
@rm -f docker.build
|
|
|
|
@$(MAKE) docker.build BUILD_FLAGS=--no-cache
|
2023-05-18 18:09:58 +00:00
|
|
|
|
2023-05-18 18:09:57 +00:00
|
|
|
docker.clean:
|
|
|
|
docker rmi $(DOCKER_IMAGE_NAME):$(GIT_HASH) $(DOCKER_IMAGE_NAME):latest
|
2023-05-18 18:09:49 +00:00
|
|
|
|
|
|
|
docker.test: docker.build
|
|
|
|
docker run --rm -it -u lchain -v $(ROOTDIR):/src $(DOCKER_IMAGE_NAME):$(GIT_HASH) \
|
|
|
|
pytest /src/tests/unit_tests
|
|
|
|
|
2023-05-18 18:09:55 +00:00
|
|
|
# this assumes that the docker image has been built
|
|
|
|
docker.lint: docker.lint.mypy docker.lint.black docker.lint.isort \
|
|
|
|
docker.lint.flake
|
|
|
|
|
|
|
|
# these can run in parallel with -j[njobs]
|
|
|
|
docker.lint.mypy:
|
|
|
|
@$(DOCKER_LINT_CMD) mypy /src
|
|
|
|
@printf "\t%s\n" "mypy ... "
|
|
|
|
|
|
|
|
docker.lint.black:
|
|
|
|
@$(DOCKER_LINT_CMD) black /src --check
|
|
|
|
@printf "\t%s\n" "black ... "
|
|
|
|
|
|
|
|
docker.lint.isort:
|
|
|
|
@$(DOCKER_LINT_CMD) isort /src --check
|
|
|
|
@printf "\t%s\n" "isort ... "
|
2023-05-18 18:09:49 +00:00
|
|
|
|
2023-05-18 18:09:55 +00:00
|
|
|
docker.lint.flake:
|
|
|
|
@$(DOCKER_LINT_CMD) flake8 /src
|
|
|
|
@printf "\t%s\n" "flake8 ... "
|