0.1.6 • Published 4 years ago

dockposer v0.1.6

Weekly downloads
23
License
Apache 2.0
Repository
github
Last release
4 years ago

dockposer

Node DeepScan grade npm version Size

docker-compose extra tool for easy deployment.

Feature

  • Build docker image
  • Push docker image to registry
  • Deploy docker-compose to remote server
  • No need to install on the server side

Requirement

Before you start using this tool, you need to make sure that you meet the conditions

  1. Docker and Docker composer installed in your local/remote machine
  2. remote machine only support Linux/Unix system

Quickly start

# install in your local machine
npm install dockposer -g

add scripts for package.json

{
  ...
  "scripts": {
    ...
+   "build": "dockposer build your_tag_name:{NPM_PACKAGE_VERSION}",
+   "push": "dockposer push your_tag_name:{NPM_PACKAGE_VERSION}",
+   "deploy": "dockposer deploy your_tag_name:{NPM_PACKAGE_VERSION}"
  }
}

run command to easy deploy

npm run build
npm run push
npm run deploy

dockposer build

Like Docker build. But it supports custom variables

For example, in an Npm project, we usually need to migrate the version like this, and then package the Docker image.

## Client Side ##

# migrate npm version to 1.2.0
npm version 1.2.0
# build image for version 1.2.0
docker build --tag your_tag_name:1.2.0 # Here, we need to specify the version to be 1.2.0
# push image to registry
docker push your_tag_name:1.2.0 # specify the version again

## Server Side ##

# pull docker image
docker pull your_tag_name:1.2.0

# open docker-compose.yml and update your_tag_name:<old_version> to your_tag_name:1.2.0.
vi docker-compose.yml

# restart serve
docker-compose down && docker-compose up -d

I can simplify the above steps with dockposer.

npm version 1.2.0
# when found `NPM_PACKAGE_VERSION`. it will read the version field from `package.json`
dockposer build your_tag_name:{NPM_PACKAGE_VERSION}
dockposer push your_tag_name:{NPM_PACKAGE_VERSION}

dockposer push

Like Docker push. But it supports custom variables

dockposer push your_tag_name:{NPM_PACKAGE_VERSION}

dockposer deploy

deploy the image on remote server with docker-compose.

First we have to know which server to deploy to.

The default configuration file dockposer.host.json is stored in the current working directory.

It has the following fields

export interface Host {
  name?: string; // alias name for the server
  path: string; // where is your `docker-compose.yml` in remote server
  host: string; // host address
  port: number; // SSH port
  username: string; // username for the server
  password: string; // password for the server
}

eg. ${cwd}/dockposer.host.json

{
  "name": "test server",
  "path": "/home/test/my_app",
  "host": "192.168.0.1",
  "port": 22,
  "username": "root",
  "password": "root"
}

Then we run the deployment command. Let's see how it work.

dockposer deploy your_tag_name:1.2.0

What did it do?

  1. read config from dockposer.host.json
  2. connect to remote server with ssh protocol
  3. run command docker pull your_tag_name:1.2.0 in remote server
  4. cd to /home/test/my_app and open docker-compose.yaml, update your_tag_name:<old_version> to your_tag_name:1.2.0.
  5. run command docker-compose down && docker-compose up -d in remote server to restart.

Contributors

Axetroy💻 🔌 ⚠️ 🐛 🎨

License

The License

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago