create-projx 1.7.6 → 1.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import {
8
8
  matchesSkip,
9
9
  saveBaselineRef,
10
10
  writeTemplateToDir
11
- } from "./chunk-NPBLDU4H.js";
11
+ } from "./chunk-OH6QQNPO.js";
12
12
  import "./chunk-N66CVDEV.js";
13
13
  export {
14
14
  BASELINE_REF,
@@ -90,6 +90,39 @@ async function generateCiYml(vars) {
90
90
  async function generateReadme(vars) {
91
91
  return renderShared("README.md.ejs", withInstances(vars));
92
92
  }
93
+ function infraTemplateVars(vars) {
94
+ const projectName = vars.projectName;
95
+ const productionDomain = vars.productionDomain ?? `${projectName}.example.com`;
96
+ const awsRegion = vars.awsRegion ?? "us-east-1";
97
+ const githubOwner = vars.githubOwner ?? "TODO";
98
+ const ecrRepos = vars.ecrRepos ?? [
99
+ `${projectName}/backend`,
100
+ `${projectName}/frontend`
101
+ ];
102
+ const hasBackendMigrations = vars.components.some(
103
+ (c) => c === "fastify" || c === "express"
104
+ );
105
+ const hasAdminPanelMigrations = vars.components.includes("admin-panel");
106
+ return {
107
+ ...vars,
108
+ productionDomain,
109
+ awsRegion,
110
+ githubOwner,
111
+ ecrRepos,
112
+ hasBackendMigrations,
113
+ hasAdminPanelMigrations,
114
+ displayName: projectName.charAt(0).toUpperCase() + projectName.slice(1)
115
+ };
116
+ }
117
+ async function generateRollback(vars) {
118
+ return renderShared("rollback.sh.ejs", infraTemplateVars(vars));
119
+ }
120
+ async function generateCodeowners(vars) {
121
+ return renderShared("codeowners.ejs", infraTemplateVars(vars));
122
+ }
123
+ async function generateRunbook(vars) {
124
+ return renderShared("runbook.md.ejs", infraTemplateVars(vars));
125
+ }
93
126
  function generateVscodeSettings(vars) {
94
127
  const settings = {};
95
128
  if (vars.components.includes("fastapi")) {
@@ -457,6 +490,26 @@ async function writeTemplateToDir(dest, repoDir, components, componentPaths, var
457
490
  );
458
491
  await chmod(join2(dest, "scripts/setup.sh"), 493);
459
492
  }
493
+ if (vars.components.includes("infra")) {
494
+ if (shouldWrite("scripts/rollback.sh")) {
495
+ await mkdir(join2(dest, "scripts"), { recursive: true });
496
+ await writeFile(
497
+ join2(dest, "scripts/rollback.sh"),
498
+ await generateRollback(vars)
499
+ );
500
+ await chmod(join2(dest, "scripts/rollback.sh"), 493);
501
+ }
502
+ if (shouldWrite(".github/CODEOWNERS")) {
503
+ await mkdir(join2(dest, ".github"), { recursive: true });
504
+ await writeFile(
505
+ join2(dest, ".github/CODEOWNERS"),
506
+ await generateCodeowners(vars)
507
+ );
508
+ }
509
+ if (shouldWrite("RUNBOOK.md")) {
510
+ await writeFile(join2(dest, "RUNBOOK.md"), await generateRunbook(vars));
511
+ }
512
+ }
460
513
  await copyStaticFiles(repoDir, dest);
461
514
  if (shouldWrite(".vscode/settings.json")) {
462
515
  await mkdir(join2(dest, ".vscode"), { recursive: true });
@@ -613,7 +666,7 @@ function ormNodeDockerfileSource(manifest, vars) {
613
666
  ENV PATH="$PNPM_HOME:$PATH"
614
667
  RUN corepack enable && corepack prepare pnpm@10.33.0 --activate
615
668
  ` : pmName === "yarn" ? "RUN corepack enable\n" : pmName === "bun" ? "RUN npm install -g bun\n" : "";
616
- const buildCopy = extraConfigCopy ? `COPY package.json tsconfig.json ${extraConfigCopy} ./` : `COPY package.json tsconfig.json ./`;
669
+ const buildCopy = extraConfigCopy ? `COPY package.json tsconfig.json tsconfig.build.json ${extraConfigCopy} ./` : `COPY package.json tsconfig.json tsconfig.build.json ./`;
617
670
  const migrateStage = migrateCmd ? `FROM build AS migrate
618
671
  CMD ["sh", "-c", "${exec} ${migrateCmd}"]
619
672
 
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  matchesSkip,
10
10
  saveBaselineRef,
11
11
  writeTemplateToDir
12
- } from "./chunk-NPBLDU4H.js";
12
+ } from "./chunk-OH6QQNPO.js";
13
13
  import {
14
14
  COMPONENTS,
15
15
  COMPONENT_MARKER,
@@ -903,7 +903,7 @@ function hasUncommittedChanges(cwd) {
903
903
  async function findPinnedFilesWithUpdates(cwd, repoDir, components, componentPaths, vars, version, componentSkips, rootSkip) {
904
904
  const { mkdtemp: mkdtemp2, rm: rm2, readFile: readFile8 } = await import("fs/promises");
905
905
  const { tmpdir: tmpdir2 } = await import("os");
906
- const { writeTemplateToDir: writeTemplateToDir2 } = await import("./baseline-2PBT5JBT.js");
906
+ const { writeTemplateToDir: writeTemplateToDir2 } = await import("./baseline-DT3CWKOO.js");
907
907
  const config = await readProjxConfig(cwd);
908
908
  const rootPinned = Array.isArray(config.skip) ? config.skip : [];
909
909
  const componentPinned = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-projx",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "description": "Scaffold production-grade fullstack projects in seconds. FastAPI, Fastify, Express, React, Flutter, Terraform — with auth, database, CI/CD, E2E tests, and Docker. One command, ready to deploy.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,9 @@
1
+ * @<%= githubOwner %>
2
+
3
+ infra/ @<%= githubOwner %>
4
+ .github/workflows/ @<%= githubOwner %>
5
+ scripts/deploy*.sh @<%= githubOwner %>
6
+ scripts/rollback.sh @<%= githubOwner %>
7
+ <% if (hasBackendMigrations) { %>backend/prisma/migrations/ @<%= githubOwner %>
8
+ <% } %><% if (hasAdminPanelMigrations) { %>admin-panel/internal/db/migrations/ @<%= githubOwner %>
9
+ <% } %>
@@ -23,7 +23,7 @@ services:
23
23
  "CMD",
24
24
  "python",
25
25
  "-c",
26
- "import urllib.request; urllib.request.urlopen('http://localhost:7860/api/health')",
26
+ "import urllib.request; urllib.request.urlopen('http://localhost:7860/api/health/live')",
27
27
  ]
28
28
  interval: 30s
29
29
  timeout: 10s
@@ -61,7 +61,7 @@ services:
61
61
  "CMD",
62
62
  "node",
63
63
  "-e",
64
- "require('http').get('http://localhost:3000/api/health', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))",
64
+ "require('http').get('http://localhost:3000/api/health/live', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))",
65
65
  ]
66
66
  interval: 30s
67
67
  timeout: 10s
@@ -99,7 +99,7 @@ services:
99
99
  "CMD",
100
100
  "node",
101
101
  "-e",
102
- "require('http').get('http://localhost:3000/api/health', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))",
102
+ "require('http').get('http://localhost:3000/api/health/live', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))",
103
103
  ]
104
104
  interval: 30s
105
105
  timeout: 10s
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env bash
2
+ # Roll <%= projectName %> back to a previous main-<sha> image tag in ECR.
3
+ #
4
+ # Usage:
5
+ # scripts/rollback.sh <previous-sha>
6
+ #
7
+ # Required env on the operator workstation:
8
+ # AWS_REGION (default <%= awsRegion %>)
9
+ # ECR_REGISTRY (account-id.dkr.ecr.<%= awsRegion %>.amazonaws.com)
10
+ # EC2_INSTANCE_ID (the <%= projectName %>-web instance)
11
+ # DOMAIN (default <%= productionDomain %>)
12
+
13
+ set -euo pipefail
14
+
15
+ if [[ $# -ne 1 ]]; then
16
+ echo "Usage: $0 <previous-sha>" >&2
17
+ exit 2
18
+ fi
19
+
20
+ PREV_SHA="$1"
21
+ AWS_REGION="${AWS_REGION:-<%= awsRegion %>}"
22
+ DOMAIN="${DOMAIN:-<%= productionDomain %>}"
23
+ TAG="main-${PREV_SHA}"
24
+
25
+ if [[ -z "${ECR_REGISTRY:-}" ]]; then
26
+ echo "ECR_REGISTRY is required" >&2
27
+ exit 2
28
+ fi
29
+ if [[ -z "${EC2_INSTANCE_ID:-}" ]]; then
30
+ echo "EC2_INSTANCE_ID is required" >&2
31
+ exit 2
32
+ fi
33
+
34
+ REPOS=(<% for (const r of ecrRepos) { %>
35
+ <%= r %><% } %>
36
+ )
37
+
38
+ echo "==> Confirming target image exists in ECR for every service"
39
+ for repo in "${REPOS[@]}"; do
40
+ if ! aws ecr describe-images --region "$AWS_REGION" --repository-name "$repo" --image-ids imageTag="$TAG" >/dev/null 2>&1; then
41
+ echo "FATAL: $repo does not have image tag $TAG in ECR" >&2
42
+ exit 3
43
+ fi
44
+ done
45
+
46
+ echo "==> Re-tagging $TAG as main-latest for every service"
47
+ for repo in "${REPOS[@]}"; do
48
+ manifest=$(aws ecr batch-get-image --region "$AWS_REGION" --repository-name "$repo" --image-ids imageTag="$TAG" --query 'images[].imageManifest' --output text)
49
+ if [[ -z "$manifest" ]]; then
50
+ echo "FATAL: failed to read manifest for $repo:$TAG" >&2
51
+ exit 4
52
+ fi
53
+ aws ecr put-image --region "$AWS_REGION" --repository-name "$repo" --image-tag "main-latest" --image-manifest "$manifest" >/dev/null
54
+ echo " re-tagged $repo -> main-latest"
55
+ done
56
+
57
+ echo "==> Triggering deploy on $EC2_INSTANCE_ID with IMAGE_TAG=$TAG"
58
+ COMMAND_ID=$(aws ssm send-command \
59
+ --region "$AWS_REGION" \
60
+ --instance-ids "$EC2_INSTANCE_ID" \
61
+ --document-name AWS-RunShellScript \
62
+ --comment "<%= projectName %> rollback to $TAG" \
63
+ --parameters commands="[\"IMAGE_TAG=$TAG AWS_REGION=$AWS_REGION ECR_REGISTRY=$ECR_REGISTRY DOMAIN=$DOMAIN bash /opt/<%= projectName %>/scripts/deploy-on-ec2.sh\"]" \
64
+ --query 'Command.CommandId' \
65
+ --output text)
66
+
67
+ echo "==> SSM command id: $COMMAND_ID"
68
+ echo "Tail logs with:"
69
+ echo " aws ssm get-command-invocation --region $AWS_REGION --instance-id $EC2_INSTANCE_ID --command-id $COMMAND_ID"
@@ -0,0 +1,64 @@
1
+ # <%= displayName %> Runbook
2
+
3
+ Single source of truth for production recovery, deploys, rollbacks, and incident response.
4
+
5
+ ## Architecture at a glance
6
+
7
+ - Single EC2 (Ubuntu 24.04, `<%= awsRegion %>`) running Docker Compose
8
+ - RDS Postgres, isolated subnets, PITR enabled, `deletion_protection=true`
9
+ - Container registry: ECR
10
+ - IaC: Terraform in [`infra/`](infra/), state in S3 + DynamoDB lock
11
+
12
+ ## Deploy
13
+
14
+ GitHub Actions builds + pushes ECR + SSM SendCommand to the EC2. Operator runs migrate by hand:
15
+
16
+ ```
17
+ aws ssm start-session --target $EC2_INSTANCE_ID
18
+ cd /opt/<%= projectName %>
19
+ docker compose run --rm migrate
20
+ ```
21
+
22
+ ## Rollback (target RTO < 2 minutes)
23
+
24
+ 1. Pick last-known-good `main-<sha>` tag in ECR.
25
+ 2. `scripts/rollback.sh <sha>` — re-tags ECR + SSM-invokes deploy.
26
+ 3. `curl https://<%= productionDomain %>/api/health` must return 200.
27
+
28
+ ## DB restore (point-in-time)
29
+
30
+ Last tested: not yet rehearsed.
31
+
32
+ ```
33
+ aws rds restore-db-instance-to-point-in-time \
34
+ --source-db-instance-identifier <%= projectName %>-1 \
35
+ --target-db-instance-identifier <%= projectName %>-1-restore-$(date +%Y%m%d) \
36
+ --restore-time <iso8601-utc>
37
+ ```
38
+
39
+ Then update `/<%= projectName %>/backend/env` `DATABASE_URL` SSM parameter; `docker compose restart backend`.
40
+
41
+ ## Certificate renewal
42
+
43
+ Let's Encrypt via certbot at `/etc/cron.d/<%= projectName %>-certbot`, daily 03:00.
44
+
45
+ ## Incident channels
46
+
47
+ - Internal alarms: `<%= projectName %>-alerts` SNS topic (subscribe via `var.alert_emails`)
48
+ - Application crashes: Sentry (Node backends: `service_configs` row with purpose `sentry`; FastAPI/frontend: `SENTRY_DSN` / `VITE_SENTRY_DSN` env)
49
+ - Customer-facing: TBD
50
+
51
+ ## Known recovery cliffs (open items)
52
+
53
+ - **Single-AZ RDS** — failover takes minutes until `multi_az=true` flipped.
54
+ - **DR untested** — restore procedure above is theoretical until rehearsed.
55
+ - **`docker container prune` + `docker image prune -a` on every deploy** — `scripts/deploy.sh` aggressively cleans the local Docker store after each successful deploy. This keeps the disk small but means **rollback to a previous image always requires a fresh `docker pull`** rather than a local-cache hit. On a slow link or during a registry outage that blocks the pull, rollback time stretches by however long the pull takes. If the rollback target is more than two deploys old it will not be in the registry's hot cache either. **Mitigation:** for the highest-risk deploys (database migrations, auth surface, payment paths), keep the previous container running on a parallel port for the first 15 minutes post-deploy so an in-place revert does not need any pull at all. Skip the prune step on the deploy host for those windows.
56
+
57
+ ## Common ops
58
+
59
+ | Task | Command |
60
+ | -------------------------- | ------------------------------------------------------------------------------------ |
61
+ | SSH-equivalent | `aws ssm start-session --target $EC2_INSTANCE_ID` |
62
+ | Tail backend logs | `docker logs --tail 200 -f backend` |
63
+ | Run a one-off migration | `docker compose run --rm migrate` |
64
+ | Re-issue certbot | `sudo certbot certonly --nginx --keep-until-expiring -d <%= productionDomain %>` |