-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/helia-ipns
* main: (27 commits) feat(e2e): add /api/v0/repo/gc test chore: disable METRICS on CI e2e test runs test: add e2e test for /api/v0/version endpoint feat(server): ⚡️ Subdomain Gateway Using Fastify (#31) feat: use production level docker settings (#26) chore: remove unused playwright init code fix: use active LTS in package.json engines fix: playwright CI node-version=20 test: get clinic flame & doctor output from e2e tests test: e2e updates fix: use HOST constant in healthcheck fix: use HOST constant test: cleanup playwright test code test: add playwright tests feat: move HOST,PORT to src/constants.ts fix: ✏️ Fixing urls. (#23) fix: ✏️ helia-docker -> helia-http-gateway (#22) build(deps): Bump @babel/traverse and depcheck (#13) feat: add health-check (#21) fix(server): 🩹 Using sessionID as a fallback to requests where referer is missing. (#20) ... Signed-off-by: Nishant Arora <[email protected]>
- Loading branch information
Showing
20 changed files
with
10,029 additions
and
3,682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npm run test:e2e | ||
env: | ||
METRICS: false | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
FROM node:20-slim | ||
FROM node:20-slim as builder | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y build-essential cmake git libssl-dev | ||
RUN apt-get install -y build-essential cmake git libssl-dev tini | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
COPY package*.json ./ | ||
|
||
RUN npm ci --quiet | ||
|
||
COPY . . | ||
|
||
RUN npm run build | ||
CMD [ "npm", "start" ] | ||
|
||
RUN npm prune --omit=dev | ||
|
||
FROM node:20-slim as app | ||
ENV NODE_ENV production | ||
WORKDIR /app | ||
# built src without dev dependencies | ||
COPY --from=builder /app ./ | ||
# tini is used to handle signals properly, see https://github.com/krallin/tini#using-tini | ||
COPY --from=builder /usr/bin/tini /usr/bin/tini | ||
|
||
# copy shared libraries (without having artifacts from apt-get install that is needed to build our application) | ||
COPY --from=builder /usr/lib/**/libcrypto* /usr/lib/ | ||
COPY --from=builder /usr/lib/**/libssl* /usr/lib/ | ||
|
||
HEALTHCHECK --interval=12s --timeout=12s --start-period=10s CMD npm run healthcheck | ||
|
||
# Use tini to handle signals properly, see https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals | ||
ENTRYPOINT ["/usr/bin/tini", "-p", "SIGKILL", "--"] | ||
|
||
CMD [ "node", "dist/src/index.js" ] | ||
|
||
# for best practices, see: | ||
# * https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/ | ||
# * https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md | ||
# * https://nodejs.org/en/docs/guides/nodejs-docker-webapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
version: "3.8" | ||
|
||
services: | ||
server: | ||
helia-http-gateway: | ||
build: . | ||
restart: always | ||
ports: | ||
- "8080:8080" | ||
- "${PORT:-8080}:8080" | ||
environment: | ||
- DEBUG="helia-server*" | ||
- DEBUG="${DEBUG:-helia-http-gateway*}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { PORT } from '../src/constants.js' | ||
|
||
// test all the same pages listed at https://probelab.io/websites/ | ||
const pages = [ | ||
// '/ipns/blog.ipfs.tech', // currently timing out for Helia. | ||
'/ipns/blog.libp2p.io', | ||
'/ipns/consensuslab.world', | ||
'/ipns/docs.ipfs.tech', | ||
'/ipns/docs.libp2p.io', | ||
'/ipns/drand.love', | ||
// '/ipns/fil.org', // currently timing out for Helia. | ||
// '/ipns/filecoin.io', // currently timing out for Helia. | ||
'/ipns/green.filecoin.io', | ||
// '/ipns/ipfs.tech', // currently timing out for Helia. | ||
'/ipns/ipld.io', | ||
'/ipns/libp2p.io', | ||
// '/ipns/n0.computer', // currently timing out for Helia. | ||
'/ipns/probelab.io', | ||
'/ipns/protocol.ai', // very slow, but can pass. | ||
'/ipns/research.protocol.ai', // slow-ish, but can pass. | ||
'/ipns/singularity.storage', | ||
'/ipns/specs.ipfs.tech', | ||
'/ipns/strn.network' | ||
// '/ipns/web3.storage' // currently timing out for Helia | ||
] | ||
|
||
// increase default test timeout to 2 minutes | ||
test.setTimeout(120000) | ||
|
||
// now for each page, make sure we can request the website, the content is not empty, and status code is 200 | ||
pages.forEach((pagePath) => { | ||
// afterEach, we should request /api/v0/repo/gc to clear the cache | ||
test(`helia-http-gateway matches ipfs.io for path '${pagePath}'`, async ({ page }) => { | ||
const ipfsIoResponse = await page.goto(`http://ipfs.io${pagePath}`) | ||
expect(ipfsIoResponse?.status()).toBe(200) | ||
const ipfsIoContent = await ipfsIoResponse?.text() | ||
// TODO: enable screenshot testing? maybe not needed if we're confirming text content matches. | ||
// await page.screenshot({ path: `screenshots${pagePath}.png`, fullPage: true }); | ||
const heliaGatewayResponse = await page.goto(`http://localhost:${PORT}${pagePath}`) | ||
expect(heliaGatewayResponse?.status()).toBe(200) | ||
// expect(page).toHaveScreenshot(`screenshots${pagePath}.png`, { fullPage: true, maxDiffPixelRatio: 0 }); | ||
|
||
// expect the response text content to be the same | ||
const heliaGatewayContent = await heliaGatewayResponse?.text() | ||
expect(heliaGatewayContent).toEqual(ipfsIoContent) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { PORT } from '../src/constants.js' | ||
|
||
test('POST /api/v0/repo/gc', async ({ page }) => { | ||
const result = await page.request.post(`http://localhost:${PORT}/api/v0/repo/gc`) | ||
expect(result?.status()).toBe(200) | ||
|
||
const maybeContent = await result?.text() | ||
expect(maybeContent).toEqual('OK') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { PORT } from '../src/constants.js' | ||
|
||
function validateResponse (content: string): void { | ||
expect(() => JSON.parse(content)).not.toThrow() | ||
const versionObj = JSON.parse(content) | ||
|
||
expect(versionObj).toHaveProperty('Version') | ||
expect(versionObj).toHaveProperty('Commit') | ||
} | ||
|
||
test('GET /api/v0/version', async ({ page }) => { | ||
const result = await page.goto(`http://localhost:${PORT}/api/v0/version`) | ||
expect(result?.status()).toBe(200) | ||
|
||
const maybeContent = await result?.text() | ||
expect(maybeContent).not.toBe(undefined) | ||
validateResponse(maybeContent as string) | ||
}) | ||
|
||
test('POST /api/v0/version', async ({ page }) => { | ||
const result = await page.request.post(`http://localhost:${PORT}/api/v0/version`) | ||
expect(result?.status()).toBe(200) | ||
|
||
const maybeContent = await result?.text() | ||
expect(maybeContent).not.toBe(undefined) | ||
validateResponse(maybeContent) | ||
}) |
Oops, something went wrong.