Best practice for deployments to droplets

Hi guys,

I would like some advice on ‘best practice’ for deploying projects to a DigitalOcean Droplet.

I have a number of hobby projects that are compiled with Docker, either webpages built with Node.js or python API’s. My usually process is:

  1. to clone the git repository to my Droplet
  2. run ‘docker-compose up -d’
  3. when I push changes to my repository, repeat the commands:
    1. git pull
    2. docker-compose up --build -d

I have recently automated step 3 with GitHub workflows.

The process has served me well without complaints when projects are small but I am now becoming more space conscious - my git repositories often include files that aren’t necessary for deployment.

So my question is: what is the best practice method for deploying projects compiled with Docker?

Some of my thoughts are:

  • create a ‘deployment’ branch in my git repository that only contains the necessary deployment files. Although I don’t know how this would stay maintained with pull requests.
  • pre-compile Docker containers and store them on Docker-Hub. Therefore only pulling and running containers to my Droplet, and not full repositories. I don’t know if Docker-Hub works in this way.
  • does GitLab provide any services to help with this?

Am I going about this the right way? Any advise would be appreciated.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

Yes, indeed you are definitely going in the right direction.

What I would usually do in this case is, as you said, have the Docker images ready and just pull them, rather than building the images each time on your Droplet.

As you are already using GitHub, what you could do is to use GitHub actions to do that.

Actually there is already one available on the GitHub Marketplace which I believe will serve you well:

That way you will have your images ready and you will only need to pull them and run them.

Hope that this helps! Regards, Bobby