use terraform & github actions
parent
c275813d97
commit
4f18b3fd66
|
|
@ -0,0 +1,72 @@
|
|||
name: Deploy to Cloudflare
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['main']
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v2.0.3
|
||||
with:
|
||||
terraform_version: 1.6.4
|
||||
|
||||
- name: Use Node.js 18.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
cache: 'npm'
|
||||
|
||||
# Automatically get an account id via the API Token
|
||||
- name: Fetch Account ID
|
||||
id: fetch_account_id
|
||||
run: |
|
||||
ACCOUNT_ID=$(curl -X GET "https://api.cloudflare.com/client/v4/accounts" -H "Authorization: Bearer "$CLOUDFLARE_API_TOKEN -H "Content-Type:application/json" | jq ".result[0].id" -r)
|
||||
if [[ "$ACCOUNT_ID" == "null" ]]; then
|
||||
echo "Failed to get an account id, please make sure you have set up CLOUDFLARE_API_TOKEN correctly!"
|
||||
exit 1
|
||||
else
|
||||
echo 'account_id='$ACCOUNT_ID >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
|
||||
- name: Install packages
|
||||
run: |
|
||||
npm install
|
||||
cd worker
|
||||
npm install
|
||||
|
||||
- name: Build worker
|
||||
run: |
|
||||
cd worker
|
||||
npx wrangler deploy src/index.ts --outdir dist --dry-run
|
||||
|
||||
- name: Build page
|
||||
run: |
|
||||
npx @cloudflare/next-on-pages
|
||||
|
||||
- name: Deploy using Terraform
|
||||
# We're using terraform for first-time setup here,
|
||||
# since we didn't setup a remote backend to store state,
|
||||
# following runs will fail with name conflict, which is normal.
|
||||
continue-on-error: true
|
||||
|
||||
run: |
|
||||
terraform init
|
||||
terraform apply -auto-approve -input=false
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
TF_VAR_CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
|
||||
|
||||
# Currently Terraform Cloudflare provider doesn't support direct upload, use wrangler to upload instead.
|
||||
- name: Upload pages
|
||||
run: |
|
||||
npx wrangler pages deploy .vercel/output/static --project-name uptimeflare
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
|
|
@ -33,3 +33,6 @@ yarn-error.log*
|
|||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
.terraform/
|
||||
terraform.tfstate*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/cloudflare/cloudflare" {
|
||||
version = "4.19.0"
|
||||
constraints = "~> 4.0"
|
||||
hashes = [
|
||||
"h1:tgDfKsBL4SxCgq3sz28oLZ2q+Elzlt1Anpkm7kVC3q8=",
|
||||
"zh:1d5315dcbd8187a3a978dc1fb08e80b6cdd353de10afe531b3d1ecb834d0dbae",
|
||||
"zh:2a6e5b2e5072e442b35ce6142172e15afb835e16799d04a0054a79d3067f7560",
|
||||
"zh:308c5690024a1f6797300018456a1ac781c8699fa4bc4892a8c36eb992604a26",
|
||||
"zh:4286969a594396ef09ff6f6840428eef9c7dac037a3a3ef1ccae12a7a21b6655",
|
||||
"zh:55cfe536e4fd76ca9a256b905ffa2823b21b5ab6288245c5295a16b03ac4d0b8",
|
||||
"zh:58c74a26eef114d59d371f978131d78daa88260df2f75a2b6ec908f61dad2754",
|
||||
"zh:5c8dd7ff7820fd96f64e37f5611ad8e265a9b54a04d25e03fe589470ad5d2a0f",
|
||||
"zh:6501f10ee5e73ebe3cfe87d4141942c9c784c4ddcde15c6f500b8a41ca3cb174",
|
||||
"zh:890df766e9b839623b1f0437355032a3c006226a6c200cd911e15ee1a9014e9f",
|
||||
"zh:97f83ab5ff249bd195cfae3b2521f037dea2ad600d70e2917b35895db67c034f",
|
||||
"zh:b340b815cc53f197b42d9e64acb6729914706d93dcf60da02e3ac53aeadfde14",
|
||||
"zh:c49c8f4908b5776f52211e41880a98a18ebf558363b69ed6af461f2c0d5c9e00",
|
||||
"zh:d0ec9cec6a169b160825b0c585b56d42175871549bb291b9409b36086e9e6756",
|
||||
"zh:f6912037890a4777a2f8b55858f38fb3428ac53610fb7297d99ced1e73531d5c",
|
||||
"zh:f95ca4b80b66b02f1762d314172523ad57176369b7b1aaf4e5018a32f4525582",
|
||||
]
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
# 🕒UptimeFlare
|
||||
# ⚡UptimeFlare
|
||||
|
||||
Another **serverless (and free!)** uptime monitoring & status page on Cloudflare Workers with more advanced features and nice UI.
|
||||
|
||||
## ⭐Features
|
||||
|
||||
- **Opensource** & Easy to deploy (in 10 minutes without local tools) & Free
|
||||
- **Opensource** & Easy to deploy (in 10 minutes) & Free
|
||||
|
||||
#### Monitoring
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ Another **serverless (and free!)** uptime monitoring & status page on Cloudflare
|
|||
- Customizable status page
|
||||
- Use your own domain with CNAME
|
||||
|
||||
## 🪧Demo
|
||||
## 📈Demo
|
||||
|
||||
My status page (Online demo): https://uptimeflare.pages.dev/
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
cloudflare = {
|
||||
source = "cloudflare/cloudflare"
|
||||
version = "~> 4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "cloudflare" {
|
||||
# read token from $CLOUDFLARE_API_TOKEN
|
||||
}
|
||||
|
||||
variable "CLOUDFLARE_ACCOUNT_ID" {
|
||||
# read account id from $TF_VAR_CLOUDFLARE_ACCOUNT_ID
|
||||
type = string
|
||||
}
|
||||
|
||||
resource "cloudflare_workers_kv_namespace" "uptimeflare_kv" {
|
||||
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
||||
title = "uptimeflare_kv"
|
||||
}
|
||||
|
||||
resource "cloudflare_worker_script" "uptimeflare" {
|
||||
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
||||
name = "uptimeflare_worker"
|
||||
content = file("worker/dist/index.js")
|
||||
module = true
|
||||
compatibility_date = "2023-11-08"
|
||||
|
||||
kv_namespace_binding {
|
||||
name = "UPTIMEFLARE_STATE"
|
||||
namespace_id = cloudflare_workers_kv_namespace.uptimeflare_kv.id
|
||||
}
|
||||
}
|
||||
|
||||
resource "cloudflare_worker_cron_trigger" "uptimeflare_worker_cron" {
|
||||
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
||||
script_name = cloudflare_worker_script.uptimeflare.name
|
||||
schedules = [
|
||||
"*/2 * * * *", # every 2 minutes
|
||||
]
|
||||
}
|
||||
|
||||
resource "cloudflare_pages_project" "uptimeflare" {
|
||||
account_id = var.CLOUDFLARE_ACCOUNT_ID
|
||||
name = "uptimeflare"
|
||||
production_branch = "main"
|
||||
|
||||
deployment_configs {
|
||||
production {
|
||||
kv_namespaces = {
|
||||
UPTIMEFLARE_STATE = cloudflare_workers_kv_namespace.uptimeflare_kv.id
|
||||
}
|
||||
compatibility_date = "2023-11-08"
|
||||
compatibility_flags = ["nodejs_compat"]
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"name": "uptimeworker",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"vercel-build": "next build",
|
||||
"deploy": "wrangler deploy",
|
||||
"dev": "wrangler dev",
|
||||
"start": "wrangler dev"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20230419.0",
|
||||
"typescript": "^5.0.4",
|
||||
"wrangler": "^3.13.1"
|
||||
}
|
||||
"name": "uptimeworker",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"vercel-build": "next build",
|
||||
"deploy": "wrangler deploy",
|
||||
"dev": "wrangler dev",
|
||||
"start": "wrangler dev"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20230419.0",
|
||||
"typescript": "^5.0.4",
|
||||
"wrangler": "^3.13.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
name = "uptimeflare-worker"
|
||||
name = "uptimeflare_worker"
|
||||
main = "src/index.ts"
|
||||
compatibility_date = "2023-05-15"
|
||||
|
||||
[triggers]
|
||||
crons = ["*/2 * * * *"] # run every 2 minutes
|
||||
compatibility_date = "2023-11-08"
|
||||
|
|
|
|||
Loading…
Reference in New Issue