Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade script for the 2.1 release #1999

Merged
merged 53 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
502f12f
feat: setup upgrade script
faustbrian Jan 18, 2019
f437d89
feat: move directories
faustbrian Jan 18, 2019
4821dbc
fix: ensure that the new directory exists
faustbrian Jan 18, 2019
3469026
fix: only move if the old directory exists
faustbrian Jan 18, 2019
333535e
feat: delete pm2 processes
faustbrian Jan 18, 2019
1311927
chore: add pm2 as dev dependency
faustbrian Jan 18, 2019
027eb45
feat: remove old or temp files
faustbrian Jan 18, 2019
e6d8773
chore: change some file locations
faustbrian Jan 18, 2019
fe39b6b
feat: ensure that required files exist
faustbrian Jan 18, 2019
5f1c173
fix: delete files in old and new folders to avoid issues
faustbrian Jan 18, 2019
b592378
feat: validate configuration
faustbrian Jan 18, 2019
08e9926
fix: plugins config is javascript
faustbrian Jan 18, 2019
f8e1d10
fix: wrong var name
faustbrian Jan 18, 2019
2ed0981
feat: update the delegates configuration
faustbrian Jan 18, 2019
2360d2b
feat: update env and plugin config
faustbrian Jan 18, 2019
3fafe2f
chore: add upgrade command
faustbrian Jan 21, 2019
ca7b7b2
refactor: prompt the user for input to ask for install and config paths
faustbrian Jan 21, 2019
2844189
fix: expand home dir in case the user enters tilde
faustbrian Jan 21, 2019
33ad0d2
fix: ask the user for the network they operate on and copy the correc…
faustbrian Jan 21, 2019
3ac6bfe
misc: logs
faustbrian Jan 21, 2019
ca936b4
Merge branch 'develop' into upgrade
faustbrian Jan 22, 2019
720579d
fix: move database files to correct directories
faustbrian Jan 22, 2019
5937c5e
misc: adjust paths
faustbrian Jan 22, 2019
880e4b8
Merge branch 'develop' into upgrade
faustbrian Jan 22, 2019
bb735c0
fix: move files into folders with network prefixes
faustbrian Jan 22, 2019
16a5612
Merge remote-tracking branch 'origin/upgrade' into upgrade
faustbrian Jan 22, 2019
0f4032d
fix: remove peers_backup from config
faustbrian Jan 22, 2019
7769233
misc: log moving and copying
faustbrian Jan 22, 2019
0d89dd2
fix: only move database files if they exist
faustbrian Jan 22, 2019
3f8eab1
fix: make sure the .env file is copied first or we exit
faustbrian Jan 22, 2019
9abc52f
fix: clean up after all files have been verified
faustbrian Jan 22, 2019
fbcef07
refactor: handle pm2 via bash
faustbrian Jan 22, 2019
d8f5a21
fix: path and log
faustbrian Jan 22, 2019
dccab20
fix: null output
faustbrian Jan 22, 2019
d0d8e18
misc: more logging
faustbrian Jan 22, 2019
0e8d1f2
misc: logging
faustbrian Jan 22, 2019
3d0a564
misc: disable plugin mods
faustbrian Jan 22, 2019
4057b52
fix: copy genesisBlock.json
faustbrian Jan 22, 2019
0301fde
fix: json not js
faustbrian Jan 22, 2019
531c0bb
fix: remove env check
faustbrian Jan 22, 2019
ab5b55b
chore: add a script to create dummy files and folders
faustbrian Jan 22, 2019
b804bc7
fix: use the network name in the pool name
faustbrian Jan 22, 2019
c549434
misc: remove 2.2 task
faustbrian Jan 22, 2019
b1d835a
fix: move log files up from sub directory
faustbrian Jan 23, 2019
090b09d
Merge branch 'develop' into upgrade
faustbrian Jan 23, 2019
6698a3a
feat: update the commander configuration if it exists
faustbrian Jan 23, 2019
2b7b0df
fix: update CORE_DIR variable in commander env
faustbrian Jan 23, 2019
76fdfa7
fix: run yarn setup after the upgrade
faustbrian Jan 23, 2019
51b37db
fix: use platform specific line break
faustbrian Jan 23, 2019
ca03c3a
Merge branch 'develop' into upgrade
faustbrian Jan 23, 2019
8583201
Update package.json
faustbrian Jan 23, 2019
f4419f2
docs: update paths in upgrade.md
faustbrian Jan 23, 2019
001c5da
Merge remote-tracking branch 'origin/upgrade' into upgrade
faustbrian Jan 23, 2019
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
16 changes: 8 additions & 8 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Upgrading Instructions for Core 2.0
# Upgrading Instructions for Core 2.\*

