Skip to content

πŸ’š πŸ’š GreenWebhook πŸ’š πŸ’š is a proxy or gateway between two systems that helps reduce your carbon footprint by dynamically routing or delaying traffic so that your workloads run when and where they will cause the lowest amount of carbon emissions.

License

Notifications You must be signed in to change notification settings

jonparker/green-webhook

Repository files navigation

πŸ’š Welcome to Green Webhook! πŸ’š

Green Webhook is a proxy or gateway between two systems that intelligently chooses which endpoint to send a webhook event to in order to location shift or time shift (coming soon) compute workloads to the endpoint with the lowest carbon intensity. It uses the Carbon Aware SDK to check the impact of an increased demand on the electricity grid for the relevant locations.

By deploying your workload to multiple regions and configuring each endpoint along with its location within a Green Webhook you can reduce the carbon emissions caused by your workload.

Currently Green Webhook supports only Azure regions but as the Carbon Aware SDK adds more support for other locations Green Webhook will be able to support them too.

Green Webhook is built on RedwoodJS and uses:

React TypeScript GraphQL Prisma Postgres TailwindCSS

Create a webhook that runs code on your laptop via ngrok

  1. Create a NextJS app by running npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/api-routes-starter"
  2. Create pages/api/user.js with:
export default function handler(req, res) {
  res.status(200).json({ name: "John Doe" });
}
  1. In a terminal run npm run dev
  2. Install Ngrok
  3. In a terminal run ngrok http 3000
  4. Copy the URL output by Ngrok and add /api/user to the end
  5. Log in to https://greenwebhook.netlify.app and create a new webhook
  6. Paste the URL from step 6 into the destination
  7. Click Save
  8. Click on the Invocation URI link to trigger the webhook
  9. Confirm that the response is 200 and contains JSON { name: "John Doe" }

Currently the Carbon Aware SDK only supports a limited list of locations but when more locations are supported then we will be able to allow you to put in the location where your computer or laptop is running in order to determine if it is the location with the lowest carbon intensity.

Getting started developing locally

Prerequisites

Start by installing dependencies:

yarn install

Whilst that is running, create a file in the root folder called .env and copy the following into it:

# Used to encrypt/decrypt session cookies. Change this value and re-deploy to log out all users of your app at once.
# Run yarn redwood generate secret and copy the value below
SESSION_SECRET=YOUR_SESSION_SECRET

# SendInBlue secret for reset password emails to work (optional)
# Requires setting up a free account at https://www.sendinblue.com/
SEND_IN_BLUE_KEY=YOUR_SENDINBLUE_SECRET
SEND_IN_BLUE_EMAIL=YOUr_SENDINBLUE_EMAIL_ADDRESS

DEPLOY_URL=http://localhost:8910

# Create a free database via https://railway.app and replace YOUR_RAILWAY_DB_URL bellow with the connection URL
DATABASE_URL="YOUR_RAILWAY_DB_URL"
CARBON_AWARE_API_BASE_URI="https://carbon-aware-api.azurewebsites.net"

# Run yarn redwood generate secret and copy the value below
SCHEDULED_WEBHOOKS_API_KEY=YOUR_SCHEDULED_WEBHOOK_SECRET_KEY

Replace YOUR_SESSION_SECRET with the secret generated by running yarn rw generate secret.

Replace YOUR_SCHEDULED_WEBHOOK_SECRET_KEY with the secret generated by running yarn rw generate secret a second time.

Create a free database via https://railway.app and copy the connection URL and replace YOUR_RAILWAY_DB_URL with it image

If you want to be able to send emails to reset passwords then you will need to create a SendInBlue account and create an API key and replace SEND_IN_BLUE_KEY with the API key.

Now when yarn install is finished you're ready to create the database tables in your Railway database.

yarn redwood prisma migrate dev

Once this finishes you should see tables appear in the database in Railway

image

Now you can run the app locally:

yarn rw dev

Your browser should automatically open to http://localhost:8910 where you'll see the Home page.

If you want to run scheduled webhooks you will need to periodically send a GET request to http://localhost:8910/.netlify/functions/schedule with the x-api-key header set to the YOUR_SCHEDULED_WEBHOOK_SECRET_KEY secret you created above.

Frontend first with Storybook

Don't know what your data models look like? That's more than ok β€” Redwood integrates Storybook so that you can work on design without worrying about data. Mockup, build, and verify your React components, even in complete isolation from the backend:

yarn rw storybook

About

πŸ’š πŸ’š GreenWebhook πŸ’š πŸ’š is a proxy or gateway between two systems that helps reduce your carbon footprint by dynamically routing or delaying traffic so that your workloads run when and where they will cause the lowest amount of carbon emissions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •