diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ae9a61a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Use an official Node.js 20 runtime as a parent image +FROM node:20 + +# Create and set the working directory +RUN mkdir -p /home/node/rudder-github-app && chown -R node:node /home/node/rudder-github-app + +# Set the working directory in the container +WORKDIR /home/node/rudder-github-app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install dependencies using npm ci +RUN npm ci --no-audit --cache .npm + +# Copy the rest of the application code to the working directory +COPY . . + +# Change ownership of the copied files to the node user +RUN chown -R node:node /home/node/rudder-github-app + +# Switch to the node user +USER node + +# Expose the port the app runs on +EXPOSE 3000 + +# Start the app using npm start +CMD ["npm", "start"] \ No newline at end of file diff --git a/db.json b/db.json deleted file mode 100644 index fe51488..0000000 --- a/db.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ce8bcea --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3' +services: + app: + build: . + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - PORT=3000 + - APP_ID=123456 # Update with your GitHub app ID + - GITHUB_APP_PRIVATE_KEY_BASE64=LS0tHL.....o= # Update with your GitHub app private key (base64 encoded) + - WEBHOOK_SECRET=webhooksecret # Update with your GitHub webhook secretset in your GitHub app + - WEBSITE_ADDRESS=http://localhost:3000 # Update with your public website address + + # To enable live code changes during development, attach current directory as volume + # volumes: + # - .:/home/node/rudder-github-app \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 58f0e9c..843f91c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rudder_github_app", - "version": "0.0.1", + "version": "0.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rudder_github_app", - "version": "0.0.1", + "version": "0.0.2", "dependencies": { "dotenv": "^16.0.3", "octokit": "^3.1.2" @@ -15,6 +15,9 @@ "smee-client": "^2.0.1", "standard": "^17.0.0", "vite": "^4.5.3" + }, + "engines": { + "node": ">=20" } }, "node_modules/@esbuild/darwin-arm64": { diff --git a/src/storage.js b/src/storage.js index 24d459b..84f00b1 100644 --- a/src/storage.js +++ b/src/storage.js @@ -4,6 +4,26 @@ import { resolve } from "path"; import { PROJECT_ROOT_PATH } from "./helpers.js"; const dbPath = process.env.DB_PATH || resolve(PROJECT_ROOT_PATH, "db.json"); +createFileIfMissing(dbPath); + +function createFileIfMissing(path){ + try { + // Try to open the file in read-only mode + const fd = fs.openSync(path, 'r'); + fs.closeSync(fd); + console.log('DB file exists at '+dbPath); + } catch (err) { + if (err.code === 'ENOENT') { + // If the file does not exist, create it + fs.writeFileSync(path, '[]', { flag: 'wx' }); // 'wx' flag ensures the file is created and not overwritten if it exists + console.log('DB file created at '+dbPath); + } else { + // Some other error occurred + console.error(err); + throw new Error("Failed to create the DB file at "+dbPath); + } + } +} export const storage = { save(data) {