This file contains the upgrade notes for Core 2.0. These notes highlight changes that
This file contains the upgrade notes for Core 2.\*. These notes highlight changes that
could break your application when you upgrade Core from one version to another.
Even though we try to ensure backwards compatibility (BC) as much as possible, sometimes
it is not possible or very complicated to avoid it and still create a good solution to
Expand All @@ -11,7 +11,7 @@ running `git pull` inside the installation directory. In a big application howev
be more things to consider, which are explained in the following.

> Note: This document assumes you have Core installed inside the `~/core` directory
> with your configuration being located at `~/.core/config`. If you are using different locations
> with your configuration being located at `~/.config/ark-core/<network>`. If you are using different locations
> you will need to adjust those inside the examples which can be found below.

> Tip: Upgrading a complex software project always comes at the risk of breaking something, so make sure you have a backup **(you should be doing this anyway)**.
Expand Down Expand Up @@ -43,7 +43,7 @@ Another way to upgrade is to change to a specific version, for example to versio
cd ~/core
git reset --hard
git fetch && git pull
git checkout tags/2.0.10
git checkout tags/2.1.0
yarn setup

### Notes
Expand All @@ -64,13 +64,13 @@ See the following notes on which changes to consider when upgrading from one ver

### Upgrade from Core 2.0.\* to 2.1.0

- Remove `"@arkecosystem/core-config": {},` from the `~/.core/config/plugins.js` file.
- Run `yarn run upgrade` from the root of the repository.

- Rename `@arkecosystem/core-transaction-pool-mem` to `@arkecosystem/core-transaction-pool` in the `~/.core/config/plugins.js` file.
- Remove `"@arkecosystem/core-config": {},` from the `~/.config/ark-core/<network>/plugins.js` file.

- Remove the `~/.core/config/network.json` file.
- Rename `@arkecosystem/core-transaction-pool-mem` to `@arkecosystem/core-transaction-pool` in the `~/.config/ark-core/<network>/plugins.js` file.

- If you have been using custom dynamic fees open the `~/.core/config/plugins.js` file and locate the `@arkecosystem/core-transaction-pool` plugin. Add below code to it and enter your desired values.
- If you have been using custom dynamic fees open the `~/.config/ark-core/<network>/plugins.js` file and locate the `@arkecosystem/core-transaction-pool` plugin. Add below code to it and enter your desired values.

