Skip to content

Commit ec2e40d

Browse files
committed
optional image prefixes
1 parent 86684c2 commit ec2e40d

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

apps/kubernetes-provider/src/index.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { PodCleaner } from "./podCleaner";
1818
import { TaskMonitor } from "./taskMonitor";
1919
import { UptimeHeartbeat } from "./uptimeHeartbeat";
20+
import { assertExhaustive } from "@trigger.dev/core";
2021

2122
const RUNTIME_ENV = process.env.KUBERNETES_PORT ? "kubernetes" : "local";
2223
const NODE_NAME = process.env.NODE_NAME || "local";
@@ -42,6 +43,9 @@ const PRE_PULL_DISABLED = process.env.PRE_PULL_DISABLED === "true";
4243
const ADDITIONAL_PULL_SECRETS = process.env.ADDITIONAL_PULL_SECRETS;
4344
const PAUSE_IMAGE = process.env.PAUSE_IMAGE || "registry.k8s.io/pause:3.9";
4445
const BUSYBOX_IMAGE = process.env.BUSYBOX_IMAGE || "registry.digitalocean.com/trigger/busybox";
46+
const DEPLOYMENT_IMAGE_PREFIX = process.env.DEPLOYMENT_IMAGE_PREFIX;
47+
const RESTORE_IMAGE_PREFIX = process.env.RESTORE_IMAGE_PREFIX;
48+
const UTILITY_IMAGE_PREFIX = process.env.UTILITY_IMAGE_PREFIX;
4549

4650
const logger = new SimpleLogger(`[${NODE_NAME}]`);
4751
logger.log(`running in ${RUNTIME_ENV} mode`);
@@ -107,7 +111,7 @@ class KubernetesTaskOperations implements TaskOperations {
107111
containers: [
108112
{
109113
name: this.#getIndexContainerName(opts.shortCode),
110-
image: opts.imageRef,
114+
image: getImageRef("deployment", opts.imageRef),
111115
ports: [
112116
{
113117
containerPort: 8000,
@@ -174,7 +178,7 @@ class KubernetesTaskOperations implements TaskOperations {
174178
containers: [
175179
{
176180
name: containerName,
177-
image: opts.image,
181+
image: getImageRef("deployment", opts.image),
178182
ports: [
179183
{
180184
containerPort: 8000,
@@ -235,12 +239,12 @@ class KubernetesTaskOperations implements TaskOperations {
235239
initContainers: [
236240
{
237241
name: "pull-base-image",
238-
image: opts.imageRef,
242+
image: getImageRef("deployment", opts.imageRef),
239243
command: ["sleep", "0"],
240244
},
241245
{
242246
name: "populate-taskinfo",
243-
image: BUSYBOX_IMAGE,
247+
image: getImageRef("utility", BUSYBOX_IMAGE),
244248
imagePullPolicy: "IfNotPresent",
245249
command: ["/bin/sh", "-c"],
246250
args: ["printenv COORDINATOR_HOST | tee /etc/taskinfo/coordinator-host"],
@@ -256,7 +260,7 @@ class KubernetesTaskOperations implements TaskOperations {
256260
containers: [
257261
{
258262
name: this.#getRunContainerName(opts.runId),
259-
image: opts.checkpointRef,
263+
image: getImageRef("restore", opts.checkpointRef),
260264
ports: [
261265
{
262266
containerPort: 8000,
@@ -362,7 +366,7 @@ class KubernetesTaskOperations implements TaskOperations {
362366
initContainers: [
363367
{
364368
name: "prepull",
365-
image: opts.imageRef,
369+
image: getImageRef("deployment", opts.imageRef),
366370
command: ["/usr/bin/true"],
367371
resources: {
368372
limits: {
@@ -376,7 +380,7 @@ class KubernetesTaskOperations implements TaskOperations {
376380
containers: [
377381
{
378382
name: "pause",
379-
image: PAUSE_IMAGE,
383+
image: getImageRef("utility", PAUSE_IMAGE),
380384
resources: {
381385
limits: {
382386
cpu: "1m",
@@ -682,6 +686,26 @@ class KubernetesTaskOperations implements TaskOperations {
682686
}
683687
}
684688

689+
type ImageType = "deployment" | "restore" | "utility";
690+
691+
function getImagePrefix(type: ImageType) {
692+
switch (type) {
693+
case "deployment":
694+
return DEPLOYMENT_IMAGE_PREFIX;
695+
case "restore":
696+
return RESTORE_IMAGE_PREFIX;
697+
case "utility":
698+
return UTILITY_IMAGE_PREFIX;
699+
default:
700+
assertExhaustive(type);
701+
}
702+
}
703+
704+
function getImageRef(type: ImageType, ref: string) {
705+
const prefix = getImagePrefix(type);
706+
return prefix ? `${prefix}/${ref}` : ref;
707+
}
708+
685709
const provider = new ProviderShell({
686710
tasks: new KubernetesTaskOperations({
687711
namespace: KUBERNETES_NAMESPACE,

0 commit comments

Comments
 (0)