feat: Contanerization via Docker & Docker Compose

This commit is contained in:
April Hall 2025-02-23 21:42:17 -05:00
parent f4fda50135
commit bb2a0787b1
Signed by: arithefirst
GPG Key ID: 4508A15C4DB91C5B
9 changed files with 145 additions and 8 deletions

42
.dockerignore Normal file
View File

@ -0,0 +1,42 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
**/src/lib/server/db/users.db*
**/minio-storage
**/vite.config.js.timestamp-*
**/vite.config.ts.timestamp-*
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build
/drizzle
.DS_Store
Thumbs.db
LICENSE
README.md

4
.gitignore vendored
View File

@ -28,7 +28,7 @@ vite.config.js.timestamp-*
vite.config.ts.timestamp-*
# Sqlite
src/lib/server/db/users.db*
**/src/lib/server/db/users.db*
# Storage
minio-storage
**/minio-storage

42
Dockerfile Normal file
View File

@ -0,0 +1,42 @@
ARG NODE_VERSION=23.8.0
FROM node:${NODE_VERSION} AS base
WORKDIR /app
###############
# Dep Stage #
###############
FROM base AS deps
COPY package.json .
RUN npm install --omit-dev
###############
# Build Stage #
###############
FROM deps AS build
COPY . .
# Run DB migrations for SQLite
RUN npm run migrate
RUN npm install
RUN npm run build
###############
# Application #
###############
FROM base AS final
COPY package.json .
# Stuff needed by the app
COPY --from=build /app/build build/
COPY --from=build /app/prodServer.ts .
COPY --from=build /app/package.json .
COPY --from=build /app/src/lib/server/db src/lib/server/db
COPY --from=deps /app/node_modules node_modules/
ENV NODE_ENV=production
EXPOSE 3000
CMD ["npm", "run", "production"]

View File

@ -5,7 +5,7 @@ A more complex version of this list is available [here](https://trello.com/b/kJw
- [x] Account / Profile management
- [ ] Channel context menus
- [ ] Containerization with docker and docker-compose
- [X] Containerization with docker and docker-compose
- [ ] Documentation
- [ ] Emoji picker
- [ ] Images/Attatchments support

49
compose.yaml Normal file
View File

@ -0,0 +1,49 @@
services:
chat-server:
container_name: svchat-server
build:
context: .
environment:
NODE_ENV: docker_production
ORIGIN: http://localhost:3000
ports:
- 3000:3000
depends_on:
- cassandra
volumes:
- svchat-users:/app/src/lib/server/db
cassandra:
container_name: svchat-db
image: cassandra
restart: always
ports:
- 9042:9042
environment:
# TODO Change default passwords
- CASSANDRA_USER=admin
- CASSANDRA_PASSWORD=admin
volumes:
- svchat-cassandra:/var/lib/cassandra
minio:
container_name: svchat-s3
image: docker.io/bitnami/minio
restart: always
ports:
- 9000:9000
- 9001:9001
environment:
# TODO Change default passwords
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
volumes:
- svchat-s3:/data
volumes:
svchat-cassandra:
driver: local
svchat-s3:
driver: local
svchat-users:
driver: local

View File

@ -11,7 +11,7 @@
"dev": "vite dev",
"format": "prettier --write .",
"lint": "eslint .",
"migrate": "npx @better-auth/cli migrate --config './src/lib/server/db/auth'",
"migrate": "npx @better-auth/cli migrate --config './src/lib/server/db/auth' -y",
"minio": "minio server minio-storage",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",

View File

@ -9,6 +9,7 @@ import { v4 as uuidv4 } from 'uuid';
const app = express();
const server = createServer(app);
const io = new Server(server);
const port = 3000;
io.on('connection', async (socket) => {
// Runs on client connection
@ -44,6 +45,6 @@ app.use((req, res, next) => {
}
});
server.listen(3005, () => {
console.log('Listening on http://0.0.0.0:3005');
server.listen(port, () => {
console.log(`Listening on http://localhost:${port}`);
});

View File

@ -18,9 +18,11 @@ function sanitizeChannelName(channelName: string) {
}
class Db {
private clientUrl: string = process.env.NODE_ENV === 'docker_production' ? 'cassandra' : 'localhost';
private client: cassandra.Client = new cassandra.Client({
contactPoints: ['localhost'],
contactPoints: [this.clientUrl],
localDataCenter: 'datacenter1',
authProvider: new cassandra.auth.PlainTextAuthProvider('admin', 'admin'),
});
// Initalize and connect

View File

@ -71,7 +71,8 @@ let fsClient: MinioClient | undefined;
if (process.env.BUILDING !== 'true') {
fsClient = new MinioClient({
endPoint: 'localhost',
// Endpoint is 'minio' in compose, 'localhost' everywhere else
endPoint: process.env.NODE_ENV === 'docker_production' ? 'minio' : 'localhost',
port: 9000,
accessKey: 'minioadmin',
secretKey: 'minioadmin',