Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ksachdeva/node-docker-compose
Docker Compose API (not wrapper on python application) for NodeJS
https://github.com/ksachdeva/node-docker-compose
api docker docker-compose typescript
Last synced: 25 days ago
JSON representation
Docker Compose API (not wrapper on python application) for NodeJS
- Host: GitHub
- URL: https://github.com/ksachdeva/node-docker-compose
- Owner: ksachdeva
- License: apache-2.0
- Created: 2018-10-31T00:52:28.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T02:32:58.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T02:32:54.533Z (about 1 month ago)
- Topics: api, docker, docker-compose, typescript
- Language: TypeScript
- Size: 428 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker Compose API for NodeJS
**Note - This is work under progress and *at present* compliance with any of the docker-compose schema version is not targeted**
## Motivation
**Why node-docker-compose when there is a python version ?**
The short answer is that I have a (private) project written using Typescript that needed to orchestrate docker containers. Initially I tried to invoke the docker-compose (python app) using child-process however the error handling and progress monitoring was not to my satisfaction (read -> it was a mess and I hated it !).
You may now suggest - `Just use dockrode to do it`. Your suggestion is valid to some extent, however my application still required a spec (an input file) for what needs to be created (i.e. images, volumes, networks) and run (i.e. containers). Therefore, instead of re-inventing yet another input specification I decided to re-use docker-compose.yaml syntax.
That said, at present I am only implementing the constructs/features that I need for my private project and will slowly add the support for other aspects of docker-compose to reach a level of compliance with few (if not all) docker-compose schema versions.
If you think the project has merits please feel free to contribute !
## Installation
```bash
npm install node-docker-compose
```## Quick Start
```ts
import {Compose, Project} from 'node-docker-compose';// Tip: use dotenv to read the environment variables
// and merge them in environmentVariables
const environmentVariables = { MY_ENV_VAR1 : 'value' };// Create the project by passing the project config
const project = new Project({
pull : true, // Note - At present no impact
composeSpec : composeFilePath,
projectName : 'MyComposeProj',
environmentVariables: environmentVariables
});const compose = new Compose(project);
// systematically first bring the down the project
// to remove any containers
await compose.down();// bring up the project
await compose.up();// if using private registry such as Google Container registry
// pass the AuthConfig
//
// in below example, it will be used for pulling images that start with 'gcr.io'
await compose.up([{
username : 'oauth2accesstoken',
password : gcrToken,
serveraddress : 'gcr.io'
}]);```
## TODO
- [ ] Support skipping creation of containers that already exist for the same project
- [ ] Callbacks to inform the progress from higher level APIs (such as up and down)
- [ ] Support to remove the networks
- [ ] Config CLI command
- [ ] Specify the list of environment files (only .env in project directory is supported for now)
- [ ] If pull is false in ProjectConfig then do not fetch the latest image (if image is already present on the system)