11import { existsSync , readFileSync } from 'fs' ;
22import { Listr } from 'listr2' ;
3- import { runRemoteCommand } from '../runner.js' ;
3+ import { runRemoteCommandForTargets } from '../runner.js' ;
44import { ui } from '../ui.js' ;
55import type { RemoteExecutor } from '../../domain/remote/executor.js' ;
66import type { ShipnodeConfig , NetworkDatabaseConfig } from '../../shared/types.js' ;
@@ -22,11 +22,11 @@ interface SetupOptions {
2222}
2323
2424export async function cmdSetup ( cwd : string , options : SetupOptions ) : Promise < void > {
25- await runRemoteCommand (
25+ await runRemoteCommandForTargets (
2626 cwd ,
27- async ( { config, executor } ) => {
27+ async ( { config, executor, serverName } ) => {
2828 ui . banner ( ) ;
29- ui . step ( `Setting up ${ config . ssh . user } @${ config . ssh . host } ` ) ;
29+ ui . step ( `Setting up ${ serverName } ( ${ config . ssh . user } @${ config . ssh . host } ) ` ) ;
3030 const created = ! options . noDeployUser && ( await bootstrapDeployUser ( cwd , config , executor ) ) ;
3131 await buildTasks ( executor , config , created ? DEPLOY_USER : null ) . run ( ) ;
3232 if ( created ) {
@@ -43,7 +43,7 @@ export async function cmdSetup(cwd: string, options: SetupOptions): Promise<void
4343 ui . outro ( 'Server ready — run: shipnode deploy' ) ;
4444 }
4545 } ,
46- { configPath : options . config } ,
46+ { configPath : options . config , includeEmpty : true } ,
4747 ) ;
4848}
4949
@@ -99,6 +99,8 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
9999 // so PM2 processes run as that user and `pm2-<user>.service` matches. Without
100100 // this, everything lands in root's home and deploy has no pm2 on their PATH.
101101 const targetHome = ownerUser ? `/home/${ ownerUser } ` : '$HOME' ;
102+ const hasApps = config . apps . length > 0 ;
103+ const hasAccessories = Object . keys ( config . accessories ?? { } ) . length > 0 ;
102104
103105 return new Listr (
104106 [
@@ -120,7 +122,7 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
120122 } ,
121123 ] , { concurrent : false } ) ,
122124 } ,
123- {
125+ ... ( hasApps ? [ {
124126 title : `Mise (version manager)${ ownerUser ? ` for ${ ownerUser } ` : '' } ` ,
125127 task : ( ) =>
126128 executor . execOrThrow (
@@ -129,8 +131,8 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
129131 `if ! command -v mise &>/dev/null && [ ! -x "$HOME/.local/bin/mise" ]; then curl -fsSL https://mise.run | sh; fi` ,
130132 ) ,
131133 ) ,
132- } ,
133- {
134+ } ] : [ ] ) ,
135+ ... ( hasApps ? [ {
134136 title : `Node.js ${ config . nodeVersion } ` ,
135137 task : ( _ctx : object , task : any ) => task . newListr ( [
136138 {
@@ -142,8 +144,8 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
142144 task : ( ) => executor . execOrThrow ( asUser ( ownerUser , `${ mise } ; mise use -g -y "node@${ nodeVersion } "` ) ) ,
143145 } ,
144146 ] , { concurrent : false } ) ,
145- } ,
146- {
147+ } ] : [ ] ) ,
148+ ... ( hasApps && config . apps . some ( ( app ) => app . appType === 'backend' && app . pm2 ) ? [ {
147149 title : 'PM2' ,
148150 task : ( _ctx : object , task : any ) => task . newListr ( [
149151 {
@@ -180,8 +182,8 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
180182 ) ,
181183 } ,
182184 ] , { concurrent : false } ) ,
183- } ,
184- {
185+ } ] : [ ] ) ,
186+ ... ( hasApps && config . apps . some ( ( app ) => app . domain ) ? [ {
185187 title : 'Caddy' ,
186188 task : ( ) =>
187189 executor . execOrThrow (
@@ -193,7 +195,23 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
193195 ' $SUDO apt-get update && $SUDO apt-get install -y caddy; ' +
194196 'fi' ,
195197 ) ,
196- } ,
198+ } ] : [ ] ) ,
199+ ...( hasAccessories ? [ {
200+ title : 'Docker' ,
201+ task : ( ) =>
202+ executor . execOrThrow (
203+ 'SUDO=""; [ "$EUID" -ne 0 ] && SUDO="sudo"; ' +
204+ 'if ! command -v docker &>/dev/null; then ' +
205+ ' $SUDO apt-get install -y ca-certificates curl gnupg; ' +
206+ ' $SUDO install -m 0755 -d /etc/apt/keyrings; ' +
207+ ' curl -fsSL https://download.docker.com/linux/ubuntu/gpg | $SUDO gpg --dearmor -o /etc/apt/keyrings/docker.gpg; ' +
208+ ' $SUDO chmod a+r /etc/apt/keyrings/docker.gpg; ' +
209+ ' echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | $SUDO tee /etc/apt/sources.list.d/docker.list > /dev/null; ' +
210+ ' $SUDO apt-get update && $SUDO apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin; ' +
211+ 'fi; ' +
212+ '$SUDO systemctl enable docker && $SUDO systemctl start docker' ,
213+ ) ,
214+ } ] : [ ] ) ,
197215 ...( config . database && config . database . type !== 'sqlite' && config . database . host === 'localhost'
198216 ? [ {
199217 title : `Database (${ config . database . type } )` ,
@@ -234,7 +252,7 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
234252 } ,
235253 } ]
236254 : [ ] ) ,
237- {
255+ ... ( hasApps ? [ {
238256 title : 'Deployment directories' ,
239257 task : ( _ctx : object , task : any ) => task . newListr ( [
240258 {
@@ -248,7 +266,7 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
248266 : `mkdir -p "${ config . remotePath } /releases" "${ config . remotePath } /shared" "${ config . remotePath } /.shipnode"` ) ,
249267 ) ,
250268 } ,
251- {
269+ ... ( config . apps . some ( ( app ) => app . domain ) ? [ {
252270 title : 'Configure Caddy include' ,
253271 task : ( ) => executor . execOrThrow (
254272 'SUDO=""; [ "$EUID" -ne 0 ] && SUDO="sudo"; ' +
@@ -257,9 +275,9 @@ function buildTasks(executor: RemoteExecutor, config: ShipnodeConfig, ownerUser:
257275 'echo "import /etc/caddy/conf.d/*.caddy" | $SUDO tee -a /etc/caddy/Caddyfile > /dev/null && ' +
258276 '$SUDO systemctl reload caddy 2>/dev/null || true' ,
259277 ) ,
260- } ,
278+ } ] : [ ] ) ,
261279 ] , { concurrent : false } ) ,
262- } ,
280+ } ] : [ ] ) ,
263281 ] ,
264282 { rendererOptions : { collapseErrors : false } } ,
265283 ) ;
0 commit comments