Skip to content

Commit

Permalink
feat: added make setup target (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveoconnor committed Aug 27, 2024
1 parent 23e39af commit 31a835b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
38 changes: 38 additions & 0 deletions {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ KUBECTL_EXEC_BACKEND = kubectl exec -it $$(kubectl get pods -l app=backend -o js
KUBECTL_EXEC_FRONTEND = kubectl exec -it $$(kubectl get pods -l app=frontend -o jsonpath="{.items[0].metadata.name}") -- bash
{% endif %}

# colors
BLUE:=$(shell echo "\033[0;36m")
GREEN:=$(shell echo "\033[0;32m")
YELLOW:=$(shell echo "\033[0;33m")
RED:=$(shell echo "\033[0;31m")
END:=$(shell echo "\033[0m")

PROJECT_SLUG:="{{ cookiecutter.project_slug }}"

## Release/Deployment Targets

.PHONY: ci
Expand Down Expand Up @@ -56,6 +65,35 @@ backend/requirements/local.txt: compile
backend/requirements/production.txt: compile
backend/requirements/tests.txt: compile

setup:
@echo " $(YELLOW)$(END) Checking if the setup is correct and all prerequisites are installed..."
@MISSING=""; \
for exec in $(PREREQUISITE_COMMANDS); do \
if ! which $$exec > /dev/null 2>&1; then \
MISSING="$$MISSING $$exec"; \
fi; \
done; \
if [ -n "$$MISSING" ]; then \
echo " $(RED)$(END)Missing executables:$$MISSING. These must be installed by you to continue"; \
false; \
else \
echo " $(GREEN)✔️$(END) All prerequisites are installed."; \
fi
@CURRENT_CONTEXT="$$(kubectl config current-context 2>&1)"; \
if [ "$$CURRENT_CONTEXT" = "kind-$(PROJECT_SLUG)" ]; then \
echo " $(GREEN)✔️$(END) The kubectl context is correctly set to kind-$(PROJECT_SLUG). Run 'tilt up' to start your cluster!"; \
else \
echo " $(YELLOW)$(END) Current kubectl context is not 'kind-$(PROJECT_SLUG)'. Switching context now..."; \
if [ -z "$$(kubectl config get-contexts -o name | grep -w 'kind-$(PROJECT_SLUG)$$')" ]; then \
echo " $(YELLOW)$(END) No context found for kind-$(PROJECT_SLUG). Creating one. Please wait, this may take a couple of minutes on a slower machine..."; \
kind create cluster --name $(PROJECT_SLUG) 1>/dev/null 2>/tmp/scaf_error.log; \
echo " $(GREEN)✔️$(END) kind-$(PROJECT_SLUG) cluster and context created."; \
echo " $(BLUE)🗣️ Remember, you can safely run \"make setup\" any time to switch between Scaf projects.$(END)"; \
fi; \
kubectl config use-context kind-$(PROJECT_SLUG) 1>/dev/null 2>/tmp/scaf_error.log; \
echo " $(GREEN)✔️$(END) Context switched to kind-$(PROJECT_SLUG). Run 'tilt up' to start your cluster! "; \
fi

outdated: ## Show all the outdated packages with their latest versions in the container
$(KUBECTL_EXEC_BACKEND) -c "pip list --outdated"

Expand Down
29 changes: 8 additions & 21 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,15 @@ Consult the links below if you prefer to use Minikube or Docker Desktop instead:

### Run the kubernetes cluster and the {{ cookiecutter.project_slug }} app to develop the code

1. Load the environment variables.
First load the environment variables, then run:

2. Start the local kubernetes cluster:

$ kind create cluster --name {{ cookiecutter.project_slug }}
* If you want to create a cluster with a different name, run:

$ kind create cluster --name <alt-project-name>

2. You can verify that it is running with

$ kubectl cluster-info

3. Verify the context with:

$ kubectl config current-context

4. To spin up the app and all the services such as the database, use

$ tilt up
$ make setup
$ tilt up

:information_source: It may take a little bit of time for all the services to start up, and it's possible for
the first run to fail because of timing conflicts. If you do see messages indicating there
were errors during the first run, stop all the containers using Ctrl-C, and then try it again.

:information_source: You can type `s` to view the console output as it starts up to confirm that the process isn't hanging.

You are now ready to edit the code.
The app will be automatically reloaded when its files change.

Expand All @@ -63,6 +45,11 @@ To remove the cluster entirely:

$ kind delete cluster --name {{ cookiecutter.project_slug }}

To switch between different Scaf project contexts:

$ tilt down # inside the codebase of the previous project
$ make setup # inside the codebase of the project you want to work on
$ tilt up

### Update dependencies

Expand Down

0 comments on commit 31a835b

Please sign in to comment.