Dokploy: Streamlining Deployment On Hetzner VPS

Alex Johnson
-
Dokploy: Streamlining Deployment On Hetzner VPS

Introduction: The Need for an Efficient Deployment Workflow

Efficient deployment is crucial for any project's success. As developers, we constantly seek ways to streamline our workflow, reduce errors, and save valuable time. Currently, the deployment process involves various manual tasks, which can be time-consuming and prone to errors. This article provides a comprehensive plan for integrating Dokploy, a powerful deployment platform, into the existing Hetzner VPS infrastructure to solve these pain points. By embracing Dokploy, we aim to achieve a Vercel-like experience while retaining full control over our infrastructure.

The Challenges of Manual Deployment

Manual deployment processes are often characterized by several inefficiencies. One of the primary issues is the use of manual Docker commands, which can be error-prone and time-intensive. Moreover, the lack of a visual dashboard for monitoring essential metrics like CPU, memory, and network usage hinders effective performance analysis. In addition, managing environment variables across containers manually adds to the complexity. The absence of built-in backup automation for databases further increases the risk of data loss. Rollbacks become complex without proper image tracking, and the absence of tools for staging environment management limits flexibility.

Pain Points and the Current State

For a solo developer, infrastructure management without platform abstraction can be a significant challenge. The time spent on deployment mechanics often overshadows the time dedicated to feature development, which affects productivity. There's also the risk of configuration drift between local development and production environments, leading to inconsistencies. Furthermore, creating a staging environment when traffic grows requires additional effort. The current state involves deployments through shell scripts and manual Docker commands on a Hetzner VPS, highlighting the need for a more efficient system.

Proposed Solution: Integrating Dokploy

Overview of Dokploy

Dokploy presents itself as a self-hosted deployment platform that seeks to solve many of the above-mentioned problems. It's an open-source alternative to popular platforms like Vercel and Netlify. By integrating Dokploy, we can simplify the deployment process, improve monitoring capabilities, and automate essential tasks. Dokploy boasts a user-friendly web UI for application and database management, with support for various technologies such as Docker, Nixpacks, Heroku Buildpacks, and Docker Compose. It also has features such as monitoring (CPU, memory, and network), and database management for several databases like PostgreSQL, MySQL, MongoDB, Redis, and MariaDB. Dokploy provides multi-server support, allowing for easy staging environment setup.

Key Benefits of the Integration

Integrating Dokploy offers several key benefits. It provides a Vercel-like developer experience, enabling a push-to-GitHub, auto-deploy workflow without vendor lock-in. A visual dashboard simplifies monitoring and rollbacks, while the easy staging environment setup allows for better scalability as the user base grows. Automated database backups enhance data protection. Role-based access control, although not critical initially for a solo developer, will prove helpful as the team expands. And finally, the self-hosted nature of Dokploy prevents the burden of monthly SaaS costs.

Implementation Plan

This section outlines a phased approach to integrate Dokploy. Each phase focuses on a specific aspect of the integration, ensuring a smooth transition and comprehensive functionality.

Phase 1: Dokploy Installation and Setup

This phase covers the initial setup of Dokploy on the Hetzner VPS:

  1. Install Dokploy: Deploy Dokploy on the Hetzner VPS using the Docker-based installation method.
  2. Configure Domain: Set up a domain or subdomain, for example, deploy.marcusgoll.com, to access the Dokploy UI.
  3. SSL/TLS Setup: Configure SSL/TLS using Let's Encrypt to secure the Dokploy dashboard.
  4. Admin Account: Create an admin account and ensure secure access.
  5. Backup Strategy: Establish a backup strategy for the Dokploy data, including UI configurations and metadata.

Phase 2: Application Migration

In this phase, we'll migrate the existing application to Dokploy:

  1. Migrate Next.js Application: Connect the Next.js application to Dokploy by linking it with the GitHub repository. Configure build settings for Next.js and Node.
  2. Environment Variables: Set up environment variables through the Dokploy UI.
  3. Custom Domain: Configure the custom domain, such as marcusgoll.com.
  4. Test Deployment: Test the deployment pipeline by pushing changes to the main branch to ensure that the auto-deploy function is operational.
  5. Migrate PostgreSQL Database: Import the existing Supabase PostgreSQL instance to Dokploy. Set up automated backups, including daily backups with a 7-day retention period. Configure the database access credentials and test the connection from the Next.js application to ensure seamless database interaction.

Phase 3: CI/CD Integration

This section deals with integrating continuous integration and continuous delivery into the workflow:

  1. Configure GitHub Webhooks: Set up GitHub webhooks to enable auto-deployment upon code pushes.
  2. Set Up Notifications: Configure deployment notifications through Discord, Slack, or email.
  3. Configure Rollback Strategy: Set up a rollback strategy using either the Dokploy UI or CLI.
  4. Document Process: Document the deployment process for future reference.
  5. Test Rollback: Test the rollback procedure and ensure a recovery time of less than 5 minutes.