```js
dynamicFees: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"test": "cross-env CORE_ENV=test jest --runInBand --forceExit",
"test:coverage": "cross-env CORE_ENV=test jest --coverage --coveragePathIgnorePatterns='/(defaults.ts|index.ts)$' --runInBand --forceExit",
"snyk": "./node_modules/.bin/snyk protect",
"upgrade": "cross-env-shell ./scripts/upgrade.sh",
"version": "cross-env-shell ./scripts/version.sh",
"release": "cross-env-shell ./scripts/release.sh",
"updates": "yarn lerna run updates",
"generateDocker": "node ./scripts/docker/generate-docker.js",
"docker": "node ./scripts/docker/generate-docker.js",
"bench": "node benchmark/index.js"
},
"devDependencies": {
Expand Down Expand Up @@ -55,6 +56,7 @@
"lint-staged": "^8.1.0",
"npm-check-updates": "^2.15.0",
"prettier": "^1.15.3",
"prompts": "^2.0.1",
"regenerator-runtime": "^0.13.1",
"request-promise": "^4.2.2",
"rimraf": "^2.6.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-container/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Environment {
return;
}

const envPath = expandHomeDir(`${process.env.CORE_PATH_DATA}/.env`);
const envPath = expandHomeDir(`${process.env.CORE_PATH_CONFIG}/.env`);

if (existsSync(envPath)) {
const env = require("envfile").parseFileSync(envPath);
Expand Down
2 changes: 1 addition & 1 deletion packages/core-json-rpc/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const defaults = {
allowRemote: false,
whitelist: ["127.0.0.1", "::ffff:127.0.0.1"],
database: {
uri: process.env.CORE_JSON_RPC_DATABASE || `sqlite://${process.env.CORE_PATH_DATA}/database/json-rpc.sqlite`,
uri: process.env.CORE_JSON_RPC_DATABASE || `sqlite://${process.env.CORE_PATH_DATA}/json-rpc.sqlite`,
options: {},
},
};
2 changes: 1 addition & 1 deletion packages/core-transaction-pool/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const defaults = {
enabled: !process.env.CORE_TRANSACTION_POOL_DISABLED,
syncInterval: 512,
storage: `${process.env.CORE_PATH_CACHE}/transaction-pool.sqlite`,
storage: `${process.env.CORE_PATH_DATA}/transaction-pool.sqlite`,
// When the pool contains that many transactions, then a new transaction is
// only accepted if its fee is higher than the transaction with the lowest
// fee in the pool. In this case the transaction with the lowest fee is removed
Expand Down
2 changes: 1 addition & 1 deletion packages/core-webhooks/__tests__/__support__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function setUp() {

await database.setUp({
dialect: "sqlite",
storage: `${process.env.CORE_PATH_DATA}/database/webhooks.sqlite`,
storage: `${process.env.CORE_PATH_DATA}/webhooks.sqlite`,
logging: process.env.CORE_DB_LOGGING,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core-webhooks/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const defaults = {
enabled: process.env.CORE_WEBHOOKS_ENABLED,
database: {
dialect: "sqlite",
storage: `${process.env.CORE_PATH_DATA}/database/webhooks.sqlite`,
storage: `${process.env.CORE_PATH_DATA}/webhooks.sqlite`,
logging: process.env.CORE_DB_LOGGING,
},
server: {
Expand Down
13 changes: 13 additions & 0 deletions scripts/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

pm2 stop ark-core > /dev/null 2>&1
pm2 stop ark-core-relay > /dev/null 2>&1
pm2 stop ark-core-forger > /dev/null 2>&1

pm2 stop core > /dev/null 2>&1
pm2 stop core-relay > /dev/null 2>&1
pm2 stop core-forger > /dev/null 2>&1

node ./scripts/upgrade/upgrade.js

yarn setup
18 changes: 18 additions & 0 deletions scripts/upgrade/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

rm -rf /home/ark/ark-core
git clone https://github.com/ArkEcosystem/core -b upgrade /home/ark/ark-core

mkdir /home/ark/.ark
touch /home/ark/.ark/.env

mkdir /home/ark/.ark/config

mkdir /home/ark/.ark/database
touch /home/ark/.ark/database/json-rpc.sqlite
touch /home/ark/.ark/database/transaction-pool.sqlite
touch /home/ark/.ark/database/webhooks.sqlite

mkdir /home/ark/.ark/logs
mkdir /home/ark/.ark/logs/mainnet
touch /home/ark/.ark/logs/mainnet/test.log
225 changes: 225 additions & 0 deletions scripts/upgrade/upgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
const envPaths = require('env-paths');
const expandHomeDir = require('expand-home-dir');
const fs = require('fs-extra');
const Joi = require('joi');
const prompts = require('prompts');
const { EOL } = require('os');

const main = async () => {
const {
corePath,
coreData,
coreNetwork
} = await prompts([{
type: 'text',
name: 'corePath',
initial: expandHomeDir('~/ark-core'),
message: 'Where is the installation located at?',
validate: value => fs.existsSync(value) ? true : `${value} does not exist.`
}, {
type: 'text',
name: 'coreData',
initial: expandHomeDir('~/.ark'),
message: 'Where is the configuration located at?',
validate: value => fs.existsSync(value) ? true : `${value} does not exist.`
}, {
type: 'select',
name: 'coreNetwork',
message: 'What network are you on?',
validate: value => ['mainnet', 'devnet', 'testnet'].includes(value) ? true : `${value} is not a valid network.`,
choices: [
{ title: 'mainnet', value: 'mainnet' },
{ title: 'devnet', value: 'devnet' },
{ title: 'testnet', value: 'testnet' }
],
}]);

// Paths
const corePaths = envPaths('ark', {
suffix: 'core'
});

const paths = {
core: {
old: expandHomeDir(corePath),
new: expandHomeDir('~/core'),
},
cache: {
old: expandHomeDir(`${coreData}/database`),
new: `${corePaths.cache}/${coreNetwork}`,
},
config: {
old: expandHomeDir(`${coreData}/config`),
new: `${corePaths.config}/${coreNetwork}`,
},
log: {
old: expandHomeDir(`${coreData}/logs`),
new: `${corePaths.log}/${coreNetwork}`,
},
temp: {
old: expandHomeDir(`${coreData}/temp`),
new: `${corePaths.temp}/${coreNetwork}`,
},
data: {
old: expandHomeDir(coreData),
new: `${corePaths.data}/${coreNetwork}`,
},
};

// update commander file if present
const commanderEnv = expandHomeDir('~/.commander')

if (fs.existsSync(commanderEnv)) {
const commanderContents = fs.readFileSync(commanderEnv).toString();

if (!commanderContents.includes('CORE_PATH_DATA')) {
fs.appendFileSync(commanderEnv, `CORE_PATH_DATA=${paths.data.new}${EOL}`);
}

if (!commanderContents.includes('CORE_PATH_CONFIG')) {
fs.appendFileSync(commanderEnv, `CORE_PATH_CONFIG=${paths.config.new}${EOL}`);
}

if (!commanderContents.includes('CORE_PATH_CACHE')) {
fs.appendFileSync(commanderEnv, `CORE_PATH_CACHE=${paths.cache.new}${EOL}`);
}

if (!commanderContents.includes('CORE_PATH_LOG')) {
fs.appendFileSync(commanderEnv, `CORE_PATH_LOG=${paths.log.new}${EOL}`);
}

if (!commanderContents.includes('CORE_PATH_TEMP')) {
fs.appendFileSync(commanderEnv, `CORE_PATH_TEMP=${paths.temp.new}${EOL}`);
}

const env = require("envfile").parseFileSync(commanderEnv);
env.CORE_DIR = env.CORE_DIR.replace('ark-core', 'core');

let envOutput = '';
for(const [key, value] of Object.entries(env)) {
envOutput += `${key}=${value}${EOL}`;
}

fs.writeFileSync(commanderEnv, envOutput);
}

// Create directories
for (const value of Object.values(paths)) {
fs.ensureDirSync(value.new);
}

// Ensure we copy the .env file
if (!fs.existsSync(`${paths.data.old}/.env`)) {
console.log(`The ${paths.data.old}/.env file does not exist.`)
process.exit(1);
}

const envCurrent = fs.readFileSync(`${paths.data.old}/.env`).toString();

// Move files & directories
for (const value of Object.values(paths)) {
if (fs.existsSync(value.old)) {
console.error(`Moving ${value.old} to ${value.new}.`);

fs.moveSync(value.old, value.new, {
overwrite: true
});
} else {
console.error(`Folder ${value.old} does not exist.`);
}
}

// Move files
if (fs.existsSync(`${paths.cache.new}/json-rpc.sqlite`)) {
fs.moveSync(`${paths.cache.new}/json-rpc.sqlite`, `${paths.data.new}/json-rpc.sqlite`);
}

if (fs.existsSync(`${paths.cache.new}/transaction-pool-${coreNetwork}.sqlite`)) {
fs.moveSync(`${paths.cache.new}/transaction-pool-${coreNetwork}.sqlite`, `${paths.data.new}/transaction-pool.sqlite`);
}

if (fs.existsSync(`${paths.cache.new}/webhooks.sqlite`)) {
fs.moveSync(`${paths.cache.new}/webhooks.sqlite`, `${paths.data.new}/webhooks.sqlite`);
}

if (fs.existsSync(`${corePaths.log}/core/${coreNetwork}`)) {
fs.moveSync(`${corePaths.log}/core/${coreNetwork}`, `${paths.log.new}/${coreNetwork}`);
}

// Remove old or temp files
fs.removeSync(`${paths.config.old}/peers_backup.json`);
fs.removeSync(`${paths.config.old}/network.json`);
fs.removeSync(`${paths.config.new}/peers_backup.json`);
fs.removeSync(`${paths.config.new}/network.json`);

// Ensure that all files core needs exist
const requiredFiles = [
{
copy: `${paths.config.new}/delegates.json`,
original: `${paths.core.new}/packages/core/src/config/${coreNetwork}/delegates.json`,
}, {
copy: `${paths.config.new}/peers.json`,
original: `${paths.core.new}/packages/core/src/config/${coreNetwork}/peers.json`,
}, {
copy: `${paths.config.new}/plugins.js`,
original: `${paths.core.new}/packages/core/src/config/${coreNetwork}/plugins.js`,
}, {
copy: `${paths.config.new}/genesisBlock.json`,
original: `${paths.core.new}/packages/core/src/config/${coreNetwork}/genesisBlock.json`,
}
];

for (const file of requiredFiles) {
if (!fs.existsSync(file.copy)) {
if (fs.existsSync(file.original)) {
console.error(`Copying ${file.original} to ${file.copy} because it is missing.`);

fs.copySync(file.original, file.copy);
} else {
console.error(`Original ${file.original} does not exist.`);
}
}
}

// Update delegate configuration
console.log('Update delegate configuration');
let configDelegates = require(`${paths.config.new}/delegates.json`)
delete configDelegates.dynamicFee
delete configDelegates.dynamicFees
fs.writeFileSync(`${paths.config.new}/delegates.json`, JSON.stringify(configDelegates, null, 4));

// Update environment file
console.log('Update environment configuration');
fs.writeFileSync(`${paths.config.new}/.env`, envCurrent.replace('ARK_', 'CORE_'));

// Validate configuration files
console.log('Validating configuration');
const { error } = Joi.validate({
delegates: require(`${paths.config.new}/delegates.json`),
peers: require(`${paths.config.new}/peers.json`),
plugins: require(`${paths.config.new}/plugins.js`),
genesisBlock: require(`${paths.config.new}/genesisBlock.json`),
}, Joi.object({
delegates: Joi.object({
secrets: Joi.array().items(Joi.string()),
bip38: Joi.string(),
}),
peers: Joi.object().required(),
plugins: Joi.object().required(),
genesisBlock: Joi.object().required(),
}).unknown());

if (error) {
console.log(error);
}

// Clean up
console.log('Performing clean up');
for (const value of Object.values(paths)) {
if (fs.existsSync(value.old)) {
fs.removeSync(value.old);
}
}
}

main()
Loading