Skip to content
Open
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
11 changes: 6 additions & 5 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ runs:
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- uses: pnpm/action-setup@v6
with:
cache: true
- uses: actions/cache@v5
with:
path: |
~/.npm
~/.cache/Cypress
key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- run: npm ci
path: ~/.cache/Cypress
key: cypress-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
- run: pnpm ci
shell: bash
17 changes: 7 additions & 10 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,33 @@ jobs:
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm --workspace=discojs run build
- run: pnpm -F discojs run build

build-lib-node:
needs: build-lib
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm --workspace=discojs-node run build
- run: pnpm -F discojs-node run build

build-lib-web:
needs: build-lib
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm run --workspace=discojs-web build
- run: pnpm -F discojs-web run build

build-server:
needs: build-lib-node
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm run --workspace=server build
- run: pnpm -F server run build

build-server-docker:
needs: build-server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
Expand All @@ -59,7 +58,7 @@ jobs:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
# Build all subprojects to upload all artifacts at once
- run: npm run --workspaces build
- run: pnpm -r run build
- uses: actions/upload-artifact@v7
with: { name: all-builds, path: "*/dist" }

Expand All @@ -69,14 +68,12 @@ jobs:
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm --workspace=webapp run build
- run: pnpm -F webapp run build

build-docs-examples:
needs: build-server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm --workspace=server run build
- run: npm run build
working-directory: docs/examples
- run: pnpm -F examples run build
2 changes: 1 addition & 1 deletion .github/workflows/_static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm run lint
- run: pnpm run lint
16 changes: 8 additions & 8 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: ./.github/actions/pull-dataset-artifacts
- uses: actions/download-artifact@v7
with: { name: all-builds }
- run: npx vitest --run --project=discojs
- run: pnpm exec vitest --run --project=discojs

test-discojs-node:
runs-on: ubuntu-latest
Expand All @@ -21,7 +21,7 @@ jobs:
- uses: ./.github/actions/pull-dataset-artifacts
- uses: actions/download-artifact@v7
with: { name: all-builds }
- run: npx vitest --run --project=discojs-node
- run: pnpm exec vitest --run --project=discojs-node

test-discojs-web:
runs-on: ubuntu-latest
Expand All @@ -31,7 +31,7 @@ jobs:
- uses: ./.github/actions/pull-dataset-artifacts
- uses: actions/download-artifact@v7
with: { name: all-builds }
- run: npx vitest --run --project=discojs-web
- run: pnpm exec vitest --run --project=discojs-web

test-server:
runs-on: ubuntu-latest
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: ./.github/actions/pull-dataset-artifacts
- uses: actions/download-artifact@v7
with: { name: all-builds }
- run: npx vitest --run --project=server
- run: pnpm exec vitest --run --project=server

test-webapp:
runs-on: ubuntu-latest
Expand All @@ -51,7 +51,7 @@ jobs:
- uses: ./.github/actions/pull-dataset-artifacts
- uses: actions/download-artifact@v7
with: { name: all-builds }
- run: npm --workspace=webapp run test:unit
- run: pnpm -F webapp run test:unit

test-e2e:
runs-on: ubuntu-latest
Expand All @@ -65,7 +65,7 @@ jobs:
with:
working-directory: webapp
install: false
start: npx vite --mode test --port 1351
start: pnpm exec vite --mode test --port 1351

test-cli:
runs-on: ubuntu-latest
Expand All @@ -75,7 +75,7 @@ jobs:
- uses: ./.github/actions/pull-dataset-artifacts
- uses: actions/download-artifact@v7
with: { name: all-builds }
- run: npm --workspace=cli start -- -t cifar10 -u 3 -e 1 -r 1
- run: pnpm -F cli start -t cifar10 -u 3 -e 1 -r 1

