-
Notifications
You must be signed in to change notification settings - Fork 53
/
Makefile
215 lines (170 loc) · 7.74 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
.DEFAULT_GOAL := help
ENV_PREFIX ?= ./
ENV_FILE := $(wildcard $(ENV_PREFIX)/.env)
ifeq ($(strip $(ENV_FILE)),)
$(info $(ENV_PREFIX)/.env file not found, skipping inclusion)
else
include $(ENV_PREFIX)/.env
export
endif
GIT_SHORT_SHA = $(shell git rev-parse --short HEAD)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
##@ Utility
help: ## Display this help. (Default)
# based on "https://gist.github.com/prwhite/8168133?permalink_comment_id=4260260#gistcomment-4260260"
@grep -hE '^[A-Za-z0-9_ \-]*?:.*##.*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
##@ Utility
help_sort: ## Display alphabetized version of help.
@grep -hE '^[A-Za-z0-9_ \-]*?:.*##.*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
#--------
# package
#--------
test: ## Run tests. See pyproject.toml for configuration.
poetry run pytest
test-cov-xml: ## Run tests with coverage
poetry run pytest --cov-report=xml
lint: ## Run linter
poetry run black .
poetry run ruff --fix .
lint-check: ## Run linter in check mode
poetry run black --check .
poetry run ruff .
typecheck: ## Run typechecker
poetry run pyright
docs-build: ## Build documentation
poetry run mkdocs build
docs-serve: ## Serve documentation
docs-serve: docs-build
poetry run mkdocs serve
#-------------
# CI
#-------------
browse: ## Open github repo in browser at HEAD commit.
gh browse $(GIT_SHORT_SHA)
GH_ACTIONS_DEBUG ?= false
ci: ## Run CI (GH_ACTIONS_DEBUG default is false).
gh workflow run "CI" --ref $(GIT_BRANCH) -f debug_enabled=$(GH_ACTIONS_DEBUG)
build_images: ## Run Build Images (GH_ACTIONS_DEBUG default is false).
gh workflow run "Build Images" --ref $(GIT_BRANCH) -f debug_enabled=$(GH_ACTIONS_DEBUG)
ci_view_workflow: ## Open CI workflow summary.
gh workflow view "CI"
build_images_view_workflow: ## Open Build Images workflow summary.
gh workflow view "Build Images"
docker_login: ## Login to ghcr docker registry. Check regcreds in $HOME/.docker/config.json.
docker login ghcr.io -u $(GH_ORG) -p $(GITHUB_TOKEN)
EXISTING_IMAGE_TAG ?= main
NEW_IMAGE_TAG ?= $(GIT_BRANCH)
# Default bumps main to the checked out branch for dev purposes
tag_images: ## Add tag to existing images, (default main --> branch, override with make -n tag_images NEW_IMAGE_TAG=latest).
crane tag $(WORKFLOW_IMAGE):$(EXISTING_IMAGE_TAG) $(NEW_IMAGE_TAG)
crane tag ghcr.io/$(GH_ORG)/$(GH_REPO_NAME_SLUG):$(EXISTING_IMAGE_TAG) $(NEW_IMAGE_TAG)
list_gcr_workflow_image_tags: ## List images in gcr.
gcloud container images list --repository=$(GCP_ARTIFACT_REGISTRY_PATH) │
gcloud container images list-tags $(WORKFLOW_IMAGE)
#-------------------
# workflow execution
#-------------------
run_help: ## Print hydra help for execute script.
poetry run dna --help
# Capture additional arguments to pass to hydra-zen cli
# converting them to make do-nothing targets
# supports passing hydra overrides as ARGS, e.g.:
# make run HYDRA_OVERRIDES="entity_config.inputs.logistic_regression.max_iter=2000 execution_context=local_shell"
HYDRA_OVERRIDES = $(filter-out $@,$(MAKECMDGOALS))
%:
@:
.PHONY: run
run: ## Run registered workflow in remote dev mode. (default)
poetry run dna $(HYDRA_OVERRIDES)
run_dev: ## Run registered workflow in remote dev mode.
poetry run dna execution_context=remote_dev $(HYDRA_OVERRIDES)
run_prod: ## Run registered workflow in remote prod mode. (ci default)
poetry run dna execution_context=remote_prod $(HYDRA_OVERRIDES)
run_local_cluster: ## Run registered workflow in local cluster dev mode.
poetry run dna execution_context=local_cluster_dev $(HYDRA_OVERRIDES)
run_local: ## Run registered workflow in local shell mode. (only with all python tasks)
poetry run dna execution_context=local_shell $(HYDRA_OVERRIDES)
#-------------
# system / dev
#-------------
install_direnv: ## Install direnv to `/usr/local/bin`. Check script before execution: https://direnv.net/ .
@which direnv > /dev/null || \
(curl -sfL https://direnv.net/install.sh | bash && \
sudo install -c -m 0755 direnv /usr/local/bin && \
rm -f ./direnv)
@echo "see https://direnv.net/docs/hook.html"
install_flytectl: ## Install flytectl. Check script before execution: https://docs.flyte.org/ .
@which flytectl > /dev/null || \
(curl -sL https://ctl.flyte.org/install | bash)
install_poetry: ## Install poetry. Check script before execution: https://python-poetry.org/docs/#installation .
@which poetry > /dev/null || (curl -sSL https://install.python-poetry.org | python3 -)
install_crane: ## Install crane. Check docs before execution: https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md .
@which crane > /dev/null || ( \
set -e; \
CRANE_VERSION="0.16.1"; \
OS=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
ARCH=$$(uname -m); \
case $$ARCH in \
x86_64|amd64) ARCH="x86_64" ;; \
aarch64|arm64) ARCH="arm64" ;; \
*) echo "Unsupported architecture: $$ARCH" && exit 1 ;; \
esac; \
TMP_DIR=$$(mktemp -d); \
trap 'rm -rf "$$TMP_DIR"' EXIT; \
echo "Downloading crane $$CRANE_VERSION for $$OS $$ARCH to $$TMP_DIR"; \
FILENAME="go-containerregistry_$$OS"_$$ARCH".tar.gz"; \
URL="https://github.com/google/go-containerregistry/releases/download/v$$CRANE_VERSION/$$FILENAME"; \
curl -sSL "$$URL" | tar xz -C $$TMP_DIR; \
sudo mv $$TMP_DIR/crane /usr/local/bin/crane; \
echo "Crane installed successfully to /usr/local/bin/crane" \
)
env_print: ## Print a subset of environment variables defined in ".env" file.
env | grep "GITHUB\|GH_\|GCP_\|FLYTE\|WORKFLOW" | sort
# gh secret set GOOGLE_APPLICATION_CREDENTIALS_DATA --repo="$(GH_REPO)" --body='$(shell cat $(GCP_GACD_PATH))'
ghsecrets: ## Update github secrets for GH_REPO from ".env" file.
@echo "secrets before updates:"
@echo
PAGER=cat gh secret list --repo=$(GH_REPO)
@echo
gh secret set FLYTE_CLUSTER_ENDPOINT --repo="$(GH_REPO)" --body="$(FLYTE_CLUSTER_ENDPOINT)"
gh secret set FLYTE_OAUTH_CLIENT_SECRET --repo="$(GH_REPO)" --body="$(FLYTE_OAUTH_CLIENT_SECRET)"
gh secret set FLYTECTL_CONFIG --repo="$(GH_REPO)" --body="$(FLYTECTL_CONFIG)"
gh secret set GCP_PROJECT_ID --repo="$(GH_REPO)" --body="$(GCP_PROJECT_ID)"
gh secret set GCP_STORAGE_SCOPES --repo="$(GH_REPO)" --body="$(GCP_STORAGE_SCOPES)"
gh secret set GCP_STORAGE_CONTAINER --repo="$(GH_REPO)" --body="$(GCP_STORAGE_CONTAINER)"
gh secret set GCP_ARTIFACT_REGISTRY_PATH --repo="$(GH_REPO)" --body="$(GCP_ARTIFACT_REGISTRY_PATH)"
@echo
@echo secrets after updates:
@echo
PAGER=cat gh secret list --repo=$(GH_REPO)
ghvars: ## Update github secrets for GH_REPO from ".env" file.
@echo "variables before updates:"
@echo
PAGER=cat gh variable list --repo=$(GH_REPO)
@echo
gh variable set WORKFLOW_IMAGE --repo="$(GH_REPO)" --body="$(WORKFLOW_IMAGE)"
@echo
@echo variables after updates:
@echo
PAGER=cat gh variable list --repo=$(GH_REPO)
update_config: ## Update flytectl config file from template.
yq e \
'.admin.endpoint = strenv(FLYTE_CLUSTER_ENDPOINT) | \
.storage.stow.config.project_id = strenv(GCP_PROJECT_ID) | \
.storage.stow.config.scopes = strenv(GCP_STORAGE_SCOPES) | \
.storage.container = strenv(GCP_STORAGE_CONTAINER)' \
.flyte/config-template.yaml > .flyte/config.yaml
tree: ## Print directory tree.
tree -a --dirsfirst -L 4 -I ".git|.direnv|*pycache*|*ruff_cache*|*pytest_cache*|outputs|multirun|conf|scripts"
approve_prs: ## Approve github pull requests from bots: PR_ENTRIES="2-5 10 12-18"
for entry in $(PR_ENTRIES); do \
if [[ "$$entry" == *-* ]]; then \
start=$${entry%-*}; \
end=$${entry#*-}; \
for pr in $$(seq $$start $$end); do \
@gh pr review $$pr --approve; \
done; \
else \
@gh pr review $$entry --approve; \
fi; \
done