Caddy works with Google Cloud Run

Caddy is great, but server setup is painful.
So, let’s use Google Cloud Run. You can use Caddy in minutes.
With Always Free, you can try it with little concern for billing.

Precondition

Contracted Google Cloud Platform and completed Google Cloud Run official documentation “Quickstart: Build and Deploy”:

Caddy + PHP

This replaces php:apache.
Put the files to be installed in root together with Dockerfile.

Build: (or docker)

gcloud builds submit --tag gcr.io/PROJECT-ID/caddy

Deploy: (or GCP console)

gcloud run deploy --image gcr.io/PROJECT-ID/caddy --platform managed

Browse:
スクリーンショット 2020-01-26 10.09.52

Note: See 502 Bad Gateway immediately after deployment. At that time php-fpm is still booting.

Freely editable Caddyfile

Display today’s date using a template.

gcloud builds submit --tag gcr.io/PROJECT-ID/caddy
gcloud run deploy --image gcr.io/PROJECT-ID/caddy --platform managed

スクリーンショット 2020-01-26 10.45.28

Note:

  • This Caddy is v1. v1 and v2 have a difference in the syntax of Caddyfile.
  • Do not change after Caddyfile: 0.0.0.0:{$PORT} and tls off
    This (IP address:port and custom domain) is realized on Cloud Run side.

Enjoy!

2 Likes

If you fail to build, try:

gcloud builds submit --project PROJECT-ID --tag gcr.io/PROJECT-ID/caddy

I also tried the official Docker image for Caddy v2.

For now, editing Caddyfile required root privileges.

gcloud builds submit --project PROJECT-ID --tag gcr.io/PROJECT-ID/caddy2
gcloud run deploy --image gcr.io/PROJECT-ID/caddy2 --platform managed

Free Caddyfile:

2 Likes

Thanks for the guide! This is really interesting. Maybe we should provide some sort of official image or container or something for GCR?

This topic was automatically closed after 180 days. New replies are no longer allowed.