Skip to content

Commit be413a1

Browse files
committed
docs: document multi-environment deploy patterns
Two patterns shown: separate shipnode.<env>.config.ts files driven by --config <path>, or a single config file switched on SHIPNODE_ENV. No new CLI surface — both use the existing --config flag.
1 parent 8f7ffc5 commit be413a1

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ All notable changes to `@devalade/shipnode` will be documented here.
1818
### Fixed
1919
- **Builds no longer fail because devDependencies are missing.** The default install commands for `npm`, `yarn`, and `bun` no longer pass `--production` / `--frozen-lockfile --production` — they now install everything so the subsequent build step has access to `tsc`, `vite`, `tsup`, etc. (pnpm was already fixed for this in v2.0.13; this completes the same fix for the other package managers.)
2020

21+
### Documentation
22+
- README: new "Multiple environments" section showing two patterns for staging/production splits — separate `shipnode.<env>.config.ts` files driven by `--config <path>`, or a single config file switched on `SHIPNODE_ENV`. No new CLI surface; both patterns use the existing `--config` flag that every command already accepts.
23+
2124
### Added
2225
- Two ways to override the server-side install command when you need flags the default doesn't carry (e.g. `'npm ci --legacy-peer-deps'`):
2326
- `.installCommand(cmd)` — standalone builder method.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,85 @@ export default shipnode
7777
.build();
7878
```
7979

80+
### Multiple environments (staging, production, …)
81+
82+
Shipnode itself stays out of the environment concept — every command takes `--config <path>`, and you keep one config file per environment.
83+
84+
```
85+
shipnode.staging.config.ts
86+
shipnode.production.config.ts
87+
```
88+
89+
```ts
90+
// shipnode.staging.config.ts
91+
import { shipnode } from '@devalade/shipnode';
92+
93+
export default shipnode
94+
.backend()
95+
.ssh({ host: 'staging.example.com', user: 'deploy' })
96+
.deployTo('/var/www/staging')
97+
.pm2('myapp-staging', { instances: 1 })
98+
.port(3000)
99+
.domain('staging.example.com')
100+
.envFile('.env.staging')
101+
.build();
102+
```
103+
104+
```ts
105+
// shipnode.production.config.ts
106+
import { shipnode } from '@devalade/shipnode';
107+
108+
export default shipnode
109+
.backend()
110+
.ssh({ host: 'prod.example.com', user: 'deploy' })
111+
.deployTo('/var/www/prod')
112+
.pm2('myapp', { instances: 2, maxMemory: '1G' })
113+
.port(3000)
114+
.domain('api.example.com')
115+
.envFile('.env.production')
116+
.build();
117+
```
118+
119+
```bash
120+
shipnode deploy --config shipnode.staging.config.ts
121+
shipnode logs --config shipnode.staging.config.ts
122+
shipnode rollback --config shipnode.production.config.ts
123+
```
124+
125+
Or factor the shared parts out and switch on an env var when you have many environments:
126+
127+
```ts
128+
// shipnode.config.ts
129+
import { shipnode } from '@devalade/shipnode';
130+
131+
const ENV = process.env.SHIPNODE_ENV ?? 'production';
132+
133+
const targets = {
134+
staging: { host: 'staging.example.com', remotePath: '/var/www/staging', domain: 'staging.example.com', envFile: '.env.staging', instances: 1 },
135+
production: { host: 'prod.example.com', remotePath: '/var/www/prod', domain: 'api.example.com', envFile: '.env.production', instances: 2 },
136+
} as const;
137+
138+
const t = targets[ENV as keyof typeof targets];
139+
if (!t) throw new Error(`Unknown SHIPNODE_ENV: ${ENV}`);
140+
141+
export default shipnode
142+
.backend()
143+
.ssh({ host: t.host, user: 'deploy' })
144+
.deployTo(t.remotePath)
145+
.pm2(`myapp-${ENV}`, { instances: t.instances })
146+
.port(3000)
147+
.domain(t.domain)
148+
.envFile(t.envFile)
149+
.build();
150+
```
151+
152+
```bash
153+
SHIPNODE_ENV=staging shipnode deploy
154+
SHIPNODE_ENV=production shipnode deploy
155+
```
156+
157+
The PM2 namespace prefix (`myapp-staging` vs `myapp`) keeps the processes distinct if you ever co-locate environments on one host.
158+
80159
### Frontend apps
81160

82161
```ts

0 commit comments

Comments
 (0)