Skip to content

Commit 11e77b5

Browse files
committed
initial service entrypoint and dockerfile
1 parent 3ec773b commit 11e77b5

File tree

5 files changed

+3086
-0
lines changed

5 files changed

+3086
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM node:18-alpine as build
2+
3+
# Move files into the image and install
4+
WORKDIR /app
5+
COPY ./service ./service
6+
7+
WORKDIR /app/service
8+
RUN yarn install --production --frozen-lockfile > /dev/null
9+
10+
# Uses assets from build stage to reduce build size
11+
FROM node:18-alpine
12+
13+
# RUN npm install -g yarn
14+
RUN apk add --update dumb-init
15+
16+
# Avoid zombie processes, handle signal forwarding
17+
ENTRYPOINT ["dumb-init", "--"]
18+
19+
WORKDIR /app/service
20+
COPY --from=build /app /app
21+
RUN mkdir /app/data && chown node /app/data
22+
23+
VOLUME /app/data
24+
EXPOSE 3000
25+
ENV PDS_PORT=3000
26+
ENV NODE_ENV=production
27+
28+
# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user
29+
USER node
30+
CMD ["node", "--heapsnapshot-signal=SIGUSR2", "--enable-source-maps", "index.js"]
31+
32+
LABEL org.opencontainers.image.source=https://github.com/bluesky-social/pds
33+
LABEL org.opencontainers.image.description="ATP Personal Data Server (PDS)"
34+
LABEL org.opencontainers.image.licenses=MIT

service/index.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
const {
3+
PDS,
4+
Database,
5+
envToCfg,
6+
envToSecrets,
7+
readEnv,
8+
} = require("@atproto/pds");
9+
10+
const main = async () => {
11+
const env = readEnv();
12+
const cfg = envToCfg(env);
13+
const secrets = envToSecrets(env);
14+
const pds = await PDS.create(cfg, secrets);
15+
if (cfg.db.dialect === "pg") {
16+
// Migrate using credentialed user
17+
const migrateDb = Database.postgres({
18+
url: cfg.db.migrationUrl,
19+
schema: cfg.db.schema,
20+
});
21+
await migrateDb.migrateToLatestOrThrow();
22+
await migrateDb.close();
23+
} else {
24+
await pds.ctx.db.migrateToLatestOrThrow();
25+
}
26+
await pds.start();
27+
// Graceful shutdown (see also https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/)
28+
process.on("SIGTERM", async () => {
29+
await pds.destroy();
30+
});
31+
};
32+
33+
main();

service/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "pds",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "Service entrypoint for atproto personal data server",
6+
"main": "index.js",
7+
"license": "MIT",
8+
"dependencies": {
9+
"@atproto/pds": "0.2.0-beta.0"
10+
}
11+
}

0 commit comments

Comments
 (0)