Skip to content

Commit

Permalink
initial service entrypoint and dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jun 14, 2023
1 parent 3ec773b commit 11e77b5
Show file tree
Hide file tree
Showing 5 changed files with 3,086 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM node:18-alpine as build

# Move files into the image and install
WORKDIR /app
COPY ./service ./service

WORKDIR /app/service
RUN yarn install --production --frozen-lockfile > /dev/null

# Uses assets from build stage to reduce build size
FROM node:18-alpine

# RUN npm install -g yarn
RUN apk add --update dumb-init

# Avoid zombie processes, handle signal forwarding
ENTRYPOINT ["dumb-init", "--"]

WORKDIR /app/service
COPY --from=build /app /app
RUN mkdir /app/data && chown node /app/data

VOLUME /app/data
EXPOSE 3000
ENV PDS_PORT=3000
ENV NODE_ENV=production

# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user
USER node
CMD ["node", "--heapsnapshot-signal=SIGUSR2", "--enable-source-maps", "index.js"]

LABEL org.opencontainers.image.source=https://github.com/bluesky-social/pds
LABEL org.opencontainers.image.description="ATP Personal Data Server (PDS)"
LABEL org.opencontainers.image.licenses=MIT
33 changes: 33 additions & 0 deletions service/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
const {
PDS,
Database,
envToCfg,
envToSecrets,
readEnv,
} = require("@atproto/pds");

const main = async () => {
const env = readEnv();
const cfg = envToCfg(env);
const secrets = envToSecrets(env);
const pds = await PDS.create(cfg, secrets);
if (cfg.db.dialect === "pg") {
// Migrate using credentialed user
const migrateDb = Database.postgres({
url: cfg.db.migrationUrl,
schema: cfg.db.schema,
});
await migrateDb.migrateToLatestOrThrow();
await migrateDb.close();
} else {
await pds.ctx.db.migrateToLatestOrThrow();
}
await pds.start();
// Graceful shutdown (see also https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/)
process.on("SIGTERM", async () => {
await pds.destroy();
});
};

main();
11 changes: 11 additions & 0 deletions service/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "pds",
"private": true,
"version": "0.0.0",
"description": "Service entrypoint for atproto personal data server",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@atproto/pds": "0.2.0-beta.0"
}
}
Loading

0 comments on commit 11e77b5

Please sign in to comment.