Skip to content

Commit

Permalink
chore(devx): make tilt crazy fast (akuity#1248)
Browse files Browse the repository at this point in the history
Signed-off-by: Kent <kent.rancourt@gmail.com>
  • Loading branch information
krancour authored Dec 12, 2023
1 parent 4458bfa commit 6e3c38e
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 33 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
bin/
docs/
ui/node_modules/
45 changes: 42 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
####################################################################################################
# builder
# back-end-builder
####################################################################################################
FROM --platform=$BUILDPLATFORM golang:1.21.4-bookworm as builder
FROM --platform=$BUILDPLATFORM golang:1.21.4-bookworm as back-end-builder

ARG TARGETOS
ARG TARGETARCH
Expand Down Expand Up @@ -61,14 +61,53 @@ RUN GRPC_HEALTH_PROBE_VERSION=v0.4.15 && \
curl -fL -o /tools/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-${TARGETOS}-${TARGETARCH} && \
chmod +x /tools/grpc_health_probe

####################################################################################################
# back-end-dev
# - no UI
# - relies on go build that runs on host
# - supports development
# - not used for official image builds
####################################################################################################
FROM ghcr.io/akuity/kargo-render:v0.1.0-rc.33 as back-end-dev

USER root

COPY --from=tools /tools/ /usr/local/bin/
COPY bin/controlplane/kargo /usr/local/bin/kargo

USER 1000:0

CMD ["/usr/local/bin/kargo"]

####################################################################################################
# ui-dev
# - includes UI dev dependencies
# - runs with vite
# - supports development
# - not used for official image builds
####################################################################################################
FROM --platform=$BUILDPLATFORM docker.io/library/node:20.9.0 AS ui-dev

RUN npm install --global pnpm
WORKDIR /ui
COPY ["ui/package.json", "ui/pnpm-lock.yaml", "./"]

RUN pnpm install

COPY ["ui/", "."]

CMD ["pnpm", "dev"]

####################################################################################################
# final
# - the official image we publish
# - purposefully last so that it is the default target when building
####################################################################################################
FROM ghcr.io/akuity/kargo-render:v0.1.0-rc.33 as final

USER root

COPY --from=builder /kargo/bin/ /usr/local/bin/
COPY --from=back-end-builder /kargo/bin/ /usr/local/bin/
COPY --from=tools /tools/ /usr/local/bin/
COPY --from=ui-builder /ui/build /ui/build

Expand Down
85 changes: 56 additions & 29 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,54 @@ trigger_mode(TRIGGER_MODE_MANUAL)
allow_k8s_contexts('orbstack')

load('ext://namespace', 'namespace_create')
namespace_create('kargo')
k8s_resource(
new_name = 'namespace',
objects = ['kargo:namespace'],
labels = ['kargo']
)

docker_build(
'ghcr.io/akuity/kargo',
'.',
only = [
local_resource(
'back-end-compile',
'CGO_ENABLED=0 GOOS=linux GOARCH=$(go env GOARCH) go build -o bin/controlplane/kargo ./cmd/controlplane',
deps=[
'api/',
'cmd/',
'internal/',
'pkg/',
'ui',
'go.mod',
'go.sum'
],
ignore = ['**/*_test.go'],
build_args = {
'GIT_COMMIT': local('git rev-parse HEAD'),
'GIT_TREE_STATE': local('if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi')
}
labels = ['native-processes'],
trigger_mode = TRIGGER_MODE_AUTO
)
docker_build(
'ghcr.io/akuity/kargo',
'.',
only = ['bin/controlplane/kargo'],
target = 'back-end-dev', # Just the back end, built natively, copied to the image
)

docker_build(
'kargo-ui',
'.',
only = ['ui/'],
target = 'ui-dev', # Just the font end, served by vite, live updated
live_update = [sync('ui', '/ui')]
)

namespace_create('kargo')
k8s_resource(
new_name = 'namespace',
objects = ['kargo:namespace'],
labels = ['kargo']
)

k8s_yaml(
helm(
'./charts/kargo',
name = 'kargo',
namespace = 'kargo',
values = 'hack/tilt/values.dev.yaml'
)
)
# Normally the API server serves up the front end, but we want live updates
# of the UI, so we're breaking it out into its own separate deployment here.
k8s_yaml('hack/tilt/ui.yaml')

k8s_resource(
new_name = 'common',
Expand All @@ -53,7 +76,7 @@ k8s_resource(
'kargo-api:secret',
'kargo-api:serviceaccount'
],
resource_deps=['dex-server']
resource_deps=['back-end-compile','dex-server']
)

k8s_resource(
Expand All @@ -69,7 +92,8 @@ k8s_resource(
'kargo-controller:serviceaccount',
'kargo-controller-argocd:clusterrole',
'kargo-controller-argocd:clusterrolebinding'
]
],
resource_deps=['back-end-compile']
)

k8s_resource(
Expand All @@ -92,7 +116,18 @@ k8s_resource(
'kargo-garbage-collector:clusterrolebinding',
'kargo-garbage-collector:configmap',
'kargo-garbage-collector:serviceaccount'
]
],
resource_deps=['back-end-compile']
)

k8s_resource(
workload = 'kargo-ui',
new_name = 'ui',
port_forwards = [
'30082:3333'
],
labels = ['kargo'],
trigger_mode = TRIGGER_MODE_AUTO
)

k8s_resource(
Expand All @@ -109,7 +144,8 @@ k8s_resource(
'kargo-webhooks-server:serviceaccount',
'kargo-webhooks-server-ns-controller:clusterrole',
'kargo-webhooks-server-ns-controller:clusterrolebinding'
]
],
resource_deps=['back-end-compile']
)

k8s_resource(
Expand All @@ -123,12 +159,3 @@ k8s_resource(
],
labels = ['kargo']
)

k8s_yaml(
helm(
'./charts/kargo',
name = 'kargo',
namespace = 'kargo',
values = 'hack/tilt/values.dev.yaml'
)
)
36 changes: 36 additions & 0 deletions hack/tilt/ui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kargo-ui
namespace: kargo
labels:
app.kubernetes.io/component: ui
app.kubernetes.io/instance: kargo
app.kubernetes.io/name: kargo
spec:
replicas: 1
strategy:
type: RollingUpdate
selector:
matchLabels:
app.kubernetes.io/component: ui
app.kubernetes.io/instance: kargo
app.kubernetes.io/name: kargo
template:
metadata:
labels:
app.kubernetes.io/component: ui
app.kubernetes.io/instance: kargo
app.kubernetes.io/name: kargo
spec:
containers:
- name: ui
image: kargo-ui:placeholder
imagePullPolicy: Always
env:
- name: API_URL
value: http://kargo-api
ports:
- name: http
containerPort: 3333
protocol: TCP

0 comments on commit 6e3c38e

Please sign in to comment.