docker icon indicating copy to clipboard operation
docker copied to clipboard

Add automated Let's Encrypt support via certbot

Open madest92 opened this issue 8 months ago โ€ข 4 comments

Summary

Adds automated Let's Encrypt certificate management using Certbot.

This introduces two optional Docker Compose services:

  • certbot-init โ€“ performs the initial certificate issuance using standalone mode
  • certbot-renew โ€“ runs in the background and periodically renews certificates

Nginx is reloaded automatically after successful renewal using kill -HUP 1

madest92 avatar Apr 02 '26 04:04 madest92

Review Change Stack

No actionable comments were generated in the recent review. ๐ŸŽ‰

โ„น๏ธ Recent review info
โš™๏ธ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bdf20dc2-305a-406e-b7f5-7d46fdce6ae1

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 22b63f1569d3b60ca962b0f64583af29ee16aae9 and 8474f5badd86545a1bfafa52f987ce9b998e1618.

๐Ÿ“’ Files selected for processing (2)
  • docker-compose.nginx.yml
  • env.example
โœ… Files skipped from review due to trivial changes (1)
  • env.example
๐Ÿšง Files skipped from review as they are similar to previous changes (1)
  • docker-compose.nginx.yml

๐Ÿ“ Walkthrough

Walkthrough

Adds two Certbot services to docker-compose for one-time certificate issuance and continuous renewal, and updates environment file comments explaining the ACME workflow and an optional GitLab PKI chain variable.

Changes

Let's Encrypt automation

Layer / File(s) Summary
Certbot renewal and initialization
docker-compose.nginx.yml
Added certbot-init (profile: acme-init) for one-time certbot certonly using HTTP-01 on ${HTTP_PORT} with idempotent certificate-existence checks, and certbot-renew (profile: acme) that loops certbot renew every 24 hours, mounts certificate directories and shared webroot, depends on nginx, and triggers nginx reload via deploy hook.
Configuration documentation
env.example
Updated comments to document the two-step Let's Encrypt workflow (acme-init profile for initial certificate, then acme profile for automatic renewal), and added an optional GITLAB_PKI_CHAIN_PATH explanation (commented example) to prevent certificate validation failures in GitLab SSO.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Compose as Docker Compose
    participant CertInit as certbot-init
    participant LE as Let's Encrypt
    participant FS as File System
    participant Nginx
    participant CertRenew as certbot-renew

    User->>Compose: Run with acme-init profile
    Compose->>CertInit: Start certbot-init
    CertInit->>FS: Check /etc/letsencrypt/live/$DOMAIN
    alt certificate missing
        CertInit->>LE: Request cert via HTTP-01 on ${HTTP_PORT}
        LE->>CertInit: HTTP-01 challenge
        CertInit->>LE: Respond to challenge
        LE->>FS: Issue and store certificate
    else certificate exists
        CertInit->>CertInit: Exit successfully
    end

    User->>Compose: Run with acme profile
    Compose->>Nginx: Start nginx
    Compose->>CertRenew: Start certbot-renew
    loop Every 24 hours
        CertRenew->>LE: certbot renew for ${DOMAIN}
        alt renewed
            LE->>FS: Update certificate files
            CertRenew->>Nginx: deploy hook (kill -HUP 1)
            Nginx->>Nginx: Reload configuration
        end
    end

Estimated code review effort

๐ŸŽฏ 2 (Simple) | โฑ๏ธ ~10 minutes

๐Ÿšฅ Pre-merge checks | โœ… 5
โœ… Passed checks (5 passed)
Check name Status Explanation
Title check โœ… Passed The title accurately and clearly summarizes the main change: adding automated Let's Encrypt certificate management via Certbot to the Docker setup.
Description check โœ… Passed The description is directly related to the changeset, providing a clear summary of the two new Docker Compose services and their purpose.
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check โœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check โœ… Passed Check skipped because no linked issues were found for this pull request.

โœ๏ธ Tip: You can configure your own custom pre-merge checks in the settings.

โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Apr 02 '26 04:04 coderabbitai[bot]

@coderabbitai approve

madest92 avatar Apr 02 '26 04:04 madest92

โœ… Actions performed

Comments resolved and changes approved.

coderabbitai[bot] avatar Apr 02 '26 04:04 coderabbitai[bot]

This PR has been automatically labelled "stale" because it hasn't had recent activity. A core team member will check in on the status of the PR to help with questions. Thank you for your contribution!

mattermost-build avatar Apr 13 '26 01:04 mattermost-build