dockerpuller

1.0.1 • Public • Published

Dockerpuller

A tiny microservice/cli tool that will push/pull Docker images for you.


Build Status npm Vave Code Style

Why?

Let's say you need to deploy a Docker container to your staging machine after your CI tests are done. You might have a section in your .travis.yml (or other .yml) that has something like this:

after_success:
  - docker build -t me/my-container .
  - docker push me/my-conainer
  - ./scripts/deploy.sh

And then in your deploy.sh something like:

#!/bin/bash 
ssh deploy@$MY_SECRET_SERVER << EOF
docker stop my-killer-app
docker rm my-killer-app
docker rmi me/my-container:current
docker pull me/my-container:latest
docker tag me/my-container:latest me/my-container:current
docker run -d --restart always --name my-killer-app -p 3000:3000 me/my-container
EOF

And that sort of does the job, but every time you set up a new project you need to do a bunch of setup like SSH keys, putting that deploy.sh in the project, etc.

With Dockerpuller you can just put

"scripts"{
    "deploy": "dockerpuller --deploy"
}

And run npm run deploy instead of that deploy.sh script.

Awesome! How do I set it up?

Step 1.

Okay, first things first, install Dockerpuller globally on your Docker host:

npm install -g dockerpuller

Step 2.

After that, set the DOCKERPULLER_SECRET and optionally PORT environment variables and start Dockerpuller:

PORT=7777 DOCKERPULLER_SECRET="PorgsWereNotOverused12345" dockerpuller

To run it as a service, you can use PM2 or Forever.

Step 2.5.

Then in your CI create the DOCKERPULLER_SECRET environment variable and set it to the same value as on your Docker host.

Step 3.

Configure your project. Install Dockerpuller and add deploy script to your package.json:

npm install --save-dev dockerpuller
"scripts"{
    "deploy": "dockerpuller --deploy"
}

By default, Dockerpuller will read config from package.json, so let's also add that:

"scripts"{
    "deploy": "dockerpuller --deploy"
},
"config"{
    "dockerpuller": {
        "host": "http://mydockerhost.com:7777",
        "image": "me/my-container",
        "ports": "3000:3000",
        "name": "my-killer-app"
    }
}

If you don't want to add config field to your package.json, Dockerpuller also supports respective CLI options. Or CURL. Both will be explained in a bit.

NOTE: Dockerpuller will not create Dockerfile for you. Don't forget to have it in place.

Step 4.

Change your .travis.yml (or other .yml) to the following:

after_success:
  - docker build -t me/my-container .
  - docker push me/my-conainer
-  - ./scripts/deploy.sh
+  - npm run deploy

Step 4.25

By the way, you can have Dockerpuller build the container for you by adding a --build option. Let's do that:

package.json:

"scripts"{
    "deploy": "dockerpuller --build --deploy"
}

.travis.yml (or other .yml)

after_success:
-  - docker build -t me/my-container .
-  - docker push me/my-conainer
-  - ./scripts/deploy.sh
+  - npm run deploy

And you're done! Now just let the magic happen.

CLI Options

If you don't want to set config in package.json, Dockerpuller supports following CLI options:

  • -h, --host [host] - Config: Docker host URL
  • -n, --name [name] - Config: Docker container name
  • -p, --ports [ports] - Config: Port bindings (i.e. 80:3000)
  • --deploy - Run deployment
  • --build - Build an image before deploying

CURL usage

If you don't want to add Dockerpuller to your project's dependencies (no one wants another dependency), you can run your deployment by running a CURL command on your CI:

curl -X "POST" "http://mydockerhost:7777" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{ \
    "secret": "'"$DOCKERPULLER_SECRET"'", \
    "ports": "80:3000", \
    "container": "me/my-container", \
    "name": "my-killer-app" \
}'

And you're done!

Readme

Keywords

none

Package Sidebar

Install

npm i dockerpuller

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • fivepointseven