<commit_before>VENV_NAME:=venv
github3_version:=1.1.0
port := 10001
image_to_use := offboard-py3
container_user_name := ghjupyter
SOPS_credentials := $(SECOPS_SOPS_PATH)/off-boarding.yaml

DOCKER_OPTS :=

.PHONY: help
help:
	@echo "Targets available"
	@echo ""
	@echo "    help          this message"
	@echo "    build         create a docker image based on working directory"
	@echo "    run           run a docker image previously created"
	@echo "    run-edit      run with modifiable current directory"
	@echo "    jupyter 	 run local (non docker) jupyter server for development"
	@echo "    $(VENV_NAME)  create a local virtualenv for old style development"

$(VENV_NAME):
	virtualenv --python=python3.7 $@
	. $(VENV_NAME)/bin/activate && echo req*.txt | xargs -n1 pip install -r
	@echo "Virtualenv created in $(VENV_NAME). You must activate before continuing."
	false

SHELL := /bin/bash
.PHONY: build
# we use a file url to avoid including work files in the production
# image. During development, you may prefer a bare dot "." to pick up
# local changes, and remove the `--ref ` option
build:
	-docker rmi $(image_to_use):$(github3_version) 2>/dev/null
	$(SHELL) -c '  \
		repo2docker --image-name "$(image_to_use):$(github3_version)" \
			--user-name $(container_user_name) \
			--no-run \
			--ref $$(git show-ref --verify --hash --head HEAD) \
			file://$$PWD/.git \
		; \
	'

# For `run`, we use the configs baked into the image at the time of
# the build, so we get what we expect.
.PHONY: run
run:
	$(SHELL) -c ' ( source set_secrets_in_env.sh $(SOPS_credentials); \
		docker run --rm --publish-all \
			--env "GITHUB_PAT" \
			--env "CIS_CLIENT_ID" \
			--env "CIS_CLIENT_SECRET" \
			--publish $(port):8888 \
			$(image_to_use):$(github3_version) \
		& \
		job_pid=$$! ; \
		sleep 5 ; \
		docker ps --filter "ancestor=$(image_to_use):$(github3_version)" ; \
		wait $$job_pid ; \
	) '

# For `run-edit`, we're mapping the current directory atop the home
# directory
.PHONY: run-edit
run-edit:
	$(SHELL) -c ' ( source set_secrets_in_env.sh $(SOPS_credentials); \
		docker run --rm --publish-all \
			$(DOCKER_OPTS) \
			--env "GITHUB_PAT" \
			--env "CIS_CLIENT_ID" \
			--env "CIS_CLIENT_SECRET" \
			--publish $(port):8888 \
			--volume "$$PWD/notebooks:/home/$(container_user_name)/notebooks" \
			$(image_to_use):$(github3_version) \
		& \
		job_pid=$$! ; \
		sleep 5 ; \
		docker ps --filter "ancestor=$(image_to_use):$(github3_version)" ; \
		wait $$job_pid ; \
	) '

.PHONY: jupyter
jupyter:
	$(SHELL) -c ' ( source set_secrets_in_env.sh $(SOPS_credentials); \
		jupyter-notebook ; \
	) '

.PHONY: debug-edit
debug-edit:<commit_msg>Fail early if credentials look bad<commit_after>VENV_NAME:=venv
github3_version:=1.1.0
port := 10001
image_to_use := offboard-py3
container_user_name := ghjupyter
SOPS_credentials := $(SECOPS_SOPS_PATH)/off-boarding.yaml

DOCKER_OPTS :=

.PHONY: help
help:
	@echo "Targets available"
	@echo ""
	@echo "    help          this message"
	@echo "    build         create a docker image based on working directory"
	@echo "    run           run a docker image previously created"
	@echo "    run-edit      run with modifiable current directory"
	@echo "    jupyter 	 run local (non docker) jupyter server for development"
	@echo "    $(VENV_NAME)  create a local virtualenv for old style development"

$(VENV_NAME):
	virtualenv --python=python3.7 $@
	. $(VENV_NAME)/bin/activate && echo req*.txt | xargs -n1 pip install -r
	@echo "Virtualenv created in $(VENV_NAME). You must activate before continuing."
	false

SHELL := /bin/bash
.PHONY: build
# we use a file url to avoid including work files in the production
# image. During development, you may prefer a bare dot "." to pick up
# local changes, and remove the `--ref ` option
build:
	-docker rmi $(image_to_use):$(github3_version) 2>/dev/null
	$(SHELL) -c '  \
		repo2docker --image-name "$(image_to_use):$(github3_version)" \
			--user-name $(container_user_name) \
			--no-run \
			--ref $$(git show-ref --verify --hash --head HEAD) \
			file://$$PWD/.git \
		; \
	'

# For `run`, we use the configs baked into the image at the time of
# the build, so we get what we expect.
.PHONY: run
run:
	$(SHELL) -ce ' ( source set_secrets_in_env.sh $(SOPS_credentials); \
		docker run --rm --publish-all \
			--env "GITHUB_PAT" \
			--env "CIS_CLIENT_ID" \
			--env "CIS_CLIENT_SECRET" \
			--publish $(port):8888 \
			$(image_to_use):$(github3_version) \
		& \
		job_pid=$$! ; \
		sleep 5 ; \
		docker ps --filter "ancestor=$(image_to_use):$(github3_version)" ; \
		wait $$job_pid ; \
	) '

# For `run-edit`, we're mapping the current directory atop the home
# directory
.PHONY: run-edit
run-edit:
	$(SHELL) -ce ' ( source set_secrets_in_env.sh $(SOPS_credentials); \
		docker run --rm --publish-all \
			$(DOCKER_OPTS) \
			--env "GITHUB_PAT" \
			--env "CIS_CLIENT_ID" \
			--env "CIS_CLIENT_SECRET" \
			--publish $(port):8888 \
			--volume "$$PWD/notebooks:/home/$(container_user_name)/notebooks" \
			$(image_to_use):$(github3_version) \
		& \
		job_pid=$$! ; \
		sleep 5 ; \
		docker ps --filter "ancestor=$(image_to_use):$(github3_version)" ; \
		wait $$job_pid ; \
	) '

.PHONY: jupyter
jupyter:
	$(SHELL) -ce ' ( source set_secrets_in_env.sh $(SOPS_credentials); \
		jupyter-notebook ; \
	) '

.PHONY: debug-edit
debug-edit:
{'fraction_non_alphanumeric': 0.14934333958724202, 'fraction_numerical': 0.011632270168855536, 'mean_word_length': 3.1389751552795033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1574136', 'n_tokens_mistral': 2174, 'n_tokens_neox': 1995, 'n_words': 512}