Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy using docker #28

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 0 additions & 1 deletion db.json

This file was deleted.

17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading