{"id":30853538,"url":"https://github.com/majiinb/api-template-gc","last_synced_at":"2026-04-20T19:31:45.134Z","repository":{"id":310847542,"uuid":"1041463144","full_name":"majiinB/API-TEMPLATE-GC","owner":"majiinB","description":"Template Node.js API with Docker \u0026 GitHub Actions for automated deployment to Google Cloud Run. Includes environment setup, security best practices, and workflow automation for main and staging branches.","archived":false,"fork":false,"pushed_at":"2025-12-23T09:30:31.000Z","size":108,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-24T23:46:38.149Z","etag":null,"topics":["api","express-js","google-cloud"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/majiinB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-20T14:20:39.000Z","updated_at":"2025-12-23T09:30:36.000Z","dependencies_parsed_at":"2025-08-20T16:34:03.487Z","dependency_job_id":"d5c1c52d-2c9f-4520-8286-2fcd7207a8df","html_url":"https://github.com/majiinB/API-TEMPLATE-GC","commit_stats":null,"previous_names":["majiinb/api-template-gc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/majiinB/API-TEMPLATE-GC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majiinB%2FAPI-TEMPLATE-GC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majiinB%2FAPI-TEMPLATE-GC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majiinB%2FAPI-TEMPLATE-GC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majiinB%2FAPI-TEMPLATE-GC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/majiinB","download_url":"https://codeload.github.com/majiinB/API-TEMPLATE-GC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majiinB%2FAPI-TEMPLATE-GC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32062287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","express-js","google-cloud"],"created_at":"2025-09-07T09:35:29.853Z","updated_at":"2026-04-20T19:31:45.114Z","avatar_url":"https://github.com/majiinB.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🏗️ API SERVICE TEMPLATE (GOOGLE CLOUD)\n\nThis repository contains a template for an API built with **Node.js, Express, and Docker**, ready to deploy on **Google Cloud Run**. It’s designed to serve as a starting point for new services.\n\n---\n\n## 👤 Creator\n\nThis API template was created by **Arthur Artugue**.  \n\n[GitHub](https://github.com/majiinB) | [Portfolio](https://personal-portfolio-virid-delta.vercel.app) | [Email](mailto:arthurartugue392@gmail.com)\n\n---\n\n## 📃 Table of Contents\n\n1. [Overview](#-overview)  \n2. [Security Features](#-security-features)  \n2. [Prerequisites](#-prerequisites)  \n    - [Make a copy](#make-a-copy-of-the-repo)  \n    - [What to Change](#what-to-change) \n    - [Additional Steps](#additional-steps)  \n3. [Setup](#-setup)  \n4. [Running Locally](#-running-locally)  \n5. [Deploying to Cloud Run](#d-eploying-to-cloud-run)  \n  \n\n---\n\n## 🔭 Overview\n\nThis API template includes:\n\n- Node.js + Express server  \n- Dockerfile for containerization  \n- GitHub Actions workflow for CI/CD to Cloud Run  \n- Example endpoints ready to extend  \n\nIt’s intended as a **starting point for new services**, so you can copy this repo, rename it, and adapt it for your specific API.\n\n---\n\n## 🔐 Security Features\n\n- **CORS**:  \n  The API already uses [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) to restrict cross-origin requests.\n  \u003e **Note:** Rate limiting was not included since this is expected to run in `Google Cloud Run`. The API will be behind a load balancer so rate limiting by IP address will not work. In addition, in memory cache (like Redis) will be dependent on your architecture (Stateless or Stateful). I recommend using `Redis` served in the cloud or just use `Google Cloud Armor`. \n\n- **Service Accounts**:  \n  Deployment uses a Google Cloud service account with minimal required permissions for Cloud Run and Artifact Registry. The key is stored securely in GitHub Secrets (`GCP_KEY`) and is never committed to the repo.\n\n- **Branch Protection \u0026 Workflow Rules**:  \n  The repository can enforce that the `staging` branch passes tests before changes are merged into `main`. This ensures deployments are safe and reviewed.\n  \u003e**Note:** You need to enforce these rules manually to your github repo. `\u003cyour-repo\u003e` -\u003e ⚙️ settings -\u003e 🌿branches -\u003e ➕ Add branch ruleset\n\n- **Environment Variables**:  \n  Sensitive configuration (like `NODE_ENV`, `PORT`, API keys) is stored in a `.env` file or GitHub Secrets, keeping credentials out of source code.\n\n\n---\n\n## ✅ Prerequisites\n\n**Before you start** Make sure you have the following installed and set up:\n\n- **Node.js 22+**  \n- **npm** or **yarn**  \n- **Docker** (for building images locally)  \n- **Google Cloud SDK**  \n- **Google Cloud CLI**  \n\nAlso, ensure you have a **Google Cloud Project** with:\n\n- Cloud Run enabled  \n- Artifact Registry repository created  \n- Service account key for authentication  \n\nOn the GitHub side:\n\n- Repository created  \n- Secrets configured:\n  - `GCP_KEY` (your service account JSON)\n\nFinally, create a **.env** file with the following keys:\n\n- `NODE_ENV=development` (see `env.config.ts` for accepted values)  \n- `PORT=8080`\n\n---\n\n## 🪜 Setup\n### Make a copy of the repo\n1. **Clone the repo**  \n```bash\ngit clone \u003cyour-repo-url\u003e\ncd \u003crepo-name\u003e\n```\n\n2. **Install dependencies**  \n```bash\nnpm install\n# or if you use yarn\nyarn install\n```\n\n3. **Create your `.env` file**  \n```bash\nNODE_ENV=development\nPORT=8080\n```\n\n### What to Change\n\n#### package.json\n- Update the `name` and `version` fields to match your API.  \n- Ensure the `start` script points to your entry file (`index.js` or `dist/index.js`).\n\n#### .env file\n- Set `NODE_ENV`, `PORT`, and any other environment variables your API needs.\n\n#### Github Workflows\n- Uncomment the whole script if automation is needed, delete if otherwise.\n\n#### Google Cloud configuration\n- Update `GCP_PROJECT_ID`, `REGION`, `ARTIFACT_REGISTRY_REPO`, and `SERVICE_NAME` in your GitHub Actions workflow.  \n- Ensure your service account key has the proper permissions for Cloud Run and Artifact Registry.\n\n### Additional Steps \n\u003e**Note:** These steps are already included in the [Deployment](#deployment) automation. Specifically when you push to `main`, perform these steps if needed (eg. for local development testing).\n\n4. **Build the Docker image**  \n```bash\ndocker build -t \u003cyour-region\u003e-docker.pkg.dev/\u003cyour-project-id\u003e/\u003cyour-repo\u003e/\u003cyour-service-name\u003e:latest .\n```\n\n5. **Authenticate Docker with Google Artifact Registry**  \n```bash\ngcloud auth configure-docker \u003cyour-region\u003e-docker.pkg.dev --quiet\n```\n\n6. **Push the Docker image to Artifact Registry**  \n```bash\ndocker push \u003cyour-region\u003e-docker.pkg.dev/\u003cyour-project-id\u003e/\u003cyour-repo\u003e/\u003cyour-service-name\u003e:latest\n```\n\n7. **Deploy to Cloud Run**  \n```bash\ngcloud run deploy \u003cyour-service-name\u003e \\\n  --image \u003cyour-region\u003e-docker.pkg.dev/\u003cyour-project-id\u003e/\u003cyour-repo\u003e/\u003cyour-service-name\u003e:latest \\\n  --region \u003cyour-region\u003e \\\n  --platform managed \\\n  --allow-unauthenticated\n```\n\n---\n\n## 🖥️ Running Locally\n\n- Run API locally (Express server):\n```bash\nnpm run dev\n# or\nyarn dev\n```\n- Run API locally (Docker Container):\n```bash\ndocker run -p 8080:8080 \u003cyour-region\u003e-docker.pkg.dev/\u003cyour-project-id\u003e/\u003cyour-repo\u003e/\u003cyour-service-name\u003e:latest\n```\n\n---\n\n## ☁️ Deploying to Cloud Run\n\nDeployment is automated via **GitHub Actions**:\n\n1. Push to the `staging` branch for testing in a staging environment (optional but recommended).  \n2. Push to the `main` branch to deploy to production.  \n\nThe workflow will:  \n- Authenticate with Google Cloud  \n- Build and push Docker image to Artifact Registry  \n- Deploy the API to Cloud Run  \n\n\u003e**Note:** Make sure the `GCP_KEY` secret in GitHub contains your service account JSON key.\n\n**Optional best practice:**  \n- You can enforce a branch protection rule in GitHub so that `main` can only be updated after the `staging` branch passes tests. This ensures that only verified code is deployed to production.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajiinb%2Fapi-template-gc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmajiinb%2Fapi-template-gc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajiinb%2Fapi-template-gc/lists"}