Skip to content
Snippets Groups Projects
Commit 993e47a6 authored by Quentin Bramas's avatar Quentin Bramas
Browse files

remove db from the container

parent 494286a2
Branches
No related merge requests found
FROM node:19
FROM node:19
RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
......@@ -11,8 +11,13 @@ WORKDIR /usr/src/app
COPY ./package.json /usr/src/app/
RUN pnpm install
COPY ./ /usr/src/app
COPY ./public /usr/src/app
COPY ./src /usr/src/app
COPY ./*.cjs /usr/src/app
COPY ./*.ts /usr/src/app
EXPOSE 80
VOLUME ["/data"]
CMD [ "pnpm", "dev", "--port", "80", "--host", "0.0.0.0"]
......@@ -3,15 +3,41 @@
import sqlite3 from 'sqlite3'
import { open } from 'sqlite'
import sqlite from 'sqlite'
import fs from 'fs'
let _db:sqlite.Database<sqlite3.Database, sqlite3.Statement> = null;
const dbPath = process.env.DATA_PATH || '/data/db.sqlite';
export async function init() {
// check if the db file exists
if(!fs.existsSync(dbPath)) {
console.log('Downloading the database file');
const file = fs.createWriteStream(dbPath);
await new Promise((resolve, reject) => {
const request = http.get('https://git.unistra.fr/bramas/s-rank/-/raw/master/db.sqlite', function(response) {
response.pipe(file);
// after download completed close filestream
file.on("finish", () => {
file.close();
console.log("Download Completed");
resolve();
});
file.on("error", (err) => {
console.log("Error while downloading the database file");
reject(err);
});
});
});
}
if (_db) return _db;
// sqlite3.Database, sqlite3.Statement is the default if no explicit generic is specified
_db = await open<sqlite3.Database, sqlite3.Statement>({
filename: './db.sqlite',
filename: dbPath,
driver: sqlite3.Database
})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment