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

update to pdsv2 #33

Merged
merged 7 commits into from
Feb 22, 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
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- pdsv2
env:
REGISTRY: ghcr.io
USERNAME: ${{ github.actor }}
Expand Down Expand Up @@ -51,7 +52,6 @@ jobs:
platforms: linux/amd64,linux/arm64
file: ./Dockerfile
tags: |
ghcr.io/bluesky-social/pds:latest
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand Down
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM node:18-alpine as build
FROM node:20.11-alpine3.18 as build

RUN npm install -g pnpm

# Move files into the image and install
WORKDIR /app
COPY ./service ./
RUN yarn install --production --frozen-lockfile > /dev/null
RUN pnpm install --production --frozen-lockfile > /dev/null

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

RUN apk add --update dumb-init

Expand All @@ -19,6 +21,8 @@ COPY --from=build /app /app
EXPOSE 3000
ENV PDS_PORT=3000
ENV NODE_ENV=production
# potential perf issues w/ io_uring on this version of node
ENV UV_USE_IO_URING=0

CMD ["node", "--enable-source-maps", "index.js"]

Expand Down
16 changes: 8 additions & 8 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ function main {

From your DNS provider's control panel, create the required
DNS record with the value of your server's public IP address.

+ Any DNS name that can be resolved on the public internet will work.
+ Replace example.com below with any valid domain name you control.
+ A TTL of 600 seconds (10 minutes) is recommended.

Example DNS record:

NAME TYPE VALUE
---- ---- -----
example.com A ${PUBLIC_IP:-Server public IP}
Expand Down Expand Up @@ -235,7 +235,7 @@ INSTALLER_MESSAGE
sleep 2
done
fi

apt-get update
apt-get install --yes ${REQUIRED_SYSTEM_PACKAGES}

Expand Down Expand Up @@ -400,7 +400,7 @@ SYSTEMD_UNIT_FILE

cat <<INSTALLER_MESSAGE
========================================================================
PDS installation successful!
PDS installation successful!
------------------------------------------------------------------------

Check service status : sudo systemctl status pds
Expand All @@ -417,10 +417,10 @@ HTTP Control Panel Inbound 443 TCP Any

Required DNS entries
------------------------------------------------------------------------
Name Type Value
Name Type Value
------- --------- ---------------
${PDS_HOSTNAME} A ${PUBLIC_IP}
*.${PDS_HOSTNAME} A ${PUBLIC_IP}
${PDS_HOSTNAME} A ${PUBLIC_IP}
*.${PDS_HOSTNAME} A ${PUBLIC_IP}

Detected public IP of this server: ${PUBLIC_IP}

Expand Down
56 changes: 43 additions & 13 deletions service/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";
const {
PDS,
Database,
envToCfg,
envToSecrets,
readEnv,
Expand All @@ -15,19 +14,11 @@ const main = async () => {
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();
httpLogger.info("pds is running");
httpLogger.info("pds has started");
pds.app.get("/check-handle", (req, res) => {
checkHandleRoute(pds, req, res);
});
// Graceful shutdown (see also https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/)
process.on("SIGTERM", async () => {
httpLogger.info("pds is stopping");
Expand All @@ -36,4 +27,43 @@ const main = async () => {
});
};

async function checkHandleRoute(
/** @type {PDS} */ pds,
/** @type {import('express').Request} */ req,
/** @type {import('express').Response} */ res
) {
try {
const { domain } = req.query;
if (!domain || typeof domain !== "string") {
return res.status(400).json({
error: "InvalidRequest",
message: "bad or missing domain query param",
});
}
const isHostedHandle = pds.ctx.cfg.identity.serviceHandleDomains.find(
(avail) => domain.endsWith(avail)
);
if (!isHostedHandle) {
return res.status(400).json({
error: "InvalidRequest",
message: "handles are not provided on this domain",
});
}
const account = await pds.ctx.accountManager.getAccount(domain);
if (!account) {
return res.status(404).json({
error: "NotFound",
message: "handle not found for this domain",
});
}
return res.json({ did: account.did, handle: account.handle });
} catch (err) {
httpLogger.error({ err }, "check handle failed");
return res.status(500).json({
error: "InternalServerError",
message: "Internal Server Error",
});
}
}

main();
2 changes: 1 addition & 1 deletion service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@atproto/pds": "0.3.0-beta.3"
"@atproto/pds": "0.4.0-beta.1"
}
}
Loading
Loading