Skip to content

Commit

Permalink
Merge pull request #51 from dxw/feature/add-dockerfile-and-docker-com…
Browse files Browse the repository at this point in the history
…pose

Add `Dockerfile` and `docker-compose.yml` files
  • Loading branch information
danlivings-dxw authored Oct 14, 2024
2 parents 8977ba0 + c779301 commit 17f1836
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_ID=123456
PRIVATE_KEY_PATH=/path/to/app.private-key.pem
PRIVATE_KEY= # Use `script/encode-key <path-to-pem-file>` to encode the private key
CLIENT_ID=SomeClientId123
CLIENT_SECRET=secret
WEBHOOK_SECRET=secret
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:22.8.0-slim

WORKDIR /towtruck
VOLUME /data

ARG APP_ID
ARG PRIVATE_KEY
ARG CLIENT_ID
ARG CLIENT_SECRET
ARG WEBHOOK_SECRET

COPY . .

RUN touch .env \
&& echo "APP_ID=$APP_ID" >> .env \
&& echo "PRIVATE_KEY=$PRIVATE_KEY" >> .env \
&& echo "CLIENT_ID=$CLIENT_ID" >> .env \
&& echo "CLIENT_SECRET=$CLIENT_SECRET" >> .env \
&& echo "WEBHOOK_SECRET=$WEBHOOK_SECRET" >> .env

RUN npm install

EXPOSE 3000
CMD [ "sh", "-c", "npm run seed && exec npm run start" ]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ The environment variables are available here: https://github.com/organizations/d

In order for Towtruck to communicate with the GitHub API, it needs several pieces of information, configured through environment variables:
- `APP_ID`: The unique numeric ID assigned to the GitHub App. This can be found in the dxw-towtruck app settings.
- `PRIVATE_KEY_PATH`: The private key used to sign access token requests. Towtruck expects this to be an absolute path to a `.pem` file stored locally and generated by GitHub in the app settings.
- `PRIVATE_KEY`: The private key used to sign access token requests.
Towtruck expects this to be a `.pem` file generated by GitHub in the app settings and encoded using Base64.
This can be generated from the `.pem` file by running `script/encode-key <path-to-pem-file>` in the terminal and copying the output.
- `CLIENT_ID`: A unique alphanumeric ID assigned to the GitHub App. This can be found in the dxw-towtruck app settings
- `CLIENT_SECRET`: A token used to authenticate API requests. These are generated by GitHub in the dxw-towtruck app settings.
- `WEBHOOK_SECRET`: A user-defined secret used to authenticate GitHub to Towtruck for receiving webhooks. This must be exactly the same as it is entered in the app settings on GitHub.
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
towtruck:
build: .
ports:
- "3000:3000"
3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
web: Dockerfile
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const httpServer = createServer(async (request, response) => {
return response.end(template);
});

const PORT = 3000;
const PORT = process.env.PORT || 3000;
httpServer.listen(PORT, () => {
console.info(`Server is running on port ${PORT}`);
});
5 changes: 2 additions & 3 deletions octokitApp.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { readFileSync } from "fs";
import { App, createNodeMiddleware } from "@octokit/app";

const APP_ID = process.env.APP_ID;
const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const CLIENT_ID = process.env.CLIENT_ID;
const CLIENT_SECRET = process.env.CLIENT_SECRET;
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET;

const privateKey = readFileSync(PRIVATE_KEY_PATH).toString();
const privateKey = Buffer.from(PRIVATE_KEY, 'base64').toString('ascii');

const app = new App({
appId: APP_ID,
Expand Down
4 changes: 4 additions & 0 deletions script/encode-key
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

cat $1 | openssl base64 | tr -d '\n'
echo

0 comments on commit 17f1836

Please sign in to comment.