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
18 changes: 10 additions & 8 deletions src/commands/from_github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import { CommandModule } from "yargs";
import chalk from "chalk";
import inquirer from "inquirer";
import moment from "moment";
import {
contentHashFile,
getImagePath,
getLegacyImagePath,
releaseFiles,
releaseFilesDefaultNames
} from "../params.js";

import { getInstallDnpLink } from "../utils/getLinks.js";
import {
githubGetReleases,
Expand All @@ -20,7 +14,15 @@ import {
import { ipfsAddDirFromUrls } from "../releaseUploader/ipfsNode/addDirFromUrls.js";
import { verifyIpfsConnection } from "../releaseUploader/ipfsNode/verifyConnection.js";
import { CliGlobalOptions } from "../types.js";
import { Manifest, defaultArch } from "@dappnode/types";
import {
Manifest,
defaultArch,
getImagePath,
getLegacyImagePath,
releaseFilesDefaultNames,
releaseFiles,
contentHashFile
} from "@dappnode/types";

interface CliCommandOptions extends CliGlobalOptions {
repoSlug: string;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/githubActions/endToEndTest/testCheckers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import chalk from "chalk";
import Docker from "dockerode";
import got from "got";
import { ValidatorData } from "./types.js";
import { getContainerName } from "../../../params.js";
import { Compose, Network } from "@dappnode/types";
import { Compose, Network, getContainerName } from "@dappnode/types";

export async function executeTestCheckers({
dnpName,
Expand Down
4 changes: 1 addition & 3 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import {
defaultDir,
defaultManifestFileName,
defaultManifestFormat,
getImageTag,
releaseFiles,
YargsError
} from "../params.js";
import { CliGlobalOptions } from "../types.js";
import { Manifest, Compose } from "@dappnode/types";
import { Manifest, Compose, getImageTag, releaseFiles } from "@dappnode/types";

const stringsToRemoveFromName = [
"DAppNode-package-",
Expand Down
3 changes: 1 addition & 2 deletions src/files/compose/getComposePackageImages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Compose } from "@dappnode/types";
import { getImageTag } from "../../params.js";
import { Compose, getImageTag } from "@dappnode/types";
import { PackageImage } from "../../types.js";

/**
Expand Down
4 changes: 2 additions & 2 deletions src/files/compose/updateComposeImageTags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mapValues } from "lodash-es";
import { getImageTag, upstreamImageLabel } from "../../params.js";
import { Compose } from "@dappnode/types";
import { upstreamImageLabel } from "../../params.js";
import { Compose, getImageTag } from "@dappnode/types";

/**
* Update service image tag to current version
Expand Down
3 changes: 1 addition & 2 deletions src/files/manifest/compactManifestIfCore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from "fs";
import path from "path";
import yaml from "js-yaml";
import { releaseFiles } from "../../params.js";
import { SetupWizard } from "@dappnode/types";
import { SetupWizard, releaseFiles } from "@dappnode/types";
import { readManifest } from "./readManifest.js";
import { writeManifest } from "./writeManifest.js";

Expand Down
9 changes: 7 additions & 2 deletions src/files/manifest/readManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import yaml from "js-yaml";
import fs from "fs";
import path from "path";
import { readFile } from "../../utils/file.js";
import { defaultDir, releaseFiles } from "../../params.js";
import { ManifestPaths, Manifest, ManifestFormat } from "@dappnode/types";
import { defaultDir } from "../../params.js";
import {
ManifestPaths,
Manifest,
ManifestFormat,
releaseFiles
} from "@dappnode/types";

/**
* Reads a manifest. Without arguments defaults to read the manifest at './dappnode_package.json'
Expand Down
4 changes: 2 additions & 2 deletions src/files/setupWizard/readSetupWizardIfExists.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from "fs";
import path from "path";
import yaml from "js-yaml";
import { defaultDir, releaseFiles } from "../../params.js";
import { defaultDir } from "../../params.js";
import { readFile } from "../../utils/file.js";
import { SetupWizard } from "@dappnode/types";
import { SetupWizard, releaseFiles } from "@dappnode/types";

export function readSetupWizardIfExists(dir?: string): SetupWizard | null {
const dirPath = dir || defaultDir;
Expand Down
173 changes: 1 addition & 172 deletions src/params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Architecture, FileFormat, ManifestFormat } from "@dappnode/types";
import { ManifestFormat } from "@dappnode/types";

export * from "./files/compose/params.js";

Expand All @@ -21,174 +21,3 @@ export const upstreamImageLabel = "dappnode.dnp.upstreamImage";
export const PINATA_URL = "https://api.pinata.cloud";
// The build_sdk.env file is used by "slaves" DAppNode packages to define the UPSTREAM_PROJECT and UPSTREAM_VERSION used in the gha
export const buildSdkEnvFileName = "build_sdk.env";
const containerNamePrefix = "DAppNodePackage-";
const containerCoreNamePrefix = "DAppNodeCore-";

/**
* Plain text file with should contain the IPFS hash of the release
* Necessary for the installer script to fetch the latest content hash
* of the eth clients. The resulting hashes are used by the DAPPMANAGER
* to install an eth client when the user does not want to use a remote node
*
* /ipfs/QmNqDvqAyy3pN3PvymB6chM7S1FgYyive8LosVKUuaDdfd
*/
export const contentHashFile = "content-hash";

export const releaseFiles = {
manifest: {
regex: /dappnode_package.*\.(json|yaml|yml)$/,
format: FileFormat.YAML,
maxSize: 100e3, // Limit size to ~100KB
required: true as const,
multiple: false as const
},
compose: {
regex: /compose.*\.yml$/,
format: FileFormat.YAML,
maxSize: 10e3, // Limit size to ~10KB
required: true as const,
multiple: false as const
},
signature: {
regex: /^signature\.json$/,
format: FileFormat.JSON,
maxSize: 10e3, // Limit size to ~10KB
required: false as const,
multiple: false as const
},
avatar: {
regex: /avatar.*\.png$/,
format: null,
maxSize: 100e3,
required: true as const,
multiple: false as const
},
setupWizard: {
regex: /setup-wizard\..*(json|yaml|yml)$/,
format: FileFormat.YAML,
maxSize: 100e3,
required: false as const,
multiple: false as const
},
setupSchema: {
regex: /setup\..*\.json$/,
format: FileFormat.JSON,
maxSize: 10e3,
required: false as const,
multiple: false as const
},
setupTarget: {
regex: /setup-target\..*json$/,
format: FileFormat.JSON,
maxSize: 10e3,
required: false as const,
multiple: false as const
},
setupUiJson: {
regex: /setup-ui\..*json$/,
format: FileFormat.JSON,
maxSize: 10e3,
required: false as const,
multiple: false as const
},
disclaimer: {
regex: /disclaimer\.md$/i,
format: FileFormat.TEXT,
maxSize: 100e3,
required: false as const,
multiple: false as const
},
gettingStarted: {
regex: /getting.*started\.md$/i,
format: FileFormat.TEXT,
maxSize: 100e3,
required: false as const,
multiple: false as const
},
prometheusTargets: {
regex: /.*prometheus-targets.(json|yaml|yml)$/,
format: FileFormat.YAML,
maxSize: 10e3,
required: false as const,
multiple: false as const
},
grafanaDashboards: {
regex: /.*grafana-dashboard.json$/,
format: FileFormat.JSON,
maxSize: 10e6, // ~ 10MB
required: false as const,
multiple: true as const
}
};

export const releaseFilesDefaultNames: {
[P in keyof typeof releaseFiles]: string;
} = {
manifest: "dappnode_package.json",
compose: "docker-compose.yml",
avatar: "avatar.png",
signature: "signature.json",
setupWizard: "setup-wizard.json",
setupSchema: "setup.schema.json",
setupTarget: "setup-target.json",
setupUiJson: "setup-ui.json",
disclaimer: "disclaimer.md",
gettingStarted: "getting-started.md",
grafanaDashboards: "grafana-dashboard.json",
prometheusTargets: "prometheus-targets.json"
};

// Naming

// Single arch images
export const getArchTag = (arch: Architecture): string =>
arch.replace(/\//g, "-");
export const getImagePath = (
name: string,
version: string,
arch: Architecture
): string => `${name}_${version}_${getArchTag(arch)}.txz`;
export const getLegacyImagePath = (name: string, version: string): string =>
`${name}_${version}.tar.xz`;

/**
* Get a unique domain per container, considering multi-service packages
*/
export const getContainerDomain = ({
dnpName,
serviceName
}: {
serviceName: string;
dnpName: string;
}): string => {
if (!serviceName || serviceName === dnpName) {
return dnpName;
} else {
return [serviceName, dnpName].join(".");
}
};

export const getImageTag = ({
dnpName,
serviceName,
version
}: {
dnpName: string;
serviceName: string;
version: string;
}): string => [getContainerDomain({ dnpName, serviceName }), version].join(":");

export const getContainerName = ({
dnpName,
serviceName,
isCore
}: {
dnpName: string;
serviceName: string;
isCore: boolean;
}): string =>
// Note: _PREFIX variables already end with the character "-"
[
isCore ? containerCoreNamePrefix : containerNamePrefix,
getContainerDomain({ dnpName, serviceName })
].join("");
14 changes: 7 additions & 7 deletions src/tasks/buildAndUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import rimraf from "rimraf";
import { verifyAvatar } from "../utils/verifyAvatar.js";
import { copyReleaseFile } from "../utils/copyReleaseFile.js";
import { addReleaseRecord } from "../utils/releaseRecord.js";
import {
releaseFiles,
CliError,
getImagePath,
getLegacyImagePath,
releaseFilesDefaultNames
} from "../params.js";
import { CliError } from "../params.js";
import { ListrContextBuildAndPublish } from "../types.js";
import { parseTimeout } from "../utils/timeout.js";
import { buildWithBuildx } from "./buildWithBuildx.js";
Expand Down Expand Up @@ -50,6 +44,12 @@ import {
writeManifest,
readSetupWizardIfExists
} from "../files/index.js";
import {
getImagePath,
getLegacyImagePath,
releaseFiles,
releaseFilesDefaultNames
} from "@dappnode/types";

// Pretty percent uploaded reporting
const percentToMessage = (percent: number) =>
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/createGithubRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
compactManifestIfCore,
composeDeleteBuildProperties
} from "../files/index.js";
import { contentHashFile, defaultDir } from "../params.js";
import { defaultDir } from "../params.js";
import {
TxData,
CliGlobalOptions,
ListrContextBuildAndPublish
} from "../types.js";
import { Github } from "../providers/github/Github.js";
import { contentHashFile } from "@dappnode/types";

/**
* Create (or edit) a Github release, then upload all assets
Expand Down
2 changes: 1 addition & 1 deletion src/utils/copyReleaseFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { releaseFilesDefaultNames } from "@dappnode/types";
import fs from "fs";
import path from "path";
import { releaseFilesDefaultNames } from "../params.js";

interface FileConfig {
regex: RegExp;
Expand Down
7 changes: 5 additions & 2 deletions test/params.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { expect } from "chai";
import { getImagePath, getLegacyImagePath } from "../src/params.js";
import { Architecture } from "@dappnode/types";
import {
Architecture,
getImagePath,
getLegacyImagePath
} from "@dappnode/types";

describe("params", () => {
const testCases: {
Expand Down
3 changes: 1 addition & 2 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from "fs";
import rimraf from "rimraf";
import { getImageTag } from "../src/params.js";
import { Compose, Manifest } from "@dappnode/types";
import { Compose, Manifest, getImageTag } from "@dappnode/types";

export const testDir = "test_files";
export function cleanTestDir(): void {
Expand Down