-
Notifications
You must be signed in to change notification settings - Fork 44
/
Makefile
139 lines (118 loc) · 5.16 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
ENV := $(shell cat .last_used_env || echo "not-set")
-include .env.${ENV}
OTEL_TRACING_PRINT ?= false
IMAGE := e2b-orchestration/api
EXCLUDE_GITHUB ?= 1
tf_vars := TF_VAR_client_machine_type=$(CLIENT_MACHINE_TYPE) \
TF_VAR_client_cluster_size=$(CLIENT_CLUSTER_SIZE) \
TF_VAR_server_machine_type=$(SERVER_MACHINE_TYPE) \
TF_VAR_server_cluster_size=$(SERVER_CLUSTER_SIZE) \
TF_VAR_gcp_project_id=$(GCP_PROJECT_ID) \
TF_VAR_gcp_region=$(GCP_REGION) \
TF_VAR_gcp_zone=$(GCP_ZONE) \
TF_VAR_domain_name=$(DOMAIN_NAME) \
TF_VAR_prefix=$(PREFIX) \
TF_VAR_terraform_state_bucket=$(TERRAFORM_STATE_BUCKET) \
TF_VAR_otel_tracing_print=$(OTEL_TRACING_PRINT) \
TF_VAR_environment=$(TERRAFORM_ENVIRONMENT)
ifeq ($(EXCLUDE_GITHUB),1)
ALL_MODULES := $(shell cat main.tf | grep "^module" | awk '{print $$2}' | grep -v -e "github_tf")
else
ALL_MODULES := $(shell cat main.tf | grep "^module" | awk '{print $$2}')
endif
WITHOUT_JOBS := $(shell echo $(ALL_MODULES) | tr ' ' '\n' | grep -v -e "nomad" | awk '{print "-target=module." $$0 ""}' | xargs)
ALL_MODULES_ARGS := $(shell echo $(ALL_MODULES) | tr ' ' '\n' | awk '{print "-target=module." $$0 ""}' | xargs)
DESTROY_TARGETS := $(shell terraform state list | grep module | cut -d'.' -f1,2 | grep -v -e "fc_envs_disk" -e "buckets" | uniq | awk '{print "-target=" $$0 ""}' | xargs)
# Login for Packer and Docker (uses gcloud user creds)
# Login for Terraform (uses application default creds)
.PHONY: login-gcloud
login-gcloud:
gcloud auth login
gcloud config set project "$(GCP_PROJECT_ID)"
gcloud --quiet auth configure-docker "$(GCP_REGION)-docker.pkg.dev"
gcloud auth application-default login
.PHONY: init
init:
@ printf "Initializing Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
./scripts/confirm.sh $(ENV)
terraform init -input=false -backend-config="bucket=${TERRAFORM_STATE_BUCKET}"
$(MAKE) -C packages/cluster-disk-image init
$(tf_vars) terraform apply -target=module.init -target=module.buckets -auto-approve -input=false -compact-warnings
gcloud auth configure-docker "${GCP_REGION}-docker.pkg.dev" --quiet
.PHONY: plan
plan:
@ printf "Planning Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
terraform fmt -recursive
$(tf_vars) terraform plan -out=.tfplan.$(ENV) -compact-warnings -detailed-exitcode $(ALL_MODULES_ARGS)
.PHONY: apply
apply:
@ printf "Applying Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
./scripts/confirm.sh $(ENV)
$(tf_vars) \
terraform apply \
-auto-approve \
-input=false \
-compact-warnings \
-parallelism=20 \
.tfplan.$(ENV)
@ rm .tfplan.$(ENV)
.PHONY: plan-without-jobs
plan-without-jobs:
@ printf "Planning Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
$(tf_vars) \
terraform plan \
-out=.tfplan.$(ENV) \
-input=false \
-compact-warnings \
-parallelism=20 \
$(WITHOUT_JOBS)
.PHONY: destroy
destroy:
@ printf "Destroying Terraform for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
./scripts/confirm.sh $(ENV)
$(tf_vars) \
terraform destroy \
-compact-warnings \
-parallelism=20 \
$(DESTROY_TARGETS)
.PHONY: version
version:
./scripts/increment-version.sh
.PHONY: build-and-upload
build-and-upload:
$(MAKE) -C packages/cluster-disk-image build
GCP_PROJECT_ID=$(GCP_PROJECT_ID) make update-api
GCP_PROJECT_ID=$(GCP_PROJECT_ID) $(MAKE) -C packages/docker-reverse-proxy build-and-upload
GCP_PROJECT_ID=$(GCP_PROJECT_ID) $(MAKE) -C packages/orchestrator build-and-upload
GCP_PROJECT_ID=$(GCP_PROJECT_ID) $(MAKE) -C packages/template-manager build-and-upload
GCP_PROJECT_ID=$(GCP_PROJECT_ID) $(MAKE) -C packages/envd build-and-upload
.PHONY: copy-public-builds
copy-public-builds:
gsutil cp -r gs://e2b-prod-public-builds/envd-v0.0.1 gs://$(GCP_PROJECT_ID)-fc-env-pipeline/envd-v0.0.1
gsutil cp -r gs://e2b-prod-public-builds/kernels/* gs://$(GCP_PROJECT_ID)-fc-kernels/
gsutil cp -r gs://e2b-prod-public-builds/firecrackers/* gs://$(GCP_PROJECT_ID)-fc-versions/
migrate:
GCP_PROJECT_ID=$(GCP_PROJECT_ID) $(MAKE) -C packages/shared migrate
.PHONY: update-api
update-api:
docker buildx install # sets up the buildx as default docker builder (otherwise the command below won't work)
docker build --platform linux/amd64 --tag "$(GCP_REGION)-docker.pkg.dev/$(GCP_PROJECT_ID)/$(IMAGE)" --push -f api.Dockerfile .
.PHONY: switch-env
switch-env:
@ touch .last_used_env
@ printf "Switching from `tput setaf 1``tput bold`$(shell cat .last_used_env)`tput sgr0` to `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
@ echo $(ENV) > .last_used_env
@ . .env.${ENV}
terraform init -input=false -upgrade -reconfigure -backend-config="bucket=${TERRAFORM_STATE_BUCKET}"
# Shortcut to importing resources into Terraform state (e.g. after creating resources manually or switching between different branches for the same environment)
.PHONY: import
import:
@ printf "Importing resources for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n\n"
./scripts/confirm.sh $(ENV)
$(tf_vars) terraform import $(TARGET) $(ID)
.PHONY: setup-ssh
setup-ssh:
@ printf "Setting up SSH for env: `tput setaf 2``tput bold`$(ENV)`tput sgr0`\n"
@ gcloud compute config-ssh --remove
@ gcloud compute config-ssh --project $(GCP_PROJECT_ID) --quiet
@ printf "SSH setup complete\n"