Self-Hosted CI/CD on an Idle Server: A Practical Deployment Setup

    A self-hosted CI/CD pipeline can automate deployments without burdening a small production server or giving an external CI platform access to production credentials. This article describes a setup built around an idle ARM cloud server, repository mirroring, a self-hosted runner, and a restricted deployment account, along with the security controls and maintenance trade-offs involved.

    1. Background: A Simple Deployment Requirement

    I recently built a documentation website for a new product. Its source code lives in a public repository, and my workflow is straightforward: edit the documentation locally, verify the changes, then commit and push. The writing and version-control steps worked smoothly, but deployment remained manual.

    Each update required logging in to the server, pulling the latest code, installing dependencies, running the build, and restarting the service. The process took more than ten minutes and was vulnerable to mistakes that could affect the live site.

    The problem was not just the repetitive work. Deployment interrupted my focus every time I updated the documentation. Automation was the obvious next step, but the environment imposed several constraints.

    2. Why Neither Production Builds nor Hosted CI Fit

    Constraint 1: Limited production resources

    The production server has modest hardware and already runs the live service. Installing frontend dependencies, bundling static assets, and building container images can consume several gigabytes of memory and substantial CPU time.

    Running those tasks on the production server could slow down builds or, more seriously, destabilize the live service. The standard approach is to separate building from running: build in a dedicated environment and send only the resulting artifacts to production.

    Constraint 2: External CI cannot access production

    For a public repository, a hosted CI service would normally be the simplest option. However, my production environment has strict security controls and does not allow external CI systems to hold production access credentials.

    The network egress of an external CI environment is also outside my control. Storing deployment credentials on a third-party platform would introduce another potential exposure point.

    Constraint 3: An idle server was available

    I already had an unused ARM cloud instance with four cores and 24 GB of memory, obtained through a free offering. It had enough capacity to host a Git service, run builds, and maintain build caches.

    That made the goal clear: leave the live service on the production server and move the automation control plane—repository mirroring, pipeline execution, build caching, and deployment orchestration—to the idle machine. My local workflow and use of the public repository would remain unchanged.

    3. Overall Architecture

    The resulting workflow is:

    1. Local documentation changes
    2. -> Public repository
    3. -> Self-hosted code platform through repository mirroring
    4. -> Self-hosted pipeline runner
    5. -> Deployment script
    6. -> Production server update
    7. -> Deployment complete

    Each component has a specific responsibility:

    1. Public repository: Remains the entry point for public collaboration, preserving community visibility and the existing development workflow.

    2. Self-hosted code platform: Runs on the idle server and mirrors code from the public repository through scheduled or event-triggered synchronization. It serves as the entry point for the internal build system.

    3. Pipeline runner: Is registered with the self-hosted code platform and responds to push events. It installs dependencies, builds the site, packages the output, and runs the deployment process. Build caches remain on the same server, reducing the time needed for repeat builds.

    4. Deployment channel: Transfers build artifacts to production through a controlled path. A dedicated, low-privilege account on the production server can write only to the site’s deployment directory and execute a limited set of reload commands. It cannot modify system-level configuration.

    4. Restricting the Deployment Account

    Security is central to this design. Three principles guide the deployment process.

    Least privilege

    Create a dedicated system account for deployments and limit its writable scope to the site’s release directory.

    Use key-based SSH authentication. On the server, apply a command restriction in authorized_keys to bind the key to a specific deployment command rather than allowing an interactive shell. This limits what someone can do with the key if it is compromised.

    Allowlisted commands

    Wrap the required reload or release-switching operations in a restricted script. The script should expose only fixed deployment actions, not arbitrary command execution.

    Artifact verification

    Include a checksum with each build artifact. Verify it after transfer and before replacing the live version.

    Prepare the release in a temporary directory, then switch it into place atomically. This avoids exposing partially deployed files and supports a quick rollback if deployment fails.

    The deployment script follows this conceptual outline:

    1. Build:
    2. Install dependencies
    3. -> Build static artifacts
    4. -> Package artifacts and calculate a checksum
    5. Deploy:
    6. Transfer artifacts with scp to a temporary directory on the target server
    7. -> Verify artifacts remotely
    8. -> Atomically switch the site directory
    9. -> Trigger a service reload
    10. Failure handling:
    11. Abort if any step fails and retain the previous release

    This is pseudocode describing the deployment stages, not a complete script.

    5. Benefits and Trade-offs

    Benefits

    Reuse of idle resources. The unused server became a reusable deployment platform at almost no additional cost. Other small projects can use the same infrastructure later.

    A clearer security boundary. Production trusts only the controlled deployment channel within the internal network. The external platform has no direct access to the production environment.

    No change to the development workflow. I still commit and push to the public repository. Synchronization, building, and deployment happen automatically afterward.

    Maintenance costs and pitfalls

    Self-hosting also means taking responsibility for the code platform and runner, including maintenance, upgrades, and backups.

    Several practical issues deserve attention:

    • ARM compatibility: Some dependencies require additional work to run on ARM.
    • Synchronization behavior: The mirroring mechanism needs idempotency and debouncing so frequent pushes do not trigger a build storm.
    • Pipeline logs: Logs need centralized retention to make deployment failures easier to investigate.

    The approach reduces dependence on external CI, but it does not eliminate operational work. It moves that responsibility onto infrastructure I control.

    6. Conclusion

    The core idea is to move resource-intensive builds and credential-sensitive deployment orchestration away from both an underpowered production server and an external CI environment that is outside the production trust boundary.

    A dedicated automation server handles those tasks, while a low-privilege deployment account and allowlisted commands protect the production boundary.

    For individual developers or small teams with spare compute capacity and strict production security requirements, the combination of build–runtime separation, self-hosted CI/CD, and tightly scoped deployment permissions offers a practical, low-cost foundation that can expand to support additional projects.