Skip to content

Commit

Permalink
Add a Dockerfile for deploying to DigitalOcean's App Platform
Browse files Browse the repository at this point in the history
Co-authored-by: Domenic Denicola <d@domenic.me>
  • Loading branch information
foolip and domenic committed Mar 18, 2021
1 parent e92e1ba commit a096e1d
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
@@ -0,0 +1,8 @@
## Ignore everything and list only what should be included.
**
!layouts
!lib
!views
!config.json
!package-lock.json
!package.json
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -90,7 +90,7 @@
"no-octal": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-process-env": "error",
"no-process-env": "off",
"no-proto": "error",
"no-redeclare": "error",
"no-restricted-properties": "off",
Expand Down
4 changes: 4 additions & 0 deletions .github/dependabot.yml
@@ -1,5 +1,9 @@
version: 2
updates:
- package-ecosystem: docker
directory: /
schedule:
interval: monthly
- package-ecosystem: npm
directory: /
schedule:
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
@@ -0,0 +1,15 @@
FROM node:14.15.5-buster-slim

WORKDIR /app

COPY . .

RUN npm install --production

ADD https://github.com/whatwg/sg/raw/main/db.json sg/db.json

ENV PORT=3000

EXPOSE $PORT

CMD [ "npm", "start" ]
11 changes: 11 additions & 0 deletions __tests__/integration.js
Expand Up @@ -34,3 +34,14 @@ test("/agreement-status throws appropriate error for incorrect pull parameter",
const body = await res.text();
expect(body).toContain("The pull parameter can only contain digits (0-9).");
});

test("/version", async () => {
process.env.VERSION = "1234567890abcdef";
const url = `http://127.0.0.1:${server.address().port}/version`;

const res = await fetch(url);
expect(res.status).toEqual(200);

const body = await res.text();
expect(body).toEqual("1234567890abcdef");
});
2 changes: 1 addition & 1 deletion lib/app.js
@@ -1,5 +1,5 @@
"use strict";
/* eslint-disable no-console, no-process-env */
/* eslint-disable no-console */
const Koa = require("koa");
const KoaRouter = require("@koa/router");
const koaHandlebars = require("koa-handlebars");
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/github.js
@@ -1,7 +1,7 @@
"use strict";
const { Octokit } = require("@octokit/rest");
const config = require("../../config.json");
const privateConfig = require("../../private-config.json");
const privateConfig = require("./private-config.js");

exports.api = new Octokit({
auth: privateConfig.gitHub.accessToken
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/json-github-database.js
@@ -1,5 +1,5 @@
"use strict";
const privateConfig = require("../../private-config.json");
const privateConfig = require("./private-config.js");
const { api, locationFromType } = require("./github.js");

exports.update = async (type, commitMessage, previousSHA, contents) => {
Expand Down
12 changes: 12 additions & 0 deletions lib/helpers/private-config.js
@@ -0,0 +1,12 @@
"use strict";
/* eslint-disable global-require */

let privateConfig;
const privateConfigFromEnv = process.env.PRIVATE_CONFIG_JSON;
if (privateConfigFromEnv) {
privateConfig = JSON.parse(Buffer.from(privateConfigFromEnv, "base64"));
} else {
privateConfig = require("../../private-config.json");
}

module.exports = privateConfig;
4 changes: 4 additions & 0 deletions lib/routes.js
Expand Up @@ -163,6 +163,10 @@ module.exports = [
path: "/version",
method: "GET",
async handler(ctx) {
if (process.env.VERSION) {
ctx.response.body = process.env.VERSION;
return;
}
await send(ctx, "version.txt");
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/server-infra/validate-github-webhook.js
@@ -1,5 +1,5 @@
"use strict";
const privateConfig = require("../../private-config.json");
const privateConfig = require("../helpers/private-config.js");
const { createHmac } = require("crypto");

module.exports = (ctx, expectedEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/tweet-webhook.js
@@ -1,5 +1,5 @@
"use strict";
const privateConfig = require("../private-config.json");
const privateConfig = require("./helpers/private-config.js");
const { standardFromRepo } = require("./helpers/workstreams.js");
const composeTweet = require("./compose-tweet.js");
const Twitter = require("twitter-lite");
Expand Down

0 comments on commit a096e1d

Please sign in to comment.