使用 GitHub Actions 自动化 Go 应用部署到 Google Cloud Run(免费层)

发布: (2025年12月20日 GMT+8 08:40)
3 min read
原文: Dev.to

Source: Dev.to

自动化 Go 应用部署到 Google Cloud Run(使用 GitHub Actions,免费层)

Hi, everyone! This is my first article on dev.to.👋

I recently built a Go application and deployed it using Google Cloud Run and GitHub Actions to deepen my DevOps skills. In this post, I’ll share how I automated the deployment process and what I learned along the way.

背景

I currently live in Canada but earn my salary in JPY. Since the exchange rate fluctuates constantly, checking the CAD/JPY rate manually every day has been a hassle. I wanted a system that would automatically notify me via Slack whenever the rate improved compared to the day before. To achieve this, I decided to automate the workflow using GCP and GitHub Actions.

系统架构

graph LR
  GitHub[GitHub] --> Actions[GitHub Actions]
  Actions --> Registry[Artifact Registry]
  Registry --> CloudRun[Cloud Run]
  Scheduler[Cloud Scheduler] --> CloudRun

为什么选择这些技术?

  • 为什么选 Go?
    It’s a statically typed language, which ensures robustness and keeps the container image size small.

  • 为什么选 Google Cloud Run?
    It’s a serverless platform, so I don’t need to manage servers. Plus, it scales to zero when not in use, allowing me to run this bot within the Free Tier.

  • 为什么选 GitHub Actions?
    It lets me manage the CI/CD pipeline right next to my code. Integrating it with GCP is secure and seamless.

关键挑战与解决方案

  • “默认安全”陷阱(403 Forbidden)
    Google Cloud Run blocks unauthenticated access by default. I resolved the 403 Forbidden errors by setting an OIDC token in the Cloud Scheduler authentication header.

  • CI/CD 配置细节
    I spent time debugging the GitHub Actions pipeline because of a mismatch in the Artifact Registry configuration. I had confused the repository name with the repository ID. This taught me that in DevOps, paying attention to the smallest details in variable names is just as important as writing the code itself.

我的收获

The trade‑off between initial setup pain and future efficiency became clear. Running code locally is intuitive and instant, while moving to the cloud felt tedious. Once I overcame that barrier, the power of automation became evident. The system now works for me while I sleep, illustrating that engineering is about enduring the initial struggle of setup to achieve long‑term efficiency.

未来改进

  • 数据库集成:Add PostgreSQL (with Atlas) to store historical rate data.
  • 数据分析:Build a Python component to analyze rate trends using Pandas and visualize the data.

链接

  • GitHub Repository:
Back to Blog

相关文章

阅读更多 »

仓库利用的权威指南

引言 仓库本质上只是一个 3‑D 盒子。利用率只是衡量你实际使用了该盒子多少的指标。虽然物流 c...