dockposer v0.1.6
dockposer
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
Docker
andDocker composer
installed in your local/remote machine- 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?
- read config from
dockposer.host.json
- connect to remote server with ssh protocol
- run command
docker pull your_tag_name:1.2.0
in remote server - cd to
/home/test/my_app
and opendocker-compose.yaml
, updateyour_tag_name:<old_version>
toyour_tag_name:1.2.0
. - run command
docker-compose down && docker-compose up -d
in remote server to restart.
Contributors
Axetroy💻 🔌 ⚠️ 🐛 🎨 |
---|
License
The License