test-docs-examples:
runs-on: ubuntu-latest
Expand All @@ -85,5 +85,5 @@ jobs:
- uses: ./.github/actions/pull-dataset-artifacts
- uses: actions/download-artifact@v7
with: { name: all-builds }
- run: npm run test
- run: pnpm run test
working-directory: docs/examples
2 changes: 1 addition & 1 deletion .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm run format:check
- run: pnpm run format:check
11 changes: 5 additions & 6 deletions .github/workflows/publish-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ jobs:
registry-url: "https://registry.npmjs.org"
package-manager-cache: false # never use caching in release builds
scope: "@epfml"
- run: npm install -g npm@latest
- run: npm ci
- run: npm --workspace=discojs{,-node,-web} version prerelease --preid=p`date +%Y%m%d%H%M%S`
- run: pnpm ci
- run: pnpm -F 'discojs*' version prerelease --preid=p`date +%Y%m%d%H%M%S`
if: github.ref_type == 'branch'
- run: npm --workspace=discojs{,-node,-web} run build
- run: npm --workspace=discojs{,-node,-web} publish --access public --tag latest
- run: pnpm -F 'discojs*' run build
- run: pnpm -F 'discojs*' publish --access public --tag latest

build-webapp:
if: github.ref_type == 'branch'
Expand All @@ -33,7 +32,7 @@ jobs:
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- run: npm --workspace=webapp run build
- run: pnpm -F webapp run build
- uses: actions/upload-pages-artifact@v5
with:
path: webapp/dist
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/record-cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/pull-dataset-artifacts
- run: npm --workspace=webapp run build
- run: npm --workspace=webapp run test:unit
- run: pnpm -F webapp run build
- run: pnpm -F webapp run test:unit
- uses: cypress-io/github-action@v7
with:
working-directory: webapp
install: false
start: npm start
start: pnpm start
wait-on: "http://localhost:8081" # Waits for above
# Records to Cypress Cloud
# https://docs.cypress.io/guides/cloud/projects#Set-up-a-project-to-record
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# dependencies
/node_modules/
/docs/examples/node_modules/
/*/node_modules/

# stored trained models
models/
Expand Down
2 changes: 1 addition & 1 deletion .knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ignore": ["docs/**"]
},
"webapp": {
"ignore": ["env.d.ts", "src/shims-vue.d.ts"]
"ignore": ["env.d.ts"]
}
}
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Prettier also ignores everything from .gitignore
package-lock.json
pnpm-lock.yaml

# File formats that are not filtered by default
*.png
Expand Down
33 changes: 21 additions & 12 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ git clone git@github.com:epfml/disco.git
cd disco
```

**2.** Install Node.js
**2.** Install Node.js and pnpm

We recommend using [nvm](https://github.com/nvm-sh/nvm) (Node Version Manager) to handle multiple Node.js versions. Start by installing `nvm` by following [their installation instructions](https://github.com/nvm-sh/nvm#installing-and-updating).
After installation, you should be able to run
Expand All @@ -71,24 +71,33 @@ Use it to install the version we use in DISCO.
nvm install # it reads `.nvmrc` to select the correct version
```

`nvm` manages your different Node.js versions while `npm` handles your different Node.js project packages within one version.
To use pnpm, you can use corepack, which usually comes bundled with Node.js

```
corepack enable
corepack use pnpm
```

`nvm` manages your different Node.js versions while `pnpm` handles your different Node.js project packages within one version.

There are many possible way to install those programs, feel free to pick the one that suits you.

**3.** Install the dependencies

```
npm ci
pnpm ci
```

**4.** Build the projects

Then we need to build the packages, which means to compile TypeScript into JavaScript.

Disco is split in multiple packages, called workspaces in NPM, which are described in the [Structure Section](#structure).
You can add `--workspaces` (or shorter as `-ws`) to many `npm` commands to act on all packages.
Or you can select a specific workspace via `--workspace=$name-or-path-to-package` (`-w $name-or-path-to-package`).
You can add `-r` to many `pnpm` commands to act on all packages.
Or you can select a specific workspace via `--filter=$name-or-path-to-package` (`-F $name-or-path-to-package`).

```
npm -ws run build
pnpm -r run build
```

**5.** Download and extract the sample training datasets. These datasets are used in the automated tests.
Expand All @@ -104,15 +113,15 @@ As you may have seen, there are many ways to use DISCO. Here we will run a serve
- First launch a `server` instance, which is used for federated and decentralized learning tasks, e.g. to list peers participating in a decentralized task.

```
npm -w server start
pnpm -F server start
```

The server should be listening on `http://localhost:8080/`.

- Secondly, start a web client, which will allow you to use DISCO from your browser. You will have to do so **from another terminal** since the previous one is now used by the server.

```
npm -w webapp start # from another terminal
pnpm -F webapp start # from another terminal
```

The web client should be running on `http://localhost:1351`, if not first restart the server and then the web client.
Expand All @@ -136,15 +145,15 @@ The last step of the installation instructions describe how to start a web inter
From the root level, launch a `server` instance:

```
npm -w server start
pnpm -F server start
```

The server should be listening on `http://localhost:8080/`.

Start the webapp:

```
npm -w webapp start # from another terminal
pnpm -F webapp start # from another terminal
```

The web client should be running on `http://localhost:8081`. Running the last command should also output a Network address at which devices on the same network can access the UI. You can find more information in the [Contributing to the `webapp`](./docs/CONTRIBUTING.md#contributing-to-webapp) Section as well as the [server README](./server/README.md).
Expand All @@ -159,8 +168,8 @@ Training a model with the `cli` on pre-defined tasks is straightforward:

```
# From the root folder
npm -w cli start -- --task cifar10 --numberOfUsers 4 --epochs 15 --roundDuration 5
npm -w cli start -- --help # for all options
pnpm -F cli start --task cifar10 --numberOfUsers 4 --epochs 15 --roundDuration 5
pnpm -F cli start --help # for all options
```

Adding CLI support for another task is described in the [CLI README](./cli/README.md).
Expand Down
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
# TODO freeze to 22 until tfjs#8425 is merged
FROM node:22 AS builder

RUN corepack enable

WORKDIR /disco

COPY package*.json .
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY isomorphic-wrtc/package.json isomorphic-wrtc/
COPY discojs/package.json discojs/
COPY discojs-node/package.json discojs-node/
COPY server/package.json server/
RUN npm ci
RUN pnpm ci

COPY isomorphic-wrtc/ isomorphic-wrtc/
# Necessary for syncing workspace injected dependencies
RUN pnpm ci
COPY discojs/ discojs/
COPY discojs-node/ discojs-node/
COPY tsconfig.base.json .
RUN npm --workspace=discojs --workspace=discojs-node run build
RUN pnpm -F discojs -F discojs-node run build

COPY server/ server/
RUN cd server/ && npm run build
RUN pnpm -F server run build

FROM node:22-slim AS runner

WORKDIR /disco

COPY --link --from=builder /disco/package*.json /disco/
RUN corepack enable

COPY --link --from=builder /disco/package.json /disco/pnpm*.yaml /disco/
COPY --link --from=builder /disco/isomorphic-wrtc/package.json isomorphic-wrtc/
COPY --link --from=builder /disco/discojs/package.json discojs/
COPY --link --from=builder /disco/discojs-node/package.json discojs-node/
COPY --link --from=builder /disco/server/package.json server/
RUN npm --omit=dev ci

# We need to copy the file dependency before installing
COPY --link --from=builder /disco/isomorphic-wrtc/ isomorphic-wrtc/
RUN pnpm --prod ci

COPY --link --from=builder /disco/discojs/dist/ discojs/dist/
COPY --link --from=builder /disco/discojs-node/dist/ discojs-node/dist/
COPY --link --from=builder /disco/server/dist/ server/dist/
Expand Down
Loading