Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
name: Build test
if: github.event_name != 'push'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: npx @dappnode/dappnodesdk build --skip_save

release:
name: Release
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Publish
run: npx @dappnode/dappnodesdk publish patch --dappnode_team_preset
env:
Expand Down
6 changes: 2 additions & 4 deletions manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ FROM --platform=${BUILDPLATFORM:-amd64} node:alpine as build

WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn --frozen-lockfile --non-interactive --ignore-scripts --ignore-optional --production
RUN yarn --frozen-lockfile --non-interactive --ignore-scripts --ignore-optional

COPY . ./
RUN yarn build


RUN yarn build-webpack

##########################
# Final stage
Expand Down
21 changes: 10 additions & 11 deletions manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
"license": "MIT",
"scripts": {
"test": "mocha \"./{,!(node_modules)/**}/*.test.ts\" ",
"build": "export NODE_OPTIONS=--openssl-legacy-provider; webpack",
"clean": "rimraf dist",
"build": "npm run clean && tsc",
"build-webpack": "webpack",
"check:types": "tsc --noEmit"
},
"dependencies": {
"@types/node": "^14.14.7",
"got": "^11.8.0",
"source-map-support": "^0.5.19",
"ts-loader": "^8.0.11",
"typescript": "^4.0.5",
"webpack": "^5.4.0",
"webpack-cli": "^4.2.0"
},
"dependencies": {},
"devDependencies": {
"@types/chai": "^4.2.14",
"@types/mocha": "^8.0.4",
"@types/node": "^20.14.2",
"chai": "^4.2.0",
"eslint": "^7.13.0",
"mocha": "^8.2.1",
"prettier": "^2.1.2",
"ts-node": "^9.0.0"
"rimraf": "^5.0.7",
"ts-loader": "^9.5.1",
"typescript": "^5.4.5",
"webpack": "^5.92.0",
"webpack-cli": "^5.1.4"
}
}
54 changes: 50 additions & 4 deletions manager/src/dappmanager/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import got from "got";
import { Manifest, PublicPackage } from "../types";
import { urlJoin } from "../utils";
import { request } from "http";
import { URL } from "url";

export const ManifestMismatchErrorCode = "MANIFEST_MISMATCH";
export class ManifestMismatchError extends Error {
Expand All @@ -15,7 +16,7 @@ export class DappmanagerClient {
}

async fetchPublicPackages(): Promise<PublicPackage[]> {
return await got(urlJoin(this.baseUrl, "/public-packages")).json();
return this.fetchJson(urlJoin(this.baseUrl, "/public-packages"));
}

async fetchPackageManifest({
Expand All @@ -25,9 +26,9 @@ export class DappmanagerClient {
name: string;
version: string;
}): Promise<Manifest> {
const manifest = await got(
const manifest = await this.fetchJson(
urlJoin(this.baseUrl, `/package-manifest/${name}`)
).json<Manifest>();
);

if (name !== manifest.name)
throw new ManifestMismatchError(
Expand All @@ -40,4 +41,49 @@ export class DappmanagerClient {

return manifest;
}

private fetchJson(url: string): Promise<any> {
return new Promise((resolve, reject) => {
const { hostname, pathname, search } = new URL(url);

const options = {
hostname,
path: pathname + search,
method: "GET",
headers: {
Accept: "application/json"
}
};

const req = request(options, res => {
let data = "";

res.on("data", chunk => {
data += chunk;
});

res.on("end", () => {
if (res.statusCode !== 200) {
reject(
new Error(`Request failed with status code ${res.statusCode}`)
);
return;
}

try {
const json = JSON.parse(data);
resolve(json);
} catch (err) {
reject(err);
}
});
});

req.on("error", err => {
reject(err);
});

req.end();
});
}
}
Loading