-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: add Tiltfile for local development
This commit adds a Tiltfile to simplify local development with Tilt. Signed-off-by: Feruzjon Muyassarov <[email protected]>
- Loading branch information
1 parent
82025f6
commit e3183d8
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- mode: Python -*- | ||
|
||
# Extensions | ||
load('ext://helm_resource', 'helm_resource', 'helm_repo') | ||
|
||
# Specifies that Tilt is allowed to run against the specified k8s context name. | ||
allow_k8s_contexts('kubernetes-admin@kubernetes') | ||
# Anoymous, ephemeral image registry. | ||
default_registry('ttl.sh') | ||
|
||
# Run a defined set of services via config.set_enabled_resources. | ||
config.define_string_list("to-run", args=True) | ||
cfg = config.parse() | ||
groups = { | ||
'balloons': ['image-build-logs', 'controller-logs'], | ||
'topology-aware': ['image-build-logs', 'controller-logs'], | ||
} | ||
|
||
resources = [] | ||
for resource_name in cfg.get('to-run', []): | ||
if resource_name in groups: | ||
resources += groups[resource_name] | ||
config.set_enabled_resources(resources) | ||
|
||
# Fail if the policy name is not provided. | ||
if len(resources) == 0: | ||
fail("🚨 ERROR: No policy passed! Please run: tilt up <POLICY_NAME>") | ||
|
||
POLICY = resource_name | ||
IMAGE_BASE = "ttl.sh/ghcr.io/containers/nri-plugins/nri-resource-policy-" | ||
IMAGE = IMAGE_BASE + POLICY | ||
COMPILE_CMD = ( | ||
'cd cmd/plugins/' + POLICY + | ||
'; CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -x -o ../../../build/bin/nri-resource-policy-' + POLICY + ' ./' | ||
) | ||
|
||
################################### | ||
# The main tasks are executed here. | ||
################################### | ||
|
||
# Builds a binary. | ||
local_resource( | ||
'image-build-logs', | ||
COMPILE_CMD, | ||
deps=['./pkg', './cmd', './deployment'] | ||
) | ||
|
||
# Builds a container image. | ||
docker_build( | ||
IMAGE, | ||
'.', | ||
dockerfile='./cmd/plugins/' + POLICY + '/Dockerfile' | ||
) | ||
|
||
# Deploy the policy Helm chart. | ||
helm_resource( | ||
'controller-logs', | ||
'./deployment/helm/' + POLICY, | ||
namespace='kube-system', | ||
deps=['./pkg', './cmd', './deployment'], | ||
image_deps=[IMAGE], | ||
image_keys=[('image.registry', 'image.repository', 'image.tag')], | ||
flags=['--set=image.name=' + IMAGE], | ||
resource_deps=['image-build-logs'] | ||
) |