Skip to content

Commit 0e6bd60

Browse files
committed
remove --self-hosted flag
1 parent 3f6c446 commit 0e6bd60

5 files changed

Lines changed: 24 additions & 29 deletions

File tree

apps/webapp/app/v3/remoteImageBuilder.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { prisma } from "~/db.server";
44
import { env } from "~/env.server";
55

66
export async function createRemoteImageBuild(project: Project) {
7-
if (!env.DEPOT_TOKEN || !env.DEPOT_PROJECT_ID) {
7+
if (!remoteBuildsEnabled()) {
88
return;
99
}
1010

@@ -57,3 +57,7 @@ async function createBuilderProjectIfNotExists(project: Project) {
5757

5858
return result.project.projectId;
5959
}
60+
61+
export function remoteBuildsEnabled() {
62+
return env.DEPOT_TOKEN && env.DEPOT_PROJECT_ID && env.DEPOT_ORG_ID && env.DEPOT_REGION;
63+
}

apps/webapp/app/v3/services/finalizeDeploymentV2.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { mkdtemp, writeFile } from "node:fs/promises";
88
import { env } from "~/env.server";
99
import { depot as execDepot } from "@depot/cli";
1010
import { FinalizeDeploymentService } from "./finalizeDeployment.server";
11+
import { remoteBuildsEnabled } from "../remoteImageBuilder.server";
1112

1213
export class FinalizeDeploymentV2Service extends BaseService {
1314
public async call(
@@ -16,10 +17,9 @@ export class FinalizeDeploymentV2Service extends BaseService {
1617
body: FinalizeDeploymentRequestBody,
1718
writer?: WritableStreamDefaultWriter
1819
) {
19-
// if it's self hosted, lets just use the v1 finalize deployment service
20-
if (body.selfHosted) {
20+
// If remote builds are not enabled, lets just use the v1 finalize deployment service
21+
if (!remoteBuildsEnabled()) {
2122
const finalizeService = new FinalizeDeploymentService();
22-
2323
return finalizeService.call(authenticatedEnv, id, body);
2424
}
2525

apps/webapp/app/v3/services/initializeDeployment.server.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { env } from "~/env.server";
55
import { type AuthenticatedEnvironment } from "~/services/apiAuth.server";
66
import { logger } from "~/services/logger.server";
77
import { generateFriendlyId } from "../friendlyIdentifiers";
8-
import { createRemoteImageBuild } from "../remoteImageBuilder.server";
8+
import { createRemoteImageBuild, remoteBuildsEnabled } from "../remoteImageBuilder.server";
99
import { calculateNextBuildVersion } from "../utils/calculateNextBuildVersion";
1010
import { BaseService, ServiceValidationError } from "./baseService.server";
1111
import { TimeoutDeploymentService } from "./timeoutDeployment.server";
@@ -46,13 +46,17 @@ export class InitializeDeploymentService extends BaseService {
4646

4747
const nextVersion = calculateNextBuildVersion(latestDeployment?.version);
4848

49+
if (payload.selfHosted && remoteBuildsEnabled()) {
50+
throw new ServiceValidationError(
51+
"Self-hosted deployments are not supported on this instance"
52+
);
53+
}
54+
4955
// Try and create a depot build and get back the external build data
50-
const externalBuildData = payload.selfHosted
51-
? undefined
52-
: await createRemoteImageBuild(environment.project);
56+
const externalBuildData = await createRemoteImageBuild(environment.project);
5357

5458
const triggeredBy = payload.userId
55-
? await this._prisma.user.findUnique({
59+
? await this._prisma.user.findFirst({
5660
where: {
5761
id: payload.userId,
5862
orgMemberships: {

packages/cli-v3/src/commands/deploy.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const DeployCommandOptions = CommonCommandOptions.extend({
4848
loadImage: z.boolean().default(false),
4949
buildPlatform: z.enum(["linux/amd64", "linux/arm64"]).default("linux/amd64"),
5050
namespace: z.string().optional(),
51-
selfHosted: z.boolean().default(false),
5251
registry: z.string().optional(),
5352
push: z.boolean().default(false),
5453
config: z.string().optional(),
@@ -103,12 +102,6 @@ export function configureDeployCommand(program: Command) {
103102
"Skip promoting the deployment to the current deployment for the environment."
104103
)
105104
)
106-
.addOption(
107-
new CommandOption(
108-
"--self-hosted",
109-
"Build and load the image using your local Docker. Use the --registry option to specify the registry to push the image to when using --self-hosted, or just use --push to push to the default registry."
110-
).hideHelp()
111-
)
112105
.addOption(
113106
new CommandOption(
114107
"--no-cache",
@@ -319,7 +312,6 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
319312
const deploymentResponse = await projectClient.client.initializeDeployment({
320313
contentHash: buildManifest.contentHash,
321314
userId: authorization.userId,
322-
selfHosted: options.selfHosted,
323315
registryHost: options.registry,
324316
namespace: options.namespace,
325317
gitMeta,
@@ -331,16 +323,10 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
331323
}
332324

333325
const deployment = deploymentResponse.data;
326+
const isLocalBuild = !deployment.externalBuildData;
334327

335-
// If the deployment doesn't have any externalBuildData, then we can't use the remote image builder
336-
// TODO: handle this and allow the user to the build and push the image themselves
337-
if (!deployment.externalBuildData && !options.selfHosted) {
338-
throw new Error(
339-
`Failed to start deployment, as your instance of trigger.dev does not support hosting. To deploy this project, you must use the --self-hosted flag to build and push the image yourself.`
340-
);
341-
}
342-
343-
if (options.selfHosted) {
328+
// Fail fast if we know local builds will fail
329+
if (isLocalBuild) {
344330
const result = await x("docker", ["buildx", "version"]);
345331

346332
if (result.exitCode !== 0) {
@@ -416,7 +402,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
416402
const registryHost = selfHostedRegistryHost ?? "registry.trigger.dev";
417403

418404
const buildResult = await buildImage({
419-
selfHosted: options.selfHosted,
405+
selfHosted: isLocalBuild,
420406
buildPlatform: options.buildPlatform,
421407
noCache: options.noCache,
422408
push: options.push,
@@ -512,7 +498,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
512498
throw new SkipLoggingError("Failed to get deployment with worker");
513499
}
514500

515-
const imageReference = options.selfHosted
501+
const imageReference = isLocalBuild
516502
? `${selfHostedRegistryHost ? `${selfHostedRegistryHost}/` : ""}${buildResult.image}${
517503
buildResult.digest ? `@${buildResult.digest}` : ""
518504
}`
@@ -532,7 +518,6 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
532518
deployment.id,
533519
{
534520
imageReference,
535-
selfHosted: options.selfHosted,
536521
skipPromotion: options.skipPromotion,
537522
},
538523
(logMessage) => {

packages/core/src/v3/schemas/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ export type StartDeploymentIndexingResponseBody = z.infer<
293293

294294
export const FinalizeDeploymentRequestBody = z.object({
295295
imageReference: z.string(),
296+
/** @deprecated This is now determined by the webapp */
296297
selfHosted: z.boolean().optional(),
297298
skipRegistryProxy: z.boolean().optional(),
298299
skipPromotion: z.boolean().optional(),
@@ -338,6 +339,7 @@ export const InitializeDeploymentRequestBody = z.object({
338339
contentHash: z.string(),
339340
userId: z.string().optional(),
340341
registryHost: z.string().optional(),
342+
/** @deprecated This is now determined by the webapp */
341343
selfHosted: z.boolean().optional(),
342344
namespace: z.string().optional(),
343345
gitMeta: GitMeta.optional(),

0 commit comments

Comments
 (0)