Skip to content

Commit

Permalink
Change Docker base image (#16)
Browse files Browse the repository at this point in the history
* Add version string printing for deployed server

* Change base image to `node:20-bookworm-slim`
  • Loading branch information
mewim authored Oct 13, 2023
1 parent 7d22ae4 commit 2559ac2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
28 changes: 9 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:bookworm-slim
FROM node:20-bookworm-slim

ARG SKIP_GRAMMAR=false
ARG SKIP_BUILD_APP=false
Expand All @@ -8,33 +8,23 @@ RUN echo "SKIP_GRAMMAR: $SKIP_GRAMMAR"
RUN echo "SKIP_BUILD_APP: $SKIP_BUILD_APP"

# Install dependencies
RUN apt-get update
RUN apt-get install -y ca-certificates curl gnupg
RUN if [ "$SKIP_GRAMMAR" != "true" ] ; then apt-get install -y openjdk-17-jdk ; else echo "Skipping openjdk installation as grammar generation is skipped" ; fi
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install -y nodejs

# Create app user
RUN useradd --create-home appuser
RUN if [ "$SKIP_GRAMMAR" != "true" ] ; then apt update && apt-get install -y openjdk-17-jdk ; else echo "Skipping openjdk installation as grammar generation is skipped" ; fi

# Copy app
COPY . /home/appuser/app
RUN chown -R appuser:appuser /home/appuser/app
COPY . /home/node/app
RUN chown -R node:node /home/node/app

# Make data and database directories
RUN mkdir -p /database
RUN mkdir -p /data
RUN chown -R appuser:appuser /database
RUN chown -R appuser:appuser /data
RUN chown -R node:node /database
RUN chown -R node:node /data

# Switch to app user
USER appuser
# Switch to node user
USER node

# Set working directory
WORKDIR /home/appuser/app
WORKDIR /home/node/app

# Install dependencies
RUN npm install
Expand Down
24 changes: 21 additions & 3 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express");
const api = require("./API");
const path = require("path");
const process = require("process");
const database = require("./utils/database");

process.on("SIGINT", () => {
console.log("SIGINT received, exiting");
Expand All @@ -20,6 +21,23 @@ app.use("/api", api);
const distPath = path.join(__dirname, "..", "..", "dist");
app.use("/", express.static(distPath));

app.listen(PORT, () => {
console.log("Deployed server started on port:", PORT);
});
const conn = database.getConnection();
conn
.query("CALL db_version() RETURN *;")
.then((res) => {
return res.getAll();
})
.then((res) => {
const row = res[0];
const version = Object.values(row)[0];
console.log("Version of Kùzu:", version);
app.listen(PORT, () => {
console.log("Deployed server started on port:", PORT);
});
})
.catch((err) => {
console.log("Error getting version of Kùzu:", err);
})
.finally(() => {
database.releaseConnection(conn);
});

0 comments on commit 2559ac2

Please sign in to comment.