Phase 4: Monitoring & Observability

In this phase, the focus will be on monitoring and observability:

  1. Enable Monitoring Dashboard: Activate the real-time monitoring dashboard to track CPU usage, memory usage, and network traffic.
  2. Set Up Alerts: Configure alerts for disk space and memory limits.
  3. Health Check Endpoints: Set up health check endpoints and integrate them with Dokploy.
  4. Load Test: Test the monitoring system during load, simulating traffic spikes.

Phase 5: Staging Environment (Future)

This future phase will deal with setting up a staging environment. It will be implemented when the website traffic exceeds 10,000 monthly visitors:

  1. Plan Staging Environment: Plan the setup of a staging environment by adding a second server, or using Dokploy's multi-server support. Configure staging branch auto-deploy and set up a staging database (separate from production). Set up a staging subdomain, like staging.marcusgoll.com.
  2. Document Workflow: Document the staging-to-production promotion workflow.

Out of Scope

The following items are out of scope for the Minimum Viable Product (MVP):

  • Docker Swarm clustering.
  • Multi-region deployments.
  • Advanced role-based access control.
  • Migrating to managed Dokploy cloud.
  • Custom Dokploy UI modifications/plugins.

Acceptance Criteria

  • Dokploy UI accessible over HTTPS at deploy.marcusgoll.com.
  • Pushing to the main branch auto-deploys to production in under 5 minutes.
  • Environment variables managed through the Dokploy UI.
  • Database backups run daily and are stored for 7 days.
  • Rollback to the previous deployment takes less than 5 minutes through the UI.
  • The real-time monitoring dashboard displays CPU, memory, and network usage.
  • Deployment notifications are sent on success and failure.
  • Documentation is updated with the new deployment workflow.
  • Zero downtime or planned downtime of less than 30 minutes during the Dokploy migration.

Technical Notes

This section covers the current deployment stack, the migration strategy, and other technical aspects.

Current Deployment Stack

The current deployment stack includes:

  • Hetzner VPS with Docker.
  • GitHub Actions for CI/CD.
  • Manual Docker commands (docker-compose.prod.yml).
  • Self-hosted Supabase PostgreSQL.

Migration Strategy (Zero-Downtime)

The migration strategy is designed to minimize downtime:

  1. Install Dokploy: Install Dokploy on the VPS without disrupting the current deployment.
  2. Configure Application: Configure the Dokploy application in parallel, using a test subdomain.
  3. Validate Deployment: Verify that the Dokploy deployment matches the production environment.
  4. Switch DNS: Switch DNS from the manual Docker deployment to Dokploy.
  5. Monitor: Monitor the new setup for 24 hours before decommissioning the old setup.

Piggybacks On

The project leverages existing infrastructure, including the Hetzner VPS, Docker setup, GitHub repository, and PostgreSQL database.

Risks and Mitigations

  • Risk: Dokploy adds complexity.
    • Mitigation: Fallback to manual Docker if necessary. Dokploy is an abstraction.
  • Risk: Learning curve.
    • Mitigation: Well-documented, similar to Vercel/Netlify UX.
  • Risk: Dokploy becomes unmaintained.
    • Mitigation: Extract Docker configurations and run manually.
  • Risk: VPS resource overhead.
    • Mitigation: Dokploy is lightweight.

ICE Scoring Rationale

Impact

  • Improves deployment DX significantly (manual to automated).
  • Enables future staging environment.
  • Reduces deployment errors and time.
  • Saves ~2-3 hours/month on deployment tasks.

Effort

  • Installation: ~2-4 hours.
  • Application migration: ~3-5 hours.
  • Testing & validation: ~2-3 hours.

Confidence

  • Well-documented open-source project.
  • Active development, good community.
  • Similar to known platforms (Vercel/Netlify).

ICE Score

  • Good quality-of-life improvement.
  • Not urgent (current deployment works).

References

  • Dokploy Website: https://dokploy.com/
  • Deployment Strategy Doc: docs/project/deployment-strategy.md
  • Tech Stack Doc: docs/project/tech-stack.md
  • Current Deployment: docker-compose.prod.yml, deploy.sh

Conclusion

Integrating Dokploy will streamline the deployment process, improve monitoring capabilities, and facilitate future scalability, providing a modern, developer-friendly experience. By adopting Dokploy, the project gains a robust, self-hosted deployment platform that enhances productivity and control.

For more information on deployment strategies and server management, check out DigitalOcean's documentation on deploying applications: DigitalOcean Deployment Guides. This is a reliable resource for server management. It is closely related to the subject matter of this article, and it offers additional insights into deployment practices and related topics.

You may also like