working rough draft
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -5,7 +5,12 @@ node_modules/
|
||||
build_cache/
|
||||
traefik/logs/*.log
|
||||
control-plane/tmp/
|
||||
control-plane/node_modules/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
postgres_data/
|
||||
|
||||
# Cloned repos and build artifacts
|
||||
/tmp/builds/
|
||||
tmp/builds/
|
||||
|
||||
5
control-plane/.dockerignore
Normal file
5
control-plane/.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.env
|
||||
.git
|
||||
.gitignore
|
||||
@@ -6,13 +6,16 @@ WORKDIR /app
|
||||
RUN apk add --no-cache git
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
COPY control-plane/package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci --only=production
|
||||
|
||||
# Copy application files
|
||||
COPY . .
|
||||
COPY control-plane/ .
|
||||
|
||||
# Copy dashboard files to public directory
|
||||
COPY dashboard/ ./public
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
|
||||
2697
control-plane/package-lock.json
generated
Normal file
2697
control-plane/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,9 @@
|
||||
"helmet": "^7.1.0",
|
||||
"compression": "^1.7.4",
|
||||
"dotenv": "^16.4.1",
|
||||
"crypto": "^1.0.1"
|
||||
"crypto": "^1.0.1",
|
||||
"fs-extra": "^11.2.0",
|
||||
"tail": "^2.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.0.3"
|
||||
|
||||
@@ -24,7 +24,7 @@ async function startContainer(deploymentId, projectId, imageName, subdomain, env
|
||||
'minipaas.deployment.id': deploymentId.toString()
|
||||
},
|
||||
HostConfig: {
|
||||
NetworkMode: 'minipaas_paas_network',
|
||||
NetworkMode: '1minipaas_paas_network',
|
||||
RestartPolicy: {
|
||||
Name: 'unless-stopped'
|
||||
}
|
||||
|
||||
@@ -27,26 +27,73 @@ function generateDockerfile(repoPath, projectType) {
|
||||
case 'nodejs':
|
||||
const packageJson = JSON.parse(fs.readFileSync(path.join(repoPath, 'package.json'), 'utf8'));
|
||||
const hasYarnLock = fs.existsSync(path.join(repoPath, 'yarn.lock'));
|
||||
const hasBuildScript = packageJson.scripts?.build;
|
||||
|
||||
dockerfile = `FROM node:20-alpine
|
||||
// Check if it's a Vite/static build app
|
||||
const allDeps = {
|
||||
...packageJson.dependencies,
|
||||
...packageJson.devDependencies
|
||||
};
|
||||
const isViteApp = allDeps?.vite || allDeps?.['@vitejs/plugin-react'] || allDeps?.['@vitejs/plugin-vue'];
|
||||
const isStaticBuildApp = isViteApp || allDeps?.['create-react-app'] || allDeps?.['next'];
|
||||
|
||||
if (isViteApp && hasBuildScript) {
|
||||
// Vite app - build and serve static files
|
||||
dockerfile = `FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
${hasYarnLock ? 'COPY yarn.lock ./\n' : ''}
|
||||
|
||||
RUN ${hasYarnLock ? 'yarn install --frozen-lockfile' : 'npm ci --only=production'}
|
||||
RUN ${hasYarnLock ? 'yarn install --frozen-lockfile' : 'npm ci'}
|
||||
|
||||
COPY . .
|
||||
|
||||
${packageJson.scripts?.build ? 'RUN ' + (hasYarnLock ? 'yarn build' : 'npm run build') + '\n' : ''}
|
||||
RUN ${hasYarnLock ? 'yarn build' : 'npm run build'}
|
||||
|
||||
# Install serve to host the static files
|
||||
RUN npm install -g serve
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
# Serve the dist folder (common for Vite)
|
||||
CMD ["serve", "-s", "dist", "-l", "3000"]
|
||||
`;
|
||||
} else {
|
||||
// Regular Node.js app
|
||||
dockerfile = `FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
${hasYarnLock ? 'COPY yarn.lock ./\n' : ''}
|
||||
|
||||
RUN ${hasYarnLock ? 'yarn install --frozen-lockfile' : (hasBuildScript ? 'npm ci' : 'npm ci --only=production')}
|
||||
|
||||
COPY . .
|
||||
|
||||
${hasBuildScript ? 'RUN ' + (hasYarnLock ? 'yarn build' : 'npm run build') + '\n' : ''}
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["${hasYarnLock ? 'yarn' : 'npm'}", "start"]
|
||||
`;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'python':
|
||||
// Check if Flask/FastAPI exists in requirements
|
||||
let cmd = '["python", "app.py"]';
|
||||
const requirementsPath = path.join(repoPath, 'requirements.txt');
|
||||
if (fs.existsSync(requirementsPath)) {
|
||||
const requirements = fs.readFileSync(requirementsPath, 'utf8').toLowerCase();
|
||||
if (requirements.includes('flask')) {
|
||||
cmd = '["python", "-m", "flask", "run", "--host=0.0.0.0"]';
|
||||
} else if (requirements.includes('fastapi') || requirements.includes('uvicorn')) {
|
||||
cmd = '["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]';
|
||||
}
|
||||
}
|
||||
|
||||
dockerfile = `FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
@@ -57,8 +104,10 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY . .
|
||||
|
||||
EXPOSE 8000
|
||||
ENV FLASK_APP=app.py
|
||||
ENV FLASK_RUN_HOST=0.0.0.0
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
CMD ${cmd}
|
||||
`;
|
||||
break;
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ CREATE TABLE IF NOT EXISTS deployments (
|
||||
docker_container_id VARCHAR(255),
|
||||
started_at TIMESTAMP,
|
||||
completed_at TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_deployments_project ON deployments(project_id);
|
||||
|
||||
@@ -44,7 +44,9 @@ services:
|
||||
retries: 5
|
||||
|
||||
control-plane:
|
||||
build: ./control-plane
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./control-plane/Dockerfile
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
@@ -57,10 +59,7 @@ services:
|
||||
NODE_ENV: development
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- ./control-plane:/app
|
||||
- /app/node_modules
|
||||
- build_cache:/tmp/builds
|
||||
- ./dashboard:/app/public
|
||||
networks:
|
||||
- paas_network
|
||||
labels:
|
||||
|
||||
Reference in New Issue
Block a user