Starting v0.04
First build of Docker image. Barely works, very buggy.
This commit is contained in:
parent
d7f75bf63b
commit
9f3cb150a7
9 changed files with 2804 additions and 15 deletions
36
Dockerfile
Normal file
36
Dockerfile
Normal file
|
@ -0,0 +1,36 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Comments are provided throughout this file to help you get started.
|
||||
# If you need more help, visit the Dockerfile reference guide at
|
||||
# https://docs.docker.com/engine/reference/builder/
|
||||
|
||||
ARG NODE_VERSION=20.0.0
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine
|
||||
|
||||
# Use production node environment by default.
|
||||
ENV NODE_ENV production
|
||||
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Download dependencies as a separate step to take advantage of Docker's caching.
|
||||
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
|
||||
# Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into
|
||||
# into this layer.
|
||||
RUN --mount=type=bind,source=package.json,target=package.json \
|
||||
--mount=type=bind,source=package-lock.json,target=package-lock.json \
|
||||
--mount=type=cache,target=/root/.npm \
|
||||
npm ci --omit=dev
|
||||
|
||||
# Run the application as a non-root user.
|
||||
USER root
|
||||
|
||||
# Copy the rest of the source files into the image.
|
||||
COPY . .
|
||||
|
||||
# Expose the port that the application listens on.
|
||||
EXPOSE 8000
|
||||
|
||||
# Run the application.
|
||||
CMD node app.js
|
5
app.js
5
app.js
|
@ -9,9 +9,8 @@ const { serverStats, containerList, containerStats, containerAction } = require(
|
|||
let sent_list, clicked;
|
||||
|
||||
const redisClient = require('redis').createClient({
|
||||
host:'localhost',
|
||||
port:6379,
|
||||
password:'somesupersecretpassword',
|
||||
url: 'redis://DweebCache:6379',
|
||||
password:'eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81',
|
||||
legacyMode:true
|
||||
});
|
||||
redisClient.connect().catch(console.log);
|
||||
|
|
25
compose.yaml
Normal file
25
compose.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
services:
|
||||
server:
|
||||
container_name: DweebUI
|
||||
build:
|
||||
context: .
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
ports:
|
||||
- 8000:8000
|
||||
depends_on:
|
||||
- cache
|
||||
links:
|
||||
- cache
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
cache:
|
||||
container_name: DweebCache
|
||||
image: redis:6.2-alpine
|
||||
restart: always
|
||||
command: redis-server --save 20 1 --loglevel warning --requirepass eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81
|
||||
volumes:
|
||||
- cache:/data
|
||||
|
||||
volumes:
|
||||
cache:
|
|
@ -2,7 +2,7 @@ const { Sequelize, DataTypes } = require('sequelize');
|
|||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'database/db.sqlite',
|
||||
storage: './database/db.sqlite',
|
||||
logging: false
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ const { Sequelize, DataTypes } = require('sequelize');
|
|||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'database/db.sqlite',
|
||||
storage: './database/db.sqlite',
|
||||
logging: false
|
||||
});
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const { writeFileSync, mkdirSync, readFileSync } = require("fs");
|
||||
const { exec, execSync } = require("child_process");
|
||||
const { dashCard } = require('../components/dashCard');
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
const { exec, execSync } = require("child_process");
|
||||
|
||||
const { docker } = require('./system_information');
|
||||
var DockerodeCompose = require('dockerode-compose');
|
||||
|
||||
|
||||
module.exports.install = async function (data) {
|
||||
|
@ -124,13 +126,25 @@ module.exports.install = async function (data) {
|
|||
mkdirSync(`./appdata/${name}`, { recursive: true });
|
||||
writeFileSync(`./appdata/${name}/docker-compose.yml`, compose_file, function (err) { console.log(err) });
|
||||
|
||||
exec(`docker compose -f ./appdata/${name}/docker-compose.yml up -d`, (error, stdout, stderr) => {
|
||||
if (error) { console.error(`error: ${error.message}`); return; }
|
||||
if (stderr) { console.error(`stderr: ${stderr}`); return; }
|
||||
console.log(`stdout:\n${stdout}`);
|
||||
});
|
||||
// exec(`docker compose -f ./appdata/${name}/docker-compose.yml up -d`, (error, stdout, stderr) => {
|
||||
// if (error) { console.error(`error: ${error.message}`); return; }
|
||||
// if (stderr) { console.error(`stderr: ${stderr}`); return; }
|
||||
// console.log(`stdout:\n${stdout}`);
|
||||
// });
|
||||
|
||||
} catch { console.log('error creating directory or compose file') }
|
||||
|
||||
try {
|
||||
var compose = new DockerodeCompose(docker, `./appdata/${name}/docker-compose.yml`, `${name}`);
|
||||
|
||||
(async () => {
|
||||
await compose.pull();
|
||||
var state = await compose.up();
|
||||
console.log(state);
|
||||
})();
|
||||
|
||||
} catch { console.log('error running compose file')}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ var Docker = require('dockerode');
|
|||
var docker = new Docker({ socketPath: '/var/run/docker.sock' });
|
||||
const { dashCard } = require('../components/dashCard');
|
||||
|
||||
|
||||
// export docker
|
||||
module.exports.docker = docker;
|
||||
|
||||
module.exports.serverStats = async function () {
|
||||
const cpuUsage = await currentLoad();
|
||||
|
|
2713
package-lock.json
generated
Normal file
2713
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -10,15 +10,16 @@
|
|||
"child_process": "^1.0.2",
|
||||
"connect-redis": "^6.1.3",
|
||||
"dockerode": "^3.3.5",
|
||||
"dockerode-compose": "^1.4.0",
|
||||
"ejs": "^3.1.9",
|
||||
"express": "^4.18.2",
|
||||
"express-session": "^1.17.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"redis": "^4.6.5",
|
||||
"sequelize": "^6.32.1",
|
||||
"socket.io": "^4.6.1",
|
||||
"sqlite3": "^5.1.6",
|
||||
"systeminformation": "^5.17.12",
|
||||
"js-yaml": "^4.1.0"
|
||||
"systeminformation": "^5.17.12"
|
||||
},
|
||||
"description": ""
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue