Deploy a static site with Caddy V2 on Google Cloud Run - gem-cloud-run-caddy-website

A passionate full-stack developer from @ePlus.DEV
Search for a command to run...

A passionate full-stack developer from @ePlus.DEV
No comments yet. Be the first to comment.
Quick and practical tips to help users optimize tasks, improve skills, and solve common problems effectively across various areas like tech, lifestyle, productivity, and more.
Overview In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to

Một bản tin giúp Developer cập nhật nhanh AI, Cloud, Open Source và những công nghệ đáng chú ý trong ngày. 📌 Executive Summary OpenAI công bố báo cáo mới về cách AI đang làm thay đổi phạm vi công

Overview In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to

Một bản tin giúp Developer cập nhật nhanh AI, Cloud, Open Source và những công nghệ đáng chú ý trong ngày. 📌 Executive Summary Anthropic bổ sung khả năng thay đổi tool giữa cuộc hội thoại mà không

Một bản tin giúp Developer cập nhật nhanh AI, Cloud, Open Source và những công nghệ đáng chú ý trong ngày. 📌 Executive Summary Claude Opus 5 bắt đầu được triển khai trên GitHub Copilot cho các tác

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell
at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. The output contains a line that declares the PROJECT_ID for this session:
Your Cloud Platform project in this session is set to YOUR_PROJECT_ID
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
gcloud auth list
Click Authorize.
Your output should now look like this:
Output:
ACTIVE: *
ACCOUNT: student-01-xxxxxxxxxxxx@qwiklabs.net
To set the active account, run:
$ gcloud config set account `ACCOUNT`
gcloud config list project
Output:
[core]
project = <project_ID>
Example output:
[core]
project = qwiklabs-gcp-44776a13dea667a6
Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
In this lab, you'll learn how to deploy a static website using Caddy V2 on Google Cloud Run. Caddy is a powerful, enterprise-ready, open source web server with automatic HTTPS. We'll containerize Caddy with your static website and deploy it to Cloud Run using Artifact Registry for container image storage.
Configure your Google Cloud environment for this lab.
qwiklabs-gcp-04-0ab4f70ed2ff with your Project ID.gcloud config set project qwiklabs-gcp-04-0ab4f70ed2ff
Note:
This command sets your active project identity.
us-west1 with your desired region (e.g., us-central1).gcloud config set run/region us-west1
Note:
This command sets your active cloud run region.
gcloud services enable run.googleapis.com artifactregistry.googleapis.com cloudbuild.googleapis.com
Note:
This command enables the necessary APIs for this lab.
Create a Docker repository in Artifact Registry to store the Caddy container image.
us-west1 with your desired region.gcloud artifacts repositories create caddy-repo --repository-format=docker --location=us-west1 --description="Docker repository for Caddy images"
Note:
This command creates an Artifact Registry repository.
Create a simple static website and configure Caddy to serve it.
index.html file with the following content:<html>
<head>
<title>My Static Website</title>
</head>
<body>
<div>Hello from Caddy on Cloud Run!</div>
<p>This website is served by Caddy running in a Docker container on Google Cloud Run.</p>
</body>
</html>
Note:
This is the HTML content for your static website.
Caddyfile with the following content::8080
root * /usr/share/caddy
file_server
Note:
This Caddyfile configures Caddy to serve files from the /usr/share/caddy directory on port 8080.
Define the Docker image for Caddy and your static website.
Dockerfile with the following content:FROM caddy:2-alpine
WORKDIR /usr/share/caddy
COPY index.html .
COPY Caddyfile /etc/caddy/Caddyfile
Note:
This Dockerfile uses the official Caddy Alpine image, sets the working directory, and copies your website and Caddyfile.
Build the Docker image and push it to Artifact Registry.
us-west1 and qwiklabs-gcp-04-0ab4f70ed2ff with your region and project ID.docker build -t us-west1-docker.pkg.dev/qwiklabs-gcp-04-0ab4f70ed2ff/caddy-repo/caddy-static:latest .
Note:
This command builds the Docker image and tags it with the Artifact Registry repository URL.
docker push us-west1-docker.pkg.dev/qwiklabs-gcp-04-0ab4f70ed2ff/caddy-repo/caddy-static:latest
Note:
This command pushes the Docker image to Artifact Registry.
Deploy the container image to Cloud Run.
us-west1 and qwiklabs-gcp-04-0ab4f70ed2ff with your region and project ID.gcloud run deploy caddy-static --image us-west1-docker.pkg.dev/qwiklabs-gcp-04-0ab4f70ed2ff/caddy-repo/caddy-static:latest --platform managed --allow-unauthenticated
Note:
This command deploys the Docker image to Cloud Run and allows unauthenticated access.
caddy-static and allow unauthenticated invocations.Note:
This configures the service name and permissions.
Note:
This is the URL where your static website is accessible.
Access the deployed website through the Cloud Run service URL.
Note:
Verify that your static website is displayed correctly.
curl -LO raw.githubusercontent.com/Techcps/Google-Cloud-Skills-Boost/master/Deploy%20a%20static%20site%20with%20Caddy%20V2%20on%20Google%20Cloud%20Run/techcps.sh
sudo chmod +x techcps.sh
./techcps.sh