Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | 5x | import { getCLIVersion } from '../utils/version.js';
// Get current CLI version automatically
const _cliVersion = getCLIVersion();
/**
* Generate Docker configuration for database
*/
export function generateDockerScaffolding(dbType, dockerConfig) {
const { port, name, user, password } = dockerConfig;
const dockerCompose = generateDockerCompose(dbType, port, name, user, password);
const dockerfile = generateDockerfile();
const dockerignore = generateDockerignore();
const envConfig = generateDockerEnvConfig(dbType, port, name, user, password);
return {
'docker-compose.yml': dockerCompose,
'Dockerfile': dockerfile,
'.dockerignore': dockerignore,
envConfig
};
}
/**
* Generate docker-compose.yml for database
*/
function generateDockerCompose(dbType, port, dbName, dbUser, dbPassword) {
const configs = {
postgres: `version: '3.8'
services:
postgres:
image: postgres:16-alpine
container_name: coherent-postgres
restart: unless-stopped
environment:
POSTGRES_DB: ${dbName}
POSTGRES_USER: ${dbUser}
POSTGRES_PASSWORD: ${dbPassword}
ports:
- "${port}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- coherent-network
volumes:
postgres_data:
networks:
coherent-network:
driver: bridge`,
mysql: `version: '3.8'
services:
mysql:
image: mysql:8
container_name: coherent-mysql
restart: unless-stopped
environment:
MYSQL_DATABASE: ${dbName}
MYSQL_USER: ${dbUser}
MYSQL_PASSWORD: ${dbPassword}
MYSQL_ROOT_PASSWORD: ${dbPassword}_root
ports:
- "${port}:3306"
volumes:
- mysql_data:/var/lib/mysql
networks:
- coherent-network
volumes:
mysql_data:
networks:
coherent-network:
driver: bridge`,
mongodb: `version: '3.8'
services:
mongodb:
image: mongo:7
container_name: coherent-mongodb
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: ${dbUser}
MONGO_INITDB_ROOT_PASSWORD: ${dbPassword}
MONGO_INITDB_DATABASE: ${dbName}
ports:
- "${port}:27017"
volumes:
- mongodb_data:/data/db
networks:
- coherent-network
volumes:
mongodb_data:
networks:
coherent-network:
driver: bridge`
};
return configs[dbType] || configs.postgres;
}
/**
* Generate Dockerfile for the application
*/
function generateDockerfile() {
return `# Use Node.js 18 Alpine as base image
FROM node:18-alpine
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Copy application code
COPY . .
# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001
# Change ownership of the app directory
RUN chown -R nodejs:nodejs /app
USER nodejs
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \\
CMD node healthcheck.js || exit 1
# Start the application
CMD ["npm", "start"]`;
}
/**
* Generate .dockerignore file
*/
function generateDockerignore() {
return `# Dependencies
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage
.grunt
# Bower dependency directory
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons
build/Release
# Dependency directories
jspm_packages/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env.local
.env.production
# parcel-bundler cache
.cache
.parcel-cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
public
# Storybook build outputs
.out
.storybook-out
# Temporary folders
tmp/
temp/
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage
.grunt
# Compiled binary addons
build/Release
# Users Environment Variables
.lock-wscript
# IDE files
.vscode/
.idea/
*.swp
*.swo
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db`;
}
/**
* Generate environment configuration for Docker
*/
function generateDockerEnvConfig(dbType, port, dbName, dbUser, dbPassword) {
const configs = {
postgres: {
DB_HOST: 'postgres',
DB_PORT: port,
DB_NAME: dbName,
DB_USER: dbUser,
DB_PASSWORD: dbPassword,
DATABASE_URL: `postgresql://${dbUser}:${dbPassword}@postgres:${port}/${dbName}`
},
mysql: {
DB_HOST: 'mysql',
DB_PORT: port,
DB_NAME: dbName,
DB_USER: dbUser,
DB_PASSWORD: dbPassword,
DATABASE_URL: `mysql://${dbUser}:${dbPassword}@mysql:${port}/${dbName}`
},
mongodb: {
DB_HOST: 'mongodb',
DB_PORT: port,
DB_NAME: dbName,
DB_USER: dbUser,
DB_PASSWORD: dbPassword,
DATABASE_URL: `mongodb://${dbUser}:${dbPassword}@mongodb:${port}/${dbName}`
}
};
return configs[dbType] || configs.postgres;
}
/**
* Generate health check script
*/
export function generateHealthCheck() {
return `import http from 'http';
const options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/health',
timeout: 2000
};
const request = http.request(options, (res) => {
console.log(\`Health check status: \${res.statusCode}\`);
if (res.statusCode === 200) {
process.exit(0);
} else {
process.exit(1);
}
});
request.on('error', (err) => {
console.log('Health check failed:', err.message);
process.exit(1);
});
request.end();`;
}
|