Skip to content

Commit

Permalink
Fix: Download locally neo4j images, avoid deleting all the user conta…
Browse files Browse the repository at this point in the history
…iners

Download locally neo4j images that were not already downloaded, avoid deleting all the user
containers by searching the boltnet name. Also added a proper README file
  • Loading branch information
konsalex committed Jun 24, 2021
1 parent be5f0dd commit 7ec213a
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 13 deletions.
100 changes: 99 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,103 @@
<div style="width:100%;text-align:center" >
<img src="./assets/logo.png" style="margin-left:auto;width:50%;">
</div>

[![GitHub Action NPM Test & Release](https://github.com/konsalex/boltnet/actions/workflows/semantic-release.yml/badge.svg)](https://github.com/konsalex/boltnet/actions/workflows/semantic-release.yml)
![npm](https://img.shields.io/npm/v/boltnet?color=green)
![NPM](https://img.shields.io/npm/l/boltnet)

---

Boltnet Readme TBF
<!-- toc -->

- [🗒 Description](#-description)
- [🚀 Installing](#-installing)
- [🔨 Usage](#-usage)
- [📣 Feedback](#-feedback)
<!-- tocstop -->

# 🗒 Description

This is a unofficial NodeJS CLI for managing Neo4j Cluster with Docker. Behind the curtains [Dockerode](https://github.com/apocas/dockerode) is used to orchestrate all the necessary operations.

If you want to know more about Neo4j Clusters, please check [here](https://neo4j.com/docs/operations-manual/current/clustering/).

**Boltnet** is not intended for production usage, rather than for automated testing 🤖

# 🚀 Installing

To install this as a global package use the below command

```bash
# NPM
npm install -g boltnet
# Yarn
yarn global add boltnet
```

# 🔨 Usage

<!-- Usages -->

- [🔘 Create Cluster](#create-cluster)
- [✂️ Prune Networks](#prune-networks)
- [🏺 Detete Boltnet Containers](#detete-boltnet-containers)

<br/>

The best way to start using **boltnet** is to execute `boltnet --help`.

```
Usage: boltnet [options]
Options:
--version Show version number [boolean]
--prune [boolean] [default: false]
-x, --remove Removes all boltnet created container [boolean]
-c, --cluster Creates a neo4j cluster with a default of 3 Core members
[number] [default: 3]
-r, --read-replica Sets read replicas to the initial cluster
[number] [default: 0]
-u, --user-name Set username for the authentication
[string] [default: "neo4j"]
-p, --user-password Set password for the authentication
[string] [default: "newpassword"]
-i, --image [string] [default: "4.3-enterprise"]
-h, --help Show help [boolean]
```

Main functionalities include:

## Create Cluster

```bash
# Create a cluster with default settings
# 3 Core members, 0 Read replicas, Username/Password: neo4j/newpassword , Neo4j Image: 4.3-enterprise
boltnet -c

# Create a cluster with custom settings
# 4 Core members, 2 Read replicas, Username/Password: random/randompass , Neo4j Image: 4.0.1-enterprise
boltnet -c 4 -r 2 -u random -p randompass -i 4.0.1-enterprise
```

## Prune Networks

Every time a cluster is created, there is also a bridge network created for the cluster members to communicate with each other.

You can prune unused networks:

```bash
boltnet --prune
```

## Detete Boltnet Containers

To delete all running/created **boltnet** containers run:

```bash
boltnet --x
```

# 📣 Feedback

If you have any suggestions or want a more advanced feature on **boltnet**, feel free to open an issue.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 49 additions & 6 deletions src/dockerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,51 @@ class DockerManager {
}
}

/**
* Checks image local availability
* If image does not exist, downloads it
*/
public async checkImage() {
DockerManager.startSpinner('Checking image local availability');
try {
const images = await DockerManager.dockerDriver.listImages();
DockerManager.successSpinner();

if (!images.some(i => i.RepoTags.includes(this.imageName))) {
DockerManager.startSpinner('Downloading New image');

let downloading = true;

await DockerManager.dockerDriver.pull(
this.imageName,
(error: string | null, stream: NodeJS.ReadableStream) => {
if (error) DockerManager.fatalFail(error);

const onFinished = () => {
// Ended Download
downloading = false;
};
DockerManager.dockerDriver.modem.followProgress(stream, onFinished);
}
);

/** Check if download have finished every half a second */
while (true) {
if (!downloading) break;
await new Promise(resolve => setTimeout(resolve, 500));
}
DockerManager.successSpinner();
}
} catch (e) {
DockerManager.fatalFail(e);
}
}

/** Create and run containers */
public async runContainers() {
await this.pingDocker();

DockerManager.spinner.text = 'Starting Cluster Members';
DockerManager.spinner.start();
DockerManager.startSpinner('Starting Cluster Members');

/** Create Cluster members */
for (let i = 0, l = this.coreClusters + this.readReplicas; i < l; i += 1) {
Expand Down Expand Up @@ -166,10 +205,14 @@ class DockerManager {
host: this.basePorts,
},
});
const container = await DockerManager.dockerDriver.createContainer(
options
);
await container.start();
try {
const container = await DockerManager.dockerDriver.createContainer(
options
);
await container.start();
} catch (e) {
DockerManager.fatalFail(e);
}
}
DockerManager.spinner.succeed();
}
Expand Down
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ console.log(chalk.yellow(STARTUP_MESSAGE));

async function createCluster(manager: DockerManager) {
await manager.pingDocker();
await manager.checkImage();
await manager.createNetwork();
await manager.runContainers();
}
Expand Down Expand Up @@ -55,12 +56,6 @@ const argv = yargs(hideBin(process.argv))
type: 'string',
default: 'newpassword',
})
.option('', {
alias: 'user-name',
description: 'Set username for the authentication',
type: 'string',
default: 'newpassword',
})
.option('i', {
alias: 'image',
nargs: 1,
Expand Down

0 comments on commit 7ec213a

Please sign in to comment.