@panoptic-it-solutions/coolify-setup 1.1.2 → 1.1.4
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.
- package/dist/generator.js +11 -17
- package/dist/git.d.ts +7 -0
- package/dist/git.js +116 -27
- package/dist/index.js +61 -12
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -25,28 +25,22 @@ function addEsbuildToPackageJson(packageManager) {
|
|
|
25
25
|
if (!packageJson.devDependencies) {
|
|
26
26
|
packageJson.devDependencies = {};
|
|
27
27
|
}
|
|
28
|
+
let addedEsbuild = false;
|
|
28
29
|
// Add esbuild if not already present
|
|
29
30
|
if (!packageJson.devDependencies.esbuild) {
|
|
30
31
|
packageJson.devDependencies.esbuild = '^0.25.0';
|
|
31
32
|
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8');
|
|
32
|
-
|
|
33
|
-
const installCmd = packageManager === 'pnpm'
|
|
34
|
-
? 'pnpm install'
|
|
35
|
-
: packageManager === 'yarn'
|
|
36
|
-
? 'yarn install'
|
|
37
|
-
: 'npm install';
|
|
38
|
-
console.log(`Running ${installCmd} to update lockfile...`);
|
|
39
|
-
execSync(installCmd, { stdio: 'inherit', cwd: process.cwd() });
|
|
40
|
-
// Remind user to commit the lockfile
|
|
41
|
-
const lockfileName = packageManager === 'pnpm'
|
|
42
|
-
? 'pnpm-lock.yaml'
|
|
43
|
-
: packageManager === 'yarn'
|
|
44
|
-
? 'yarn.lock'
|
|
45
|
-
: 'package-lock.json';
|
|
46
|
-
console.log(`\n⚠️ IMPORTANT: Commit ${lockfileName} before pushing to avoid CI build failures!\n`);
|
|
47
|
-
return true;
|
|
33
|
+
addedEsbuild = true;
|
|
48
34
|
}
|
|
49
|
-
|
|
35
|
+
// Always run install to ensure lockfile is in sync
|
|
36
|
+
const installCmd = packageManager === 'pnpm'
|
|
37
|
+
? 'pnpm install'
|
|
38
|
+
: packageManager === 'yarn'
|
|
39
|
+
? 'yarn install'
|
|
40
|
+
: 'npm install';
|
|
41
|
+
console.log(`Running ${installCmd} to ensure lockfile is in sync...`);
|
|
42
|
+
execSync(installCmd, { stdio: 'inherit', cwd: process.cwd() });
|
|
43
|
+
return addedEsbuild;
|
|
50
44
|
}
|
|
51
45
|
catch (error) {
|
|
52
46
|
console.log('Warning: Failed to update package.json:', error);
|
package/dist/git.d.ts
CHANGED
|
@@ -8,4 +8,11 @@ export interface GitHubSetupResult {
|
|
|
8
8
|
existingRemote: string | null;
|
|
9
9
|
warnings: string[];
|
|
10
10
|
}
|
|
11
|
+
export interface CommitAndPushResult {
|
|
12
|
+
committed: boolean;
|
|
13
|
+
pushed: boolean;
|
|
14
|
+
branchName: string;
|
|
15
|
+
warnings: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare function commitAndPushToDevelop(files: string[]): Promise<CommitAndPushResult>;
|
|
11
18
|
export declare function setupGitHub(projectName: string): Promise<GitHubSetupResult>;
|
package/dist/git.js
CHANGED
|
@@ -33,6 +33,81 @@ function isCorrectRemote(remoteUrl, projectName) {
|
|
|
33
33
|
];
|
|
34
34
|
return expectedPatterns.some(pattern => remoteUrl.includes(pattern));
|
|
35
35
|
}
|
|
36
|
+
export async function commitAndPushToDevelop(files) {
|
|
37
|
+
const result = {
|
|
38
|
+
committed: false,
|
|
39
|
+
pushed: false,
|
|
40
|
+
branchName: 'develop',
|
|
41
|
+
warnings: [],
|
|
42
|
+
};
|
|
43
|
+
// Initialize git if not already a repo
|
|
44
|
+
if (!isGitRepo()) {
|
|
45
|
+
run('git init');
|
|
46
|
+
}
|
|
47
|
+
// Stage all specified files
|
|
48
|
+
for (const file of files) {
|
|
49
|
+
try {
|
|
50
|
+
run(`git add "${file}"`);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// File might not exist, that's ok
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Check if there are staged changes
|
|
57
|
+
try {
|
|
58
|
+
const status = run('git diff --cached --name-only');
|
|
59
|
+
if (!status) {
|
|
60
|
+
result.warnings.push('No changes to commit');
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
result.warnings.push('Failed to check git status');
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
// Commit the changes
|
|
69
|
+
try {
|
|
70
|
+
run('git commit -m "chore: add Coolify deployment configuration"');
|
|
71
|
+
result.committed = true;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
result.warnings.push(`Failed to commit: ${error}`);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
// Check if remote exists
|
|
78
|
+
const remoteUrl = getGitRemoteUrl();
|
|
79
|
+
if (!remoteUrl) {
|
|
80
|
+
result.warnings.push('No remote configured - files committed locally but not pushed');
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
// Ensure develop branch exists and push to it
|
|
84
|
+
try {
|
|
85
|
+
const currentBranch = run('git branch --show-current');
|
|
86
|
+
if (currentBranch === 'develop') {
|
|
87
|
+
// Already on develop, just push
|
|
88
|
+
run('git push origin develop');
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Check if develop exists remotely
|
|
92
|
+
try {
|
|
93
|
+
run('git fetch origin develop');
|
|
94
|
+
// Develop exists, checkout and merge/rebase current changes
|
|
95
|
+
run('git checkout develop');
|
|
96
|
+
run(`git merge ${currentBranch} --no-edit`);
|
|
97
|
+
run('git push origin develop');
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Develop doesn't exist remotely, create it from current branch
|
|
101
|
+
run('git push origin HEAD:develop');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
result.pushed = true;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
result.warnings.push(`Failed to push to develop: ${error}`);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
36
111
|
export async function setupGitHub(projectName) {
|
|
37
112
|
const result = {
|
|
38
113
|
repoCreated: false,
|
|
@@ -75,17 +150,9 @@ export async function setupGitHub(projectName) {
|
|
|
75
150
|
// Don't proceed with operations that would push to the wrong repo
|
|
76
151
|
return result;
|
|
77
152
|
}
|
|
78
|
-
// Remote exists and is correct, just push
|
|
79
|
-
try {
|
|
80
|
-
run('git push origin HEAD');
|
|
81
|
-
result.repoPushed = true;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
result.warnings.push(`Failed to push to existing remote: ${error}`);
|
|
85
|
-
}
|
|
86
153
|
}
|
|
87
154
|
else {
|
|
88
|
-
// Create the repository
|
|
155
|
+
// Create the repository (pushes current branch)
|
|
89
156
|
try {
|
|
90
157
|
await runAsync(`gh repo create ${ORG}/${projectName} --private --source=. --push`);
|
|
91
158
|
result.repoCreated = true;
|
|
@@ -95,35 +162,57 @@ export async function setupGitHub(projectName) {
|
|
|
95
162
|
throw new Error(`Failed to create repository: ${error}`);
|
|
96
163
|
}
|
|
97
164
|
}
|
|
98
|
-
// Ensure we're on
|
|
99
|
-
const currentBranch = run('git branch --show-current');
|
|
100
|
-
if (currentBranch !== 'main') {
|
|
101
|
-
run('git checkout -b main 2>/dev/null || git checkout main');
|
|
102
|
-
}
|
|
103
|
-
// Push main
|
|
165
|
+
// Ensure we're on develop branch and push to it
|
|
104
166
|
try {
|
|
105
|
-
run('git
|
|
106
|
-
|
|
167
|
+
const currentBranch = run('git branch --show-current');
|
|
168
|
+
if (currentBranch !== 'develop') {
|
|
169
|
+
// Check if develop exists locally
|
|
170
|
+
try {
|
|
171
|
+
run('git checkout develop');
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// Create develop from current branch
|
|
175
|
+
run('git checkout -b develop');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
run('git push origin develop -u');
|
|
179
|
+
result.developBranchCreated = true;
|
|
180
|
+
result.repoPushed = true;
|
|
107
181
|
}
|
|
108
182
|
catch {
|
|
109
|
-
result.warnings.push('Failed to push
|
|
183
|
+
result.warnings.push('Failed to push develop branch');
|
|
110
184
|
}
|
|
111
|
-
// Create
|
|
185
|
+
// Create main branch from develop if it doesn't exist
|
|
112
186
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
187
|
+
// Check if main exists remotely
|
|
188
|
+
run('git ls-remote --exit-code --heads origin main');
|
|
189
|
+
result.mainBranchPushed = true; // Already exists
|
|
115
190
|
}
|
|
116
191
|
catch {
|
|
117
|
-
|
|
192
|
+
// Main doesn't exist, create it from develop
|
|
193
|
+
try {
|
|
194
|
+
run('git push origin develop:main');
|
|
195
|
+
result.mainBranchPushed = true;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
result.warnings.push('Failed to create main branch');
|
|
199
|
+
}
|
|
118
200
|
}
|
|
119
|
-
// Create
|
|
201
|
+
// Create staging branch from develop if it doesn't exist
|
|
120
202
|
try {
|
|
121
|
-
|
|
122
|
-
run('git
|
|
123
|
-
result.
|
|
203
|
+
// Check if staging exists remotely
|
|
204
|
+
run('git ls-remote --exit-code --heads origin staging');
|
|
205
|
+
result.stagingBranchCreated = true; // Already exists
|
|
124
206
|
}
|
|
125
207
|
catch {
|
|
126
|
-
|
|
208
|
+
// Staging doesn't exist, create it from develop
|
|
209
|
+
try {
|
|
210
|
+
run('git push origin develop:staging');
|
|
211
|
+
result.stagingBranchCreated = true;
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
result.warnings.push('Failed to create staging branch');
|
|
215
|
+
}
|
|
127
216
|
}
|
|
128
217
|
// Set develop as default branch
|
|
129
218
|
try {
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import ora from 'ora';
|
|
|
4
4
|
import prompts from 'prompts';
|
|
5
5
|
import { detectProject } from './detector.js';
|
|
6
6
|
import { generateFiles } from './generator.js';
|
|
7
|
-
import { setupGitHub } from './git.js';
|
|
7
|
+
import { setupGitHub, commitAndPushToDevelop } from './git.js';
|
|
8
8
|
async function main() {
|
|
9
9
|
console.log(chalk.bold.cyan('\n🚀 Panoptic Coolify Setup\n'));
|
|
10
10
|
// Detect project type
|
|
@@ -65,6 +65,36 @@ async function main() {
|
|
|
65
65
|
includeRedis: response.includeRedis,
|
|
66
66
|
includeMinio: response.includeMinio,
|
|
67
67
|
});
|
|
68
|
+
// Track generated files for commit
|
|
69
|
+
const generatedFiles = [
|
|
70
|
+
'Dockerfile',
|
|
71
|
+
'docker-compose.yml',
|
|
72
|
+
'docker-compose.build.yml',
|
|
73
|
+
'.github/workflows/build-deploy.yml',
|
|
74
|
+
'.claude/rules/coolify.md',
|
|
75
|
+
'entrypoint.sh',
|
|
76
|
+
'package.json', // May be modified with esbuild
|
|
77
|
+
];
|
|
78
|
+
// Add lockfile based on package manager
|
|
79
|
+
if (project.packageManager === 'pnpm') {
|
|
80
|
+
generatedFiles.push('pnpm-lock.yaml');
|
|
81
|
+
}
|
|
82
|
+
else if (project.packageManager === 'yarn') {
|
|
83
|
+
generatedFiles.push('yarn.lock');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
generatedFiles.push('package-lock.json');
|
|
87
|
+
}
|
|
88
|
+
// Add migrate script if postgres included
|
|
89
|
+
if (response.includePostgres) {
|
|
90
|
+
if (project.type === 'nextjs') {
|
|
91
|
+
generatedFiles.push('lib/db/migrate.ts');
|
|
92
|
+
generatedFiles.push('tsconfig.json'); // May be modified with exclude
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
generatedFiles.push('scripts/migrate.ts');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
68
98
|
console.log(chalk.green(' ✓ Dockerfile'));
|
|
69
99
|
console.log(chalk.green(' ✓ docker-compose.yml'));
|
|
70
100
|
console.log(chalk.green(' ✓ docker-compose.build.yml'));
|
|
@@ -72,9 +102,14 @@ async function main() {
|
|
|
72
102
|
console.log(chalk.green(' ✓ .claude/rules/coolify.md'));
|
|
73
103
|
console.log(chalk.green(' ✓ entrypoint.sh'));
|
|
74
104
|
if (response.includePostgres) {
|
|
75
|
-
|
|
105
|
+
if (project.type === 'nextjs') {
|
|
106
|
+
console.log(chalk.green(' ✓ lib/db/migrate.ts'));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.log(chalk.green(' ✓ scripts/migrate.ts'));
|
|
110
|
+
}
|
|
76
111
|
}
|
|
77
|
-
// Setup GitHub
|
|
112
|
+
// Setup GitHub first (creates repo/remote if needed)
|
|
78
113
|
if (response.createRepo) {
|
|
79
114
|
console.log(chalk.bold('\nSetting up GitHub...'));
|
|
80
115
|
try {
|
|
@@ -86,17 +121,14 @@ async function main() {
|
|
|
86
121
|
else if (result.existingRemote) {
|
|
87
122
|
console.log(chalk.yellow(` ⚠ Using existing remote: ${result.existingRemote}`));
|
|
88
123
|
}
|
|
89
|
-
if (result.
|
|
90
|
-
console.log(chalk.green(' ✓ Pushed to
|
|
124
|
+
if (result.developBranchCreated) {
|
|
125
|
+
console.log(chalk.green(' ✓ Pushed to develop branch'));
|
|
91
126
|
}
|
|
92
127
|
if (result.mainBranchPushed) {
|
|
93
|
-
console.log(chalk.green(' ✓
|
|
128
|
+
console.log(chalk.green(' ✓ Created/verified main branch'));
|
|
94
129
|
}
|
|
95
130
|
if (result.stagingBranchCreated) {
|
|
96
|
-
console.log(chalk.green(' ✓ Created staging branch'));
|
|
97
|
-
}
|
|
98
|
-
if (result.developBranchCreated) {
|
|
99
|
-
console.log(chalk.green(' ✓ Created develop branch'));
|
|
131
|
+
console.log(chalk.green(' ✓ Created/verified staging branch'));
|
|
100
132
|
}
|
|
101
133
|
if (result.defaultBranchSet) {
|
|
102
134
|
console.log(chalk.green(' ✓ Set develop as default branch'));
|
|
@@ -116,12 +148,29 @@ async function main() {
|
|
|
116
148
|
console.log(chalk.yellow(' You can manually run: gh repo create Panoptic-IT-Solutions/' + response.projectName));
|
|
117
149
|
}
|
|
118
150
|
}
|
|
151
|
+
// Commit and push generated files to develop
|
|
152
|
+
console.log(chalk.bold('\nCommitting and pushing to develop...'));
|
|
153
|
+
try {
|
|
154
|
+
const commitResult = await commitAndPushToDevelop(generatedFiles);
|
|
155
|
+
if (commitResult.committed) {
|
|
156
|
+
console.log(chalk.green(' ✓ Committed changes'));
|
|
157
|
+
}
|
|
158
|
+
if (commitResult.pushed) {
|
|
159
|
+
console.log(chalk.green(' ✓ Pushed to develop branch'));
|
|
160
|
+
}
|
|
161
|
+
for (const warning of commitResult.warnings) {
|
|
162
|
+
console.log(chalk.yellow(` ⚠ ${warning}`));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
console.log(chalk.yellow(` ⚠ Failed to commit/push: ${error}`));
|
|
167
|
+
console.log(chalk.yellow(' You may need to manually commit and push the generated files'));
|
|
168
|
+
}
|
|
119
169
|
console.log(chalk.bold.green('\n✅ Setup complete!\n'));
|
|
120
170
|
console.log('Next steps:');
|
|
121
171
|
console.log(chalk.cyan(' 1. Review the generated files'));
|
|
122
172
|
console.log(chalk.cyan(' 2. Update .env with your secrets'));
|
|
123
|
-
console.log(chalk.cyan(' 3.
|
|
124
|
-
console.log(chalk.cyan(' 4. Configure Coolify to deploy from staging branch\n'));
|
|
173
|
+
console.log(chalk.cyan(' 3. Configure Coolify to deploy from staging branch\n'));
|
|
125
174
|
}
|
|
126
175
|
main().catch((error) => {
|
|
127
176
|
console.error(chalk.red('Error:'), error);
|