Skip to content

Commit 98fcefe

Browse files
feat: deploy using docker (#28)
1 parent ae6062c commit 98fcefe

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use an official Node.js 20 runtime as a parent image
2+
FROM node:20
3+
4+
# Create and set the working directory
5+
RUN mkdir -p /home/node/rudder-github-app && chown -R node:node /home/node/rudder-github-app
6+
7+
# Set the working directory in the container
8+
WORKDIR /home/node/rudder-github-app
9+
10+
# Copy package.json and package-lock.json to the working directory
11+
COPY package*.json ./
12+
13+
# Install dependencies using npm ci
14+
RUN npm ci --no-audit --cache .npm
15+
16+
# Copy the rest of the application code to the working directory
17+
COPY . .
18+
19+
# Change ownership of the copied files to the node user
20+
RUN chown -R node:node /home/node/rudder-github-app
21+
22+
# Switch to the node user
23+
USER node
24+
25+
# Expose the port the app runs on
26+
EXPOSE 3000
27+
28+
# Start the app using npm start
29+
CMD ["npm", "start"]

db.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3'
2+
services:
3+
app:
4+
build: .
5+
ports:
6+
- "3000:3000"
7+
environment:
8+
- NODE_ENV=production
9+
- PORT=3000
10+
- APP_ID=123456 # Update with your GitHub app ID
11+
- GITHUB_APP_PRIVATE_KEY_BASE64=LS0tHL.....o= # Update with your GitHub app private key (base64 encoded)
12+
- WEBHOOK_SECRET=webhooksecret # Update with your GitHub webhook secretset in your GitHub app
13+
- WEBSITE_ADDRESS=http://localhost:3000 # Update with your public website address
14+
15+
# To enable live code changes during development, attach current directory as volume
16+
# volumes:
17+
# - .:/home/node/rudder-github-app

package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/storage.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ import { resolve } from "path";
44
import { PROJECT_ROOT_PATH } from "./helpers.js";
55

66
const dbPath = process.env.DB_PATH || resolve(PROJECT_ROOT_PATH, "db.json");
7+
createFileIfMissing(dbPath);
8+
9+
function createFileIfMissing(path){
10+
try {
11+
// Try to open the file in read-only mode
12+
const fd = fs.openSync(path, 'r');
13+
fs.closeSync(fd);
14+
console.log('DB file exists at '+dbPath);
15+
} catch (err) {
16+
if (err.code === 'ENOENT') {
17+
// If the file does not exist, create it
18+
fs.writeFileSync(path, '[]', { flag: 'wx' }); // 'wx' flag ensures the file is created and not overwritten if it exists
19+
console.log('DB file created at '+dbPath);
20+
} else {
21+
// Some other error occurred
22+
console.error(err);
23+
throw new Error("Failed to create the DB file at "+dbPath);
24+
}
25+
}
26+
}
727

828
export const storage = {
929
save(data) {

0 commit comments

Comments
 (0)