balloon
(🎈 BALLOON | FU-SEN)
January 26, 2020, 1:52am
1
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.
Dockerfile
FROM abiosoft/caddy:php
COPY ./ /srv/
RUN sed -i 's/0\.0\.0\.0/0.0.0.0:{$PORT}/' /etc/Caddyfile
RUN sed -e '$a tls off' /etc/Caddyfile
index.php
<?php
$target = getenv('TARGET', true) ?: 'Caddy';
echo sprintf("Hello %s!", $target);
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:
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.
Caddyfile
0.0.0.0:{$PORT}
tls off
# Do not rewrite up to this point!
browse
log stdout
errors stdout
templates
Dockerfile
FROM abiosoft/caddy
copy ./Caddyfile /etc/
COPY ./ /srv/
index.html
{{.Now "Monday, 2 Jan 2006"}}
gcloud builds submit --tag gcr.io/PROJECT-ID/caddy
gcloud run deploy --image gcr.io/PROJECT-ID/caddy --platform managed
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!
balloon
(🎈 BALLOON | FU-SEN)
January 28, 2020, 3:36am
2
If you fail to build, try:
gcloud builds submit --project PROJECT-ID --tag gcr.io/PROJECT-ID/caddy
balloon
(🎈 BALLOON | FU-SEN)
January 28, 2020, 3:44am
3
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:
matt
(Matt Holt)
February 3, 2020, 6:05am
4
Thanks for the guide! This is really interesting. Maybe we should provide some sort of official image or container or something for GCR?