Skip to content

Commit 1defa5c

Browse files
committed
WIP
1 parent c1ff653 commit 1defa5c

38 files changed

+3508
-325
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ assets/img/.DS_Store
7070

7171
# VSCode related files #
7272
# .vscode
73+
test-strapi-project/
74+
dist/

dist/cli.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/cli.js

Lines changed: 0 additions & 302 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"node": ">=18.0.0"
99
},
1010
"bin": {
11-
"strapi-dockerize": "./dist/cli.js"
11+
"strapi-dockerize": "./dist/index.js"
1212
},
1313
"files": [
1414
"dist",
@@ -33,6 +33,8 @@
3333
"dev:watch": "tsx watch src/cli.tsx"
3434
},
3535
"dependencies": {
36+
"@clack/core": "^0.5.0",
37+
"@clack/prompts": "^0.11.0",
3638
"@inkjs/ui": "^1.0.0",
3739
"@types/ink-spinner": "^3.0.4",
3840
"chalk": "^5.3.0",
@@ -47,7 +49,7 @@
4749
"ink-select-input": "^5.0.0",
4850
"ink-spinner": "^5.0.0",
4951
"ink-text-input": "^5.0.1",
50-
"liquidjs": "^10.10.1",
52+
"liquidjs": "^10.21.1",
5153
"node-fetch": "^3.3.2",
5254
"ora": "^8.0.1",
5355
"react": "^18.2.0",
@@ -103,5 +105,8 @@
103105
"extends": [
104106
"@commitlint/config-conventional"
105107
]
108+
},
109+
"volta": {
110+
"node": "22.17.0"
106111
}
107112
}

pnpm-lock.yaml

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generators.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import type { StrapiProject, DockerConfig } from "./types";
2+
import { Liquid } from "liquidjs";
3+
import { readFileSync } from "fs";
4+
import { join } from "path";
5+
import {
6+
writeFilesWithEnv,
7+
generateSecrets,
8+
type FileToWrite,
9+
type EnvFileToWrite,
10+
} from "./utils/file-writer";
11+
12+
export async function generateDockerFiles(
13+
project: StrapiProject,
14+
config: DockerConfig
15+
): Promise<void> {
16+
console.log("🐳 Generating complete Docker setup...");
17+
18+
const liquid = new Liquid();
19+
const secrets = generateSecrets();
20+
21+
// Map database types to Strapi database clients
22+
const databaseClientMap = {
23+
postgresql: "postgres",
24+
mysql: "mysql",
25+
mariadb: "mysql", // MariaDB uses mysql client in Strapi
26+
sqlite: "sqlite",
27+
};
28+
29+
// Prepare template variables
30+
const templateVars = {
31+
packageManager: project.packageManager,
32+
environment:
33+
config.environment === "both" ? "development" : config.environment,
34+
database: {
35+
client: databaseClientMap[config.database.type],
36+
type: config.database.type,
37+
serviceName:
38+
config.database.type === "postgresql"
39+
? "strapiDB"
40+
: config.database.type,
41+
name: config.database.name,
42+
user: config.database.user,
43+
password: config.database.password,
44+
port: config.database.port,
45+
host: config.database.host,
46+
image:
47+
config.database.type === "postgresql"
48+
? "postgres"
49+
: config.database.type === "mariadb"
50+
? "mariadb"
51+
: "mysql",
52+
tag:
53+
config.database.type === "postgresql"
54+
? "16.0-alpine"
55+
: config.database.type === "mariadb"
56+
? "10.11"
57+
: "8.0",
58+
charset: "utf8mb4",
59+
collation: "utf8mb4_unicode_ci",
60+
},
61+
secrets,
62+
};
63+
64+
const files: FileToWrite[] = [];
65+
66+
// Generate Dockerfile (development)
67+
const dockerfilePath = join(
68+
__dirname,
69+
"templates/dockerfile/development.liquid"
70+
);
71+
const dockerfileTemplate = readFileSync(dockerfilePath, "utf8");
72+
const dockerfile = await liquid.parseAndRender(
73+
dockerfileTemplate,
74+
templateVars
75+
);
76+
77+
files.push({
78+
path: "Dockerfile",
79+
content: dockerfile,
80+
description: "Development Dockerfile",
81+
});
82+
83+
// Generate Dockerfile.prod (production) if production or both
84+
if (config.environment === "production" || config.environment === "both") {
85+
const dockerfileProdPath = join(
86+
__dirname,
87+
"templates/dockerfile/production.liquid"
88+
);
89+
const dockerfileProdTemplate = readFileSync(dockerfileProdPath, "utf8");
90+
const dockerfileProd = await liquid.parseAndRender(
91+
dockerfileProdTemplate,
92+
templateVars
93+
);
94+
95+
files.push({
96+
path: "Dockerfile.prod",
97+
content: dockerfileProd,
98+
description: "Production Dockerfile",
99+
});
100+
}
101+
102+
// Generate docker-compose.yml if requested
103+
if (config.useCompose) {
104+
// SQLite uses a different template (no separate database service)
105+
const templateName =
106+
config.database.type === "sqlite" ? "sqlite" : "complete";
107+
const composePath = join(
108+
__dirname,
109+
`templates/compose/${templateName}.liquid`
110+
);
111+
const composeTemplate = readFileSync(composePath, "utf8");
112+
const compose = await liquid.parseAndRender(composeTemplate, templateVars);
113+
114+
const description =
115+
config.database.type === "sqlite"
116+
? "Docker Compose for Strapi with SQLite"
117+
: "Docker Compose with Strapi + Database";
118+
119+
files.push({
120+
path: "docker-compose.yml",
121+
content: compose,
122+
description,
123+
});
124+
}
125+
126+
// Prepare .env file for smart merging
127+
const envFile: EnvFileToWrite = {
128+
path: ".env",
129+
templateVars,
130+
description: "Environment variables (merged with existing)",
131+
};
132+
133+
// Write all files with smart env handling
134+
await writeFilesWithEnv(files, envFile, project.path);
135+
136+
// Show next steps
137+
console.log("\n🎯 Next steps:");
138+
console.log("1. Review the generated files");
139+
console.log("2. Run: docker-compose up -d");
140+
console.log("3. Your Strapi app will be available at http://localhost:1337");
141+
console.log(
142+
"\n⚠️ Keep your .env file secure - it contains sensitive secrets!"
143+
);
144+
}

0 commit comments

Comments
 (0)