diff --git a/caddy/builtins/http.Caddyfile b/caddy/builtins/http.Caddyfile new file mode 100644 index 0000000..d01a7e1 --- /dev/null +++ b/caddy/builtins/http.Caddyfile @@ -0,0 +1,7 @@ +# Routes all plain http requests to sourcegraph-frontend - suitable for local testing. +# +# Caddyfile documentation: https://caddyserver.com/docs/caddyfile + +:80 + +reverse_proxy {$SRC_FRONTEND_ADDRESSES} diff --git a/caddy/builtins/https.custom-cert.Caddyfile b/caddy/builtins/https.custom-cert.Caddyfile new file mode 100644 index 0000000..695acc4 --- /dev/null +++ b/caddy/builtins/https.custom-cert.Caddyfile @@ -0,0 +1,16 @@ +# Serves Sourcegraph over HTTPS, using a custom SSL certificate/key pair +# that's bind mounted from the host to /sourcegraph.pem and /sourcegraph.key. +# +# Caddyfile documentation: https://caddyserver.com/docs/caddyfile + +{$SRC_SITE_ADDRESS} + +# Redirects all HTTP traffic to HTTPS (using custom SSL certificates disables the automatic HTTPS feature of Caddy, see https://caddyserver.com/docs/automatic-https) +@http { + protocol http +} +redir @http https://{host}{uri} + +tls /sourcegraph.pem /sourcegraph.key + +reverse_proxy {$SRC_FRONTEND_ADDRESSES} diff --git a/caddy/builtins/https.lets-encrypt-prod.Caddyfile b/caddy/builtins/https.lets-encrypt-prod.Caddyfile new file mode 100644 index 0000000..669d083 --- /dev/null +++ b/caddy/builtins/https.lets-encrypt-prod.Caddyfile @@ -0,0 +1,21 @@ +# Serves Sourcegraph over HTTPS, using Caddy's automatic HTTPS certificate feature: +# https://caddyserver.com/docs/automatic-https +# +# 🚨 Warning: If your DNS and Caddy configuration aren't properly configured (as +# specified in https://caddyserver.com/docs/automatic-https), you can +# run into Let's Encrypt rate limits which can block your certificates +# for up to a week. +# It's strongly recommened that you use the staging Caddyfile +# (https.lets-encrypt-staging.Caddyfile) to test your +# configuration before switching to this production one. +# +# Caddyfile documentation: https://caddyserver.com/docs/caddyfile +# + +{ + email {$SRC_ACME_EMAIL} +} + +{$SRC_SITE_ADDRESS} + +reverse_proxy {$SRC_FRONTEND_ADDRESSES} diff --git a/caddy/builtins/https.lets-encrypt-staging.Caddyfile b/caddy/builtins/https.lets-encrypt-staging.Caddyfile new file mode 100644 index 0000000..dfcef3b --- /dev/null +++ b/caddy/builtins/https.lets-encrypt-staging.Caddyfile @@ -0,0 +1,27 @@ +# Serves Sourcegraph over HTTPS, using Caddy's automatic HTTPS certificate feature: +# https://caddyserver.com/docs/automatic-https +# +# Note: This configuration uses Let's Encrypt's staging environment. This will +# allow you to ensure that everything is correctly configured (with a reduced +# chance of running into rate limit issues). Note that using this configuration +# issues a fake certificate (for testing purposes) instead of a trusted one. +# +# 🚨 Warning: If your DNS and Caddy configuration aren't properly configured (as +# specified in https://caddyserver.com/docs/automatic-https), you can +# run into Let's Encrypt rate limits which can block your certificates +# for up to a week. +# It's strongly recommened that you use this Caddyfile to test your +# configuration before switching to the production one. +# +# Caddyfile documentation: https://caddyserver.com/docs/caddyfile +# + +{ + # Use Let's Encrypt's staging environment + acme_ca "https://acme-staging-v02.api.letsencrypt.org/directory" + email {$SRC_ACME_EMAIL} +} + +{$SRC_SITE_ADDRESS} + +reverse_proxy {$SRC_FRONTEND_ADDRESSES} diff --git a/docker-compose/docker-compose.yaml b/docker-compose/docker-compose.yaml index ad5a5c4..44faf33 100644 --- a/docker-compose/docker-compose.yaml +++ b/docker-compose/docker-compose.yaml @@ -2,23 +2,57 @@ version: '2.4' services: # Description: Acts as a reverse proxy for all of the sourcegraph-frontend instances # - # Disk: none + # Disk: 1GB / persistent SSD # Ports exposed to other Sourcegraph services: none - # Ports exposed to the public internet: 7080 (HTTP) and/or 7443 (HTTPS) + # Ports exposed to the public internet: 80 (HTTP) and 443 (HTTPS) # - # Note: nginx/nginx/sourcegraph_backend.conf lists all of the sourcegraph-frontend - # network addresses that Nginx should proxy. nginx/nginx/sourcegraph_backend.conf - # needs to be updated with new addresses when scaling the number of soucegraph-frontend - # replicas. - nginx: - container_name: nginx - image: 'index.docker.io/library/nginx:1.17.7@sha256:8aa7f6a9585d908a63e5e418dc5d14ae7467d2e36e1ab4f0d8f9d059a3d071ce' - cpus: 1 - mem_limit: '1g' + # Sourcegraph ships with a few builtin templates that cover common HTTP/HTTPS configurations: + # - HTTP only (default) + # - HTTPS with Let's Encrypt + # - HTTPS with custom certificates + # + # Follow the directions in the comments below to swap between these configurations. + # + # If none of these built-in configurations suit your needs, then you can create your own Caddyfile, see: + # https://caddyserver.com/docs/caddyfile + caddy: + container_name: caddy + image: 'index.docker.io/caddy/caddy:alpine@sha256:b0f0a763527ca11a555bc5b5f942fa2d84ae0c90b0b60e47d0426ff884dd10ad' + cpus: 4 + mem_limit: '4g' + environment: + - 'XDG_DATA_HOME=/caddy-storage/data' + - 'XDG_CONFIG_HOME=/caddy-storage/config' + - 'SRC_FRONTEND_ADDRESSES="sourcegraph-frontend-0:3080"' + # Uncomment & update this line when using Let's Encrypt or custom HTTPS certificates: + # - 'SRC_SITE_ADDRESS="sourcegraph.example.com"' + # + # Uncomment & update the following line when using HTTPS with Let's Encrypt + # - 'SRC_ACME_EMAIL=admin@example.com' volumes: - - '../nginx:/etc/nginx' + - 'caddy:/caddy-storage' + # + # Comment out the following line when using HTTPS with either Let's Encrypt or custom certficates + - '../caddy/builtins/http.Caddyfile:/etc/caddy/Caddyfile' + # + # Uncomment the following line when using HTTPS with Let's Encrypt's staging environment + # - '../caddy/builtins/https.lets-encrypt-staging.Caddyfile:/etc/caddy/Caddyfile' + # + # Uncomment the following line when using HTTPS with Let's Encrypt's production environment + # IMPORTANT: Strongly recommended to test with the staging configuration above first, see that file for details. + # - '../caddy/builtins/https.lets-encrypt-prod.Caddyfile:/etc/caddy/Caddyfile' + # + # Uncomment the following line when using HTTPS with custom certificates + # - '../caddy/builtins/https.custom-cert.Caddyfile:/etc/caddy/Caddyfile' + # + # Uncomment / update the following line when using HTTPS with custom certficates + # - '/LOCAL/CERT/PATH.pem:/sourcegraph.pem' + # + # Uncomment / update the following line when using HTTPS with custom certficates + # - '/LOCAL/KEY/PATH.pem:/sourcegraph.key' ports: - - '0.0.0.0:80:7080' + - '0.0.0.0:80:80' + - '0.0.0.0:443:443' networks: - sourcegraph restart: always @@ -559,6 +593,7 @@ services: restart: always volumes: + caddy: gitserver-0: grafana: #jaeger-cassandra: