@@ -3,6 +3,11 @@ import { dirname, isAbsolute, resolve } from "node:path";
33import type { RegistryMap } from "@bunny.net/app-config" ;
44import { createMcClient } from "@bunny.net/openapi-client" ;
55import { resolveConfig } from "../../config/index.ts" ;
6+ import {
7+ REGISTRY_URL_ENV ,
8+ REGISTRY_USERNAME ,
9+ tryResolveRegistryEndpoint ,
10+ } from "../../core/bunny-registry.ts" ;
611import { clientOptions } from "../../core/client-options.ts" ;
712import { bunny } from "../../core/colors.ts" ;
813import { defineCommand } from "../../core/define-command.ts" ;
@@ -124,6 +129,7 @@ async function applyPostPushSuggestions(
124129}
125130
126131import {
132+ BUNNY_REGISTRY_ID ,
127133 buildImage ,
128134 buildImageRef ,
129135 dockerLogin ,
@@ -207,7 +213,8 @@ export const appsDeployCommand = defineCommand<DeployArgs>({
207213 } )
208214 . option ( "registry" , {
209215 type : "string" ,
210- describe : "bunny.net registry ID to push to (overrides bunny.jsonc)" ,
216+ describe :
217+ 'Registry ID to push to, or "bunny" for the bunny.net registry (overrides bunny.jsonc)' ,
211218 } )
212219 . option ( "container" , {
213220 type : "string" ,
@@ -459,17 +466,98 @@ export const appsDeployCommand = defineCommand<DeployArgs>({
459466 if ( mode . kind === "build" ) {
460467 assertDockerfileExists ( mode . dockerfile , targetName ) ;
461468
469+ const bunnyEndpoint = tryResolveRegistryEndpoint ( ) ;
470+ // `--registry bunny` is a friendly alias for the internal sentinel.
471+ if ( registryId === "bunny" ) registryId = BUNNY_REGISTRY_ID ;
472+
462473 // Ensure a registry is selected before we build (we need its hostname).
463474 if ( ! registryId ) {
464- const resolved = await promptRegistry ( client ) ;
475+ const resolved = await promptRegistry ( client , {
476+ bunnyEndpoint : bunnyEndpoint ?? undefined ,
477+ } ) ;
465478 if ( ! resolved ) {
466479 throw new UserError (
467480 "A registry is required to build and push images." ,
468481 ) ;
469482 }
470483 registryId = resolved . id ;
471484 freshCreds = resolved . freshCredentials ;
472- setContainerRegistry ( targetName , registryId ) ;
485+ // TODO: The bunny registry has no account record — don't persist a sentinel AT THE MOMENT
486+ if ( ! resolved . bunny ) setContainerRegistry ( targetName , registryId ) ;
487+ }
488+
489+ // TODO: bunny.net registry (env stub): build + push with the API token, then skip deploy — MC can't pull from it until `/registries` exposes a `bunny` record we can deploy by id.
490+ if ( registryId === BUNNY_REGISTRY_ID ) {
491+ if ( ! bunnyEndpoint ) {
492+ throw new UserError (
493+ "The bunny.net registry endpoint is not configured." ,
494+ `Set ${ REGISTRY_URL_ENV } to the registry URL and try again.` ,
495+ ) ;
496+ }
497+ if ( ! cfg . apiKey ) {
498+ throw new UserError (
499+ "Not logged in." ,
500+ 'Run "bunny login" to authenticate.' ,
501+ ) ;
502+ }
503+
504+ const tag = args . tag ?? ( await generateTag ( ) ) ;
505+ const imageRef = buildImageRef (
506+ bunnyEndpoint . host ,
507+ undefined ,
508+ toml . app . name ,
509+ tag ,
510+ ) ;
511+ const buildCwd = resolveBuildContext ( mode . dockerfile , args . context ) ;
512+
513+ logger . info ( `Building ${ imageRef } ...` ) ;
514+ await buildImage ( mode . dockerfile , imageRef , buildCwd ) ;
515+
516+ if ( noPush ) {
517+ logger . success ( `Image built: ${ imageRef } ` ) ;
518+ logger . dim ( "Skipping push and deploy (--no-push)." ) ;
519+ if ( output === "json" ) {
520+ logger . log (
521+ JSON . stringify ( {
522+ built : true ,
523+ image : imageRef ,
524+ pushed : false ,
525+ deployed : false ,
526+ } ) ,
527+ ) ;
528+ }
529+ return ;
530+ }
531+
532+ const loginSpin = spinner ( `Logging in to ${ bunnyEndpoint . host } ...` ) ;
533+ loginSpin . start ( ) ;
534+ try {
535+ await dockerLogin ( bunnyEndpoint . host , REGISTRY_USERNAME , cfg . apiKey ) ;
536+ } finally {
537+ loginSpin . stop ( ) ;
538+ }
539+
540+ logger . info ( `Pushing ${ imageRef } ...` ) ;
541+ await pushImage ( imageRef ) ;
542+
543+ if ( output === "json" ) {
544+ logger . log (
545+ JSON . stringify ( {
546+ built : true ,
547+ image : imageRef ,
548+ pushed : true ,
549+ deployed : false ,
550+ reason : "mc-pull-unsupported" ,
551+ } ) ,
552+ ) ;
553+ return ;
554+ }
555+
556+ logger . success ( `Pushed ${ imageRef } ` ) ;
557+ logger . warn (
558+ "Magic Containers can't deploy from the bunny.net registry yet — image pushed, deploy skipped." ,
559+ ) ;
560+ return ;
473561 }
474562
475563 const regSpin = spinner ( "Fetching registry..." ) ;
0 commit comments