Skip to content

Commit 08cbfe7

Browse files
committed
Merge branch 'develop', prepare 6.2.0
2 parents b144d0a + ba9d4ae commit 08cbfe7

File tree

7 files changed

+128
-2
lines changed

7 files changed

+128
-2
lines changed

.github/workflows/prerelease.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ jobs:
6262
- name: package
6363
run: yarn package
6464

65+
# bump version & commit it
66+
- run: npm version prerelease --preid=dev --no-git-tag-version
67+
- name: setup git
68+
run: |
69+
git config user.email "[email protected]"
70+
git config user.name "$GITHUB_ACTOR"
71+
- name: commit new version to develop
72+
run: |
73+
git add -A
74+
git commit -m "Bump version for @next release"
75+
git push "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY"
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6578
# deploy to npm
6679
- run: npm publish --access public --tag next
6780
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> Simple Docker deployment tool
44
5-
[![Build Status](https://travis-ci.org/exoframejs/exoframe.svg?branch=master)](https://travis-ci.org/exoframejs/exoframe)
5+
[![Test Status](https://github.com/exoframejs/exoframe/workflows/Test/badge.svg)](https://github.com/exoframejs/exoframe/actions?query=workflow%3ATest)
66
[![Coverage Status](https://coveralls.io/repos/github/exoframejs/exoframe/badge.svg?branch=master)](https://coveralls.io/github/exoframejs/exoframe?branch=master)
77
[![npm](https://img.shields.io/npm/v/exoframe.svg)](https://www.npmjs.com/package/exoframe)
88
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://opensource.org/licenses/MIT)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "exoframe",
3-
"version": "6.1.4",
3+
"version": "6.1.5-dev.3",
44
"description": "Exoframe is a self-hosted tool that allows simple one-command deployments using Docker",
55
"main": "dist/index.js",
66
"repository": "[email protected]:exoframejs/exoframe.git",
@@ -51,6 +51,7 @@
5151
"ora": "^4.0.2",
5252
"pkg": "^4.4.0",
5353
"prettier": "^2.0.4",
54+
"pretty-bytes": "^5.3.0",
5455
"semver-diff": "^3.1.1",
5556
"sinon": "^9.0.2",
5657
"tar-fs": "^2.0.0",

src/commands/system.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// npm packages
2+
const got = require('got');
3+
const chalk = require('chalk');
4+
const prettyBytes = require('pretty-bytes');
5+
6+
// our packages
7+
const {userConfig, isLoggedIn, logout} = require('../config');
8+
9+
exports.command = ['system [cmd]'];
10+
exports.describe = 'execute system commands (prune to remove unused data)';
11+
exports.builder = {
12+
cmd: {
13+
default: '',
14+
description: 'command to execute [prune]',
15+
},
16+
};
17+
exports.handler = async args => {
18+
if (!isLoggedIn()) {
19+
return;
20+
}
21+
22+
// get command
23+
const {cmd} = args;
24+
25+
if (cmd !== 'prune') {
26+
console.log('Only "prune" command is currently supported!');
27+
return;
28+
}
29+
30+
// services request url
31+
const remoteUrl = `${userConfig.endpoint}/system/prune`;
32+
33+
// construct shared request params
34+
const options = {
35+
method: 'POST',
36+
headers: {
37+
Authorization: `Bearer ${userConfig.token}`,
38+
},
39+
responseType: 'json',
40+
json: {},
41+
};
42+
// try sending request
43+
try {
44+
const {body} = await got(remoteUrl, options);
45+
console.log(chalk.bold('Data prune successful!'));
46+
console.log('');
47+
console.log(
48+
chalk.bold('Reclaimed:'),
49+
prettyBytes(body.data.map(item => item.SpaceReclaimed).reduce((acc, val) => acc + val, 0))
50+
);
51+
} catch (e) {
52+
// if authorization is expired/broken/etc
53+
if (e.response.statusCode === 401) {
54+
logout(userConfig);
55+
console.log(chalk.red('Error: authorization expired!'), 'Please, relogin and try again.');
56+
return;
57+
}
58+
59+
console.log(chalk.red(`Error executing ${cmd} command:`), e.toString());
60+
console.error(e);
61+
}
62+
};

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const template = require('./commands/template');
2626
const setup = require('./commands/setup');
2727
const secrets = require('./commands/secrets');
2828
const completion = require('./commands/completion');
29+
const system = require('./commands/system');
2930

3031
// init program
3132
yargs
@@ -45,4 +46,5 @@ yargs
4546
.command(template)
4647
.command(setup)
4748
.command(secrets)
49+
.command(system)
4850
.command(completion(yargs)).argv;

test/__snapshots__/prune.test.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Should execute prune 1`] = `
4+
Array [
5+
Array [
6+
"Data prune successful!",
7+
],
8+
Array [
9+
"",
10+
],
11+
Array [
12+
"Reclaimed:",
13+
"1.02 kB",
14+
],
15+
]
16+
`;

test/prune.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-env jest */
2+
// mock config for testing
3+
jest.mock('../src/config', () => require('./__mocks__/config'));
4+
5+
// npm packages
6+
const nock = require('nock');
7+
const sinon = require('sinon');
8+
9+
// our packages
10+
const {handler: system} = require('../src/commands/system');
11+
12+
// test update
13+
test('Should execute prune', done => {
14+
// handle correct request
15+
const pruneServer = nock('http://localhost:8080')
16+
.post('/system/prune')
17+
.reply(200, {pruned: true, data: [{SpaceReclaimed: 1024}]});
18+
// spy on console
19+
const consoleSpy = sinon.spy(console, 'log');
20+
// execute login
21+
system({cmd: 'prune'}).then(() => {
22+
// make sure log in was successful
23+
// check that server was called
24+
expect(pruneServer.isDone()).toBeTruthy();
25+
// first check console output
26+
expect(consoleSpy.args).toMatchSnapshot();
27+
// restore console
28+
console.log.restore();
29+
pruneServer.done();
30+
done();
31+
});
32+
});

0 commit comments

Comments
 (0)