6
35 Comments

Ask IH: How do you deploy?

Ask IH: How do you deploy?

So, dear IHers, how do you deploy your code?
I'm looking for a tool similar to Netlify, but for backend deployments.
I used to use Nanobox, but its engines are outdated.

I need a tool that can get Dockerfile / code for bitbucket and deploy to to my provider (DigitalOcean in my case) and that will handle database migrations / seeding as well as secrets (for creating the .env file).

Any suggestions?

Thanks!

on January 26, 2019
  1. 6

    I used to use Nanobox, too! Now I use Gitlab CI/CD.

    Every time I push code, gitlab builds my app in a container and runs the tests. If the push was to master, it also runs a script that deploys the code to my server (on Digital Ocean). Secrets can be saved in variables in the projects tab.

    I'm planning a tutorial on this process soon. BTW, the features above are completely free.

    1. 3

      Hey! Thank for the reply!
      Mind to share how you provision the servers and deploy your code?

      1. 3

        Of course! I'll make a youtube tutorial on it and upload it to my channel. That's what I do 😉

        1. 1

          Thank you, I am looking forward to the tutorial.
          I am already using digital ocean for some projects, but these are manually deployed.
          Now I want to set up automatic deployment of docker images / containers to digital ocean.

  2. 3
    1. Write ansible playbook to provision the machine
    2. Make sure your have the dockerfile ready
    3. Use CI/CD tools. I use opensource Jenkins and whenever a change is merged . run the job that will do the CI and CD
    1. 1

      Thanks!
      Right now planning on running terraform to provision the infra, GitLab CI for migrations as well as docker building and ansible for pulling the image and running it on the server.

  3. 3

    I have for all my early to mid level projects used bash scripts to deploy to the environments / stages. In the bash scripts it will even perform the ssh into my digital ocean instances and perform the changes. I pass arguments to the script. I use git for my code so the bash scripts pulls from the correct repository and branch I have deemed it to have. I have found docker to be nice optimization for larger code deploys over multiple instances but a waste of time/effort for a startup that should be focused on lean setups. Perhaps practice a few command line deploys to a box and then replicate that to a bash script and you’ll find its pretty straight forward.

    1. 1

      Thank you for the reply!
      Mind to share what exactly your script is doing?

      1. 2

        Here is a ruby on rails app deploy script for when I just need to update the app - as an example. I write different ones per app, per what I'm trying to accomplish. This script was edited over time to meet my needs.

        #!/bin/bash -o xtrace
        trap 'echo "# $BASH_COMMAND"' DEBUG

        # THIS FUNCTION UPDATES THE SERVICE WORKER VERSION SO CACHE REFRESHES. I USED A SERVICE WORKER "TEMPLATE" THAT HAS A VARIABLE TO REPLACE
        replaceSWTag() {
        thistime=$(date +%s%N)
        local search="{{swtime}}"
        echo "RUNNING"
        sed "s/{{swtime}}/$thistime/g" sw_tmpl.js > sw.js
        }

        # THIS FUNCTION ZIPS UP ONE OF THE FOLDERS IN THE APP
        zipApp () {
        tar -zcvf MYAPP.tar.gz app
        }

        # RUN 1ST FUNCTION
        replaceSWTag
        # RUN 2ND FUNCTION
        zipApp

        # WAIT FOR BOTH FUNCTIONS TO COMPLETE
        wait

        # SEND VIA SECURE COPY MY APP'S TAR GZ APP
        sshpass -p "MYSERVERPASSWORD" scp MYAPP.tar.gz [email protected]:/home/SERVERUSER/public/appfolder/

        # SEND VIA SECURE COPY MY APP'S SERVICE WORKER FILE
        sshpass -p "MYSERVERPASSWORD" scp sw.js [email protected]:/home/SERVERUSER/public/appfolder/public/

        # LOG INTO MY SERVER VIA SSH AND PERFORM THE SERVER SIDE UPDATES
        sshpass -p "MYSERVERPASSWORD" ssh [email protected] << 'ENDSSH'
        # CHANGE DIRECTORY TO WHERE APP IS HELD
        cd /home/SERVERUSER/public_html/APPFOLDER/
        # BACKUP THE OLD FOLDER FIRST
        tar -zcvf "app_$(date '+%Y-%m-%d-%H_%M_%S').tar.gz" app;
        # UNTAR MY NEW APP VERSION
        tar -xvzf MYAPP.tar.gz;
        # REMOVE OLD FILES FROM LAST APP VERSION OF THE ASSET DIRECTORY NOT USED
        bundle exec rake assets:clean RAILS_ENV=production
        # PRECOMPILE ON SERVER THE NEW ASSETS
        bundle exec rake assets:precompile RAILS_ENV=production & pid1=$!
        # TELL MY LOGS A MESSAGE
        echo "Child PID=$pid1 launched"
        # WAIT FOR ALL ABOVE TO COMPLEE
        wait $pid1
        # TELL MY LOGS THAT THE APP IS RESTARTING
        echo "RESTARTING NOW"
        # ACTUALLY RESTART THE PASSENNGER + RUBY ON RAILS APP TO RUN
        touch tmp/restart.txt;
        ENDSSH

  4. 3

    Capistrano, not sure what I would do without it.

    My app is written in Ruby on Rails, but I just read online that Capistrano can also be used for applications written in other languages.

    1. 1

      Same. Write some code, push to git, cap production deploy.

    2. 1

      Thank you for your reply!
      I know Capistrano but used to use Ansible.
      Do you mind to share your exact flow? What do you deploy: docker or code? How you provision servers?

      1. 2

        It deploys code from the repo, does migrations, assets compilations and sym linking. For provisioning servers, I use Chef.

        I will give you a more detailed answer tomorrow as I have very limited internet access for today.

    3. 1

      Capistrano/Ansible is a great way to do it, and they're also pretty easy to setup with standard CI/CD tools.

  5. 2

    https://lexico.io is running on Azure DevOps, which is pretty idiot-proof - great for someone with little DevOps experience.

    Inside the .NET ecosystem, it works pretty flawlessly - trigger on commit/merge, automated testing and push to production.

    Much nicer than my earlier days using git triggers/scp/etc.

    I can't say how well it would work outside the .NET ecosystem, so YMMV.

  6. 1

    It depends whether you prefer a high-level, click-a-button kind of tool where the details are hidden away; or a lower-level one where you can tweak it exactly the way you want.

    For the latter I like git-deploy.

  7. 1

    Great question!

    I did various things for my side projects, but my side projects were never in need of a complicated deployment so I kept it simple.

    For my personal web and WordPress blog I use regional hosting (cheap) that comes with one click WP install and FTP access for simple static websites. I also started to use Netlify for a pure static web.

    For Ruby applications I was running OpenShift Online v2 (more like Heroku, current OpenShift is a Kubernetes distribution), Heroku and my own VPS on various providers. Right now I just run VPS in Digital Ocean with pure Bash scripts.

    I automated the provisioning and git-push setup so everything is pretty nice to maintain. I am also writing a book right now about it called "VPS for Makers". You can check it out: https://vpsformakers.com/. Except for required theory I will mention specifics for Python, Ruby, PostgreSQL, Redis on Fedora/CentOS.

    I would say go with your own VPS only if you actually want to understand details and fiddle with permissions, AppArmor/SELinux, firewalls, etc... otherwise manage platform does the job most likely better.

  8. 1

    In case anyone interested:
    I decided to switch to GitLab with its awesome CI/CD.
    Build Docker image using GitLab CI/CD, store it in GitLab Registry, provision infra with Terraform and copy and execute docker image with Ansible.
    I'm excited!

  9. 1

    I use Kubernetes in Google Cloud.

    DigitalOcean also have kubernetes support now, if you feel like learning a cutting edge technology I definitely recommend going with Kubernetes.

    Database migrations ect, can be handled in the code. Here is an example of how I usually do it in Go: https://medium.com/storyteltech/a-mini-guide-build-a-rest-api-as-a-go-microservice-together-with-mysql-fc203a6411c0

    1. 1

      I tried to understand kubernetes, but I'm not sure what added value it has

      1. 1

        It's literally just images running in a cluster, and allows you to easily scale up the backend and a ton of other cool feature. Stuff that would require you to have an extreme amount of other tools installed otherwise. I would say that together with Cloud Functions it's the next big thing in backend infrastructure.

        Totally worth it to at least learn about :)

        1. 1

          Still not sure how its different from docker container.
          Also I assume it will cost more than a regular DO droplet that runs docker image

          1. 2

            A docker container is running an image. And it runs ON a server.

            A kubernetes pod can run one or many containers. Each pod is scheduled to a server. Meaning that kubernetes it's running the servers.

            With kubernetes you can easily scale up across multiple servers if needed, all while keeping everything within the same kubernetes cluster.

            It also offers tons of security layers, and allow you to easily do rollouts of new versions without disrupting the current running versions.

            Furthermore all except the actual docker image is kept in configuration files, meaning that you can spawn another service within seconds, providing you already have the image.

            1. 2

              Interesting! Thanks for the explanation!

              1. 2

                No worries :) Feel free to ask if you wonder anything more!

  10. 1

    Dokku is great (https://github.com/dokku/dokku). Just like heroku but absolutely free and you have full control over everything. SSL, zero-downtime deployments are a snap.

    1. 1

      Thank you, I've heard of Dokku. But managing my own servers (even though Dokku can be installed with one-click app on DO) sounds cumbersome

      1. 2

        To each his own I suppose. Managed systems are often are turn-off for me because they are restrictive and it's often difficult to see what's going on in case of problems. I find managing a naked Linux slice simpler, easier and way more cost-effective. Just as an example, running https://soccer.coachaide.com on a 2GB RAM VPS system costs me ~$3/month.

        1. 1

          What? $3 a month for a 2GB machine. Which cloud provider do you use?

          1. 1

            OVH (https://www.ovh.com/world/vps/vps-ssd.xml). I paid $3.15 for several months in advance. Looks like the current going price is $3.35/month but they've updated the specs as well a bit (10GB->20GB SSD).

  11. 1

    A buddy of mine developed Cleaver (https://getcleaver.com) which allows you to provision servers and deploy web-apps with just a few clicks - and it's free! 👍

    1. 1

      Thank you, looks interesting!

  12. 1

    Check out https://now.sh. Not great for databases, but it will build from your Dockerfile and deploy. Has an excellent way to handle secrets.

    1. 2

      Now has its own servers and suited more towards serverless rather than a full blown backend application.
      But thanks for the suggestion!

  13. 1

    This comment was deleted 6 years ago.

Trending on Indie Hackers
I spent $0 on marketing and got 1,200 website visitors - Here's my exact playbook User Avatar 50 comments Veo 3.1 vs Sora 2: AI Video Generation in 2025 🎬🤖 User Avatar 26 comments I built eSIMKitStore — helping travelers stay online with instant QR-based eSIMs 🌍 User Avatar 20 comments Codenhack Beta — Full Access + Referral User Avatar 20 comments 🚀 Get Your Brand Featured on FaceSeek User Avatar 18 comments Day 6 - Slow days as a solo founder User Avatar 15 comments