mirror of
https://github.com/logos-storage/codex-factory.git
synced 2026-01-02 13:03:07 +00:00
feat: external configuration (#89)
This commit is contained in:
parent
51f37f402f
commit
ddd764e668
12
README.md
12
README.md
@ -31,9 +31,12 @@ $ npm install -g @ethersphere/bee-factory
|
||||
## Usage
|
||||
|
||||
```shell
|
||||
# This spin up the cluster and exits
|
||||
# This spins up the cluster for specific Bee version and exits
|
||||
$ bee-factory start --detach 1.5.1
|
||||
|
||||
# The spins up the cluster using Bee version configured in external places. See bellow for options where to place it.
|
||||
$ bee-factory start --detach
|
||||
|
||||
# This attaches to the Queen container and displays its logs
|
||||
$ bee-factory logs queen --follow
|
||||
|
||||
@ -48,6 +51,13 @@ $ bee-factory start 1.5.1
|
||||
|
||||
For more details see the `--help` page of the CLI and its commands.
|
||||
|
||||
### External Bee version configuration
|
||||
|
||||
You can omit the Bee version argument when running `bee-factory start` command if you specify it in one of the expected places:
|
||||
|
||||
- `package.json` placed in current working directory (cwd) under the `engines.bee` property.
|
||||
- `.beefactory.json` placed in current working directory (cwd) with property `version`.
|
||||
|
||||
### Docker Images
|
||||
|
||||
Bee Factory as the NPM package that you can install, like mentioned above, works in a way that it orchestrates launching Bee Factory Docker images
|
||||
|
||||
@ -73,6 +73,7 @@
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0",
|
||||
"npm": ">=6.0.0"
|
||||
"npm": ">=6.0.0",
|
||||
"bee": "1.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
import { waitForBlockchain, waitForQueen, waitForWorkers } from '../utils/wait'
|
||||
import ora from 'ora'
|
||||
import { VerbosityLevel } from './root-command/logging'
|
||||
import { findBeeVersion } from '../utils/config-sources'
|
||||
|
||||
const DEFAULT_REPO = 'ethersphere'
|
||||
|
||||
@ -72,12 +73,18 @@ export class Start extends RootCommand implements LeafCommand {
|
||||
})
|
||||
public envPrefix!: string
|
||||
|
||||
@Argument({ key: 'bee-version', description: 'Bee image version', required: true })
|
||||
@Argument({ key: 'bee-version', description: 'Bee image version', required: false })
|
||||
public beeVersion!: string
|
||||
|
||||
public async run(): Promise<void> {
|
||||
await super.init()
|
||||
|
||||
if (!this.beeVersion) {
|
||||
this.beeVersion = await findBeeVersion()
|
||||
this.console.log('Bee version not specified. Found it configured externally.')
|
||||
this.console.log(`Spinning up cluster with Bee version ${this.beeVersion}.`)
|
||||
}
|
||||
|
||||
const dockerOptions = await this.buildDockerOptions()
|
||||
const docker = new Docker(this.console, this.envPrefix, this.imagePrefix, this.repo)
|
||||
const status = await docker.getAllStatus()
|
||||
|
||||
32
src/utils/config-sources.ts
Normal file
32
src/utils/config-sources.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { readFile } from 'fs/promises'
|
||||
import * as path from 'path'
|
||||
|
||||
async function searchPackageJson(): Promise<string | undefined> {
|
||||
const expectedPath = path.join(process.cwd(), 'package.json')
|
||||
const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' }))
|
||||
|
||||
return pkgJson?.engines?.bee
|
||||
}
|
||||
|
||||
async function searchBeeFactory(): Promise<string | undefined> {
|
||||
const expectedPath = path.join(process.cwd(), '.beefactory.json')
|
||||
const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' }))
|
||||
|
||||
return pkgJson?.version
|
||||
}
|
||||
|
||||
export async function findBeeVersion(): Promise<string> {
|
||||
const packageJson = await searchPackageJson()
|
||||
|
||||
if (packageJson) {
|
||||
return packageJson
|
||||
}
|
||||
|
||||
const beeFactory = await searchBeeFactory()
|
||||
|
||||
if (beeFactory) {
|
||||
return beeFactory
|
||||
}
|
||||
|
||||
throw new Error('Bee Version was not specified nor it is present in expected external places!')
|
||||
}
|
||||
@ -8,8 +8,6 @@ import { Bee, BeeDebug, Reference } from '@ethersphere/bee-js'
|
||||
import { DockerError } from '../../src/utils/docker'
|
||||
import { findContainer, waitForUsablePostageStamp } from '../utils/docker'
|
||||
|
||||
const BEE_VERSION = '1.5.1'
|
||||
|
||||
let testFailed = false
|
||||
|
||||
function wrapper(fn: () => Promise<unknown>): () => Promise<unknown> {
|
||||
@ -53,7 +51,7 @@ describe('start command', () => {
|
||||
'should start cluster',
|
||||
wrapper(async () => {
|
||||
// As spinning the cluster with --detach the command will exit once the cluster is up and running
|
||||
await run(['start', '--detach', BEE_VERSION])
|
||||
await run(['start', '--detach'])
|
||||
|
||||
await expect(findContainer(docker, 'queen')).resolves.toBeDefined()
|
||||
await expect(findContainer(docker, 'blockchain')).resolves.toBeDefined()
|
||||
@ -83,7 +81,7 @@ describe('start command', () => {
|
||||
it(
|
||||
'',
|
||||
wrapper(async () => {
|
||||
await run(['start', '--detach', BEE_VERSION])
|
||||
await run(['start', '--detach'])
|
||||
|
||||
expect(docker.getNetwork(`${envPrefix}-network`)).toBeDefined()
|
||||
}),
|
||||
@ -95,7 +93,7 @@ describe('start command', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
console.log('(before) Starting up Bee Factory')
|
||||
await run(['start', '--detach', BEE_VERSION])
|
||||
await run(['start', '--detach'])
|
||||
|
||||
console.log('(before) Creating postage stamp ')
|
||||
const postage = await beeDebug.createPostageBatch('10', 18)
|
||||
@ -116,7 +114,7 @@ describe('start command', () => {
|
||||
'',
|
||||
wrapper(async () => {
|
||||
console.log('(test) Starting the Bee Factory')
|
||||
await run(['start', '--fresh', '--detach', BEE_VERSION])
|
||||
await run(['start', '--fresh', '--detach'])
|
||||
|
||||
console.log('(test) Trying to fetch the data')
|
||||
await expect(bee.downloadData(reference)).rejects.toHaveProperty('status', 404)
|
||||
|
||||
@ -6,8 +6,6 @@ import { run } from '../utils/run'
|
||||
import { ENV_ENV_PREFIX_KEY } from '../../src/command/start'
|
||||
import { findContainer } from '../utils/docker'
|
||||
|
||||
const BEE_VERSION = '1.5.1'
|
||||
|
||||
describe('stop command', () => {
|
||||
let docker: Dockerode
|
||||
const envPrefix = `bee-factory-test-${crypto.randomBytes(4).toString('hex')}`
|
||||
@ -26,7 +24,7 @@ describe('stop command', () => {
|
||||
describe('should stop cluster', () => {
|
||||
beforeAll(async () => {
|
||||
// As spinning the cluster with --detach the command will exit once the cluster is up and running
|
||||
await run(['start', '--detach', BEE_VERSION])
|
||||
await run(['start', '--detach'])
|
||||
})
|
||||
|
||||
it('', async () => {
|
||||
@ -51,7 +49,7 @@ describe('stop command', () => {
|
||||
describe('should stop cluster and remove containers', () => {
|
||||
beforeAll(async () => {
|
||||
// As spinning the cluster with --detach the command will exit once the cluster is up and running
|
||||
await run(['start', '--detach', BEE_VERSION])
|
||||
await run(['start', '--detach'])
|
||||
})
|
||||
|
||||
it('', async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user