Skip to content

Commit e87605b

Browse files
committed
dockerize client
1 parent f039d73 commit e87605b

12 files changed

+895
-1260
lines changed

.dockerignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
node_modules
2+
Dockerfile*
3+
docker-compose*
4+
.dockerignore
5+
.git
6+
.gitignore
7+
README.md
8+
LICENSE
9+
.vscode
10+
Makefile
11+
helm-charts
12+
.env
13+
.editorconfig
14+
.idea
15+
coverage*

Dockerfile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# use the official Bun image
2+
# see all versions at https://hub.docker.com/r/oven/bun/tags
3+
FROM oven/bun:1 as base
4+
WORKDIR /usr/src/app
5+
6+
# install dependencies into temp directory
7+
# this will cache them and speed up future builds
8+
FROM base AS install
9+
RUN mkdir -p /temp/dev
10+
COPY package.json bun.lockb /temp/dev/
11+
RUN cd /temp/dev && bun install --frozen-lockfile
12+
13+
# install with --production (exclude devDependencies)
14+
RUN mkdir -p /temp/prod
15+
COPY package.json bun.lockb /temp/prod/
16+
RUN cd /temp/prod && bun install --frozen-lockfile --production
17+
18+
# copy node_modules from temp directory
19+
# then copy all (non-ignored) project files into the image
20+
FROM base AS prerelease
21+
COPY --from=install /temp/dev/node_modules node_modules
22+
COPY . .
23+
24+
# [optional] tests & build
25+
ENV NODE_ENV=production
26+
RUN bun test
27+
RUN bun run build
28+
29+
# copy production dependencies and source code into final image
30+
FROM base AS release
31+
COPY --from=install /temp/prod/node_modules node_modules
32+
COPY --from=prerelease /usr/src/app/bin ./bin
33+
COPY --from=prerelease /usr/src/app/lib ./lib
34+
COPY --from=prerelease /usr/src/app/package.json .
35+
36+
# run the app
37+
USER bun
38+
ENTRYPOINT [ "bun", "run", "./bin/cli.ts" ]

bin/cli.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,45 @@ import { Command, Option } from "commander";
55

66
const program = new Command();
77
let paramURL: string = "";
8-
let paramFollow: boolean;
8+
let paramFollow: boolean = false;
99
let paramPollInterval: number;
1010
let ordered: Ordered = "none";
11-
12-
let polling = false;
11+
let quiet: boolean = false;
12+
let save: string | undefined;
1313

1414
program
1515
.arguments("<url>")
1616
.option("-f, --follow", "follow the LDES, the client stays in sync")
17+
.option("-q", "Be quiet")
1718
.addOption(
18-
new Option("--ordered <ordered>", "emit members in order")
19+
new Option("-o --ordered <ordered>", "emit members in order")
1920
.choices(["ascending", "descending", "none"])
2021
.default("none"),
2122
)
2223
.option(
2324
"-s, --save <path>",
2425
"filepath to the save state file to use, used both to resume and to update",
2526
)
26-
.addOption(
27-
new Option("--polling <boolean>", "Enable polling")
28-
.choices(["true", "false"])
29-
.default("false"),
30-
)
3127
.option("--pollInterval <number>", "Specify poll interval")
3228
.option("--shape <shapefile>", "Specify a shapefile")
29+
.option("--save <shapefile>", "Specify save location")
3330
.action((url: string, program) => {
31+
save = program.save;
3432
paramURL = url;
3533
paramFollow = program.follow;
3634
paramPollInterval = program.pollInterval;
3735
ordered = program.ordered;
38-
polling = program.polling == "true";
39-
// console.log(paramURL)
40-
// console.log(program.follow, paramPollInterval)
36+
quiet = program.q;
4137
});
4238

4339
program.parse(process.argv);
4440

4541
async function main() {
4642
const client = replicateLDES(
4743
intoConfig({
48-
polling,
44+
polling: paramFollow,
4945
url: paramURL,
46+
stateFile: save,
5047
follow: paramFollow,
5148
pollInterval: paramPollInterval,
5249
fetcher: { maxFetched: 2, concurrentRequests: 10 },
@@ -63,10 +60,11 @@ async function main() {
6360
while (el) {
6461
if (el.value) {
6562
seen.add(el.value.id);
66-
if (seen.size % 100 == 1) {
67-
console.log("Got member", seen.size, "quads", el.value.quads.length);
63+
if (!quiet) {
64+
if (seen.size % 100 == 1) {
65+
console.log("Got member", seen.size, "quads", el.value.quads.length);
66+
}
6867
}
69-
// console.log("Found", seen.size, "members");
7068
}
7169

7270
if (el.done) {

bin/repl.ts

Whitespace-only changes.

bin/run.ts

-3
This file was deleted.

bin/sync.ts

Whitespace-only changes.

bin/validate.ts

-8
This file was deleted.

lib/client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Config } from "./config";
22
import { Member } from "./page";
33
import rdfDereference, { RdfDereferencer } from "rdf-dereference";
4-
import { FileStateFactory, State, StateFactory } from "./state";
4+
import { FileStateFactory, NoStateFactory, State, StateFactory } from "./state";
55
import { CBDShapeExtractor } from "extract-cbd-shape";
66
import { DataFactory, Store } from "n3";
77
import { Term } from "@rdfjs/types";
@@ -152,7 +152,7 @@ export class Client {
152152

153153
this.streamId = stream;
154154
this.ordered = ordered;
155-
this.stateFactory = new FileStateFactory(config.stateFile);
155+
this.stateFactory = config.stateFile ? new FileStateFactory(config.stateFile) : new NoStateFactory();
156156
this.modulatorFactory = new ModulatorFactory(this.stateFactory);
157157

158158
if (process) {

lib/config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface Config {
2020
polling: boolean;
2121
follow: boolean;
2222
url: string;
23-
stateFile: string;
23+
stateFile?: string;
2424
pollInterval: number;
2525
mediator: MediatorConfig;
2626
fetcher: FetcherConfig;
@@ -41,7 +41,6 @@ export interface WithTarget {
4141
const defaultConfig: Config = {
4242
polling: false,
4343
follow: false,
44-
stateFile: "save.json",
4544
url: "",
4645
pollInterval: 200,
4746
fetcher: DefaultFetcherConfig,

lib/state.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ export interface StateFactory {
6262
write(): void;
6363
}
6464

65-
export class LocalStorateStateFactory {}
65+
export class NoStateFactory implements StateFactory {
66+
build<T>(
67+
_name: string,
68+
_serialize: (item: T) => string,
69+
deserialize: (item: string) => T | undefined,
70+
create: () => T,
71+
): StateT<T> {
72+
return new StateT<any>(deserialize, create);
73+
}
74+
write(): void {
75+
}
76+
}
6677

6778
export class FileStateFactory implements StateFactory {
6879
private location: string;

0 commit comments

Comments
 (0)