Question

Best practice for deployments to droplets

Posted March 23, 2021 188 views
NginxMongoDBUbuntuNode.jsGitPythonDockerUbuntu 16.04GitHub Actions

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.

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.

×
Submit an Answer
1 answer

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:

https://github.com/marketplace/actions/build-and-push-docker-images

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