When developing dockerized applications, you might stumble upon the sheer difficulty and annoyance of simply deploying your Compose file along with built service images. If you're not using a full cloud setup and instead want to deploy to a small number of machines, you're left with doing it manually or going for complete automation. At least that was the case until now - I'm happy to introduce compose-deploy. As the name suggests, it is a simple CLI tool that helps you with defining and running your deployments with ease.
Let's go through an example deployment to grasp how easy it actually is to deploy a simple hello-world service to our server. Our Compose file looks like the following
version: '3.7'services:demo:build: .image: brunoscheufler/demo-service:1.0.0restart: on-failureinit: trueenvironment:NODE_ENV: production
and our compose-deploy configuration contains
name: sample-deploymenttargets:- host: 'my-server-ip'username: deploy-userprivateKeyFile: ./key/id_rsapassphrase: 'SECRET PASSPHRASE'composeFile: ./docker-compose.yml
Now we're ready to run the deployment!
$ compose-deploy🔨 Building Docker images...Building demoStep 1/4 : FROM node:11-alpine---> ebbf98230a82Step 2/4 : WORKDIR /app---> Using cache---> 311a77c5bbdaStep 3/4 : COPY index.js /app---> Using cache---> 994482d9b3d0Step 4/4 : CMD node index.js---> Using cache---> aa2745a3fd0cSuccessfully built aa2745a3fd0cSuccessfully tagged brunoscheufler/demo-service:1.0.0🌎 Pushing Docker images...Pushing demo (brunoscheufler/demo-service:1.0.0)...The push refers to repository [docker.io/brunoscheufler/demo-service]1.0.0: digest: sha256:<LONG_HASH> size: 1364🎯 Deploying services...💫 Deploying to target 1 of 1...📡 Connecting to target server🥁 Connected! Copying Compose file...Removing network sample_default📦 Pulling Docker images...Pulling demo ... done⚡️ Launching deployment...Creating network "sample_default" with the default driverCreating sample_demo_1 ... done✅ Deployment done!
And that's it! We've now deployed our demo service in less than thirty seconds. It works like magic ✨ If you're interested, head over to the repository and give it a try!