Prerequisites:
- Node.js version >= 14.15.0
- Postgres version >= 13
-
Clone the repo:
git clone https://github.com/infracost/cloud-pricing-api.git cd cloud-pricing-api
-
Use the Infracost CLI to get an API key so your self-hosted Cloud Pricing API can download the latest pricing data from us:
infracost auth login
The key is saved in
~/.config/infracost/credentials.yml
. -
Generate a 32 character API token that your Infracost CLI users will use to authenticate when calling your self-hosted Cloud Pricing API. If you ever need to rotate the API key, you can simply update this environment variable and restart the application.
export SELF_HOSTED_INFRACOST_API_KEY=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) echo "SELF_HOSTED_INFRACOST_API_KEY=$SELF_HOSTED_INFRACOST_API_KEY"
-
Add a
.env
file with the following content:# Don't forget to run `CREATE DATABASE cloud_pricing;` first. POSTGRES_URI=postgresql://postgres:my_password@localhost:5432/cloud_pricing # The Infracost API from Step 2, used to download pricing data from us. INFRACOST_API_KEY=<API Key from Step 2> # The API key you generated in step 3, used to authenticate Infracost CLI users with your self-hosted Cloud Pricing API. SELF_HOSTED_INFRACOST_API_KEY=<API Key from Step 3>
-
Install the npm packages:
npm install
-
Download the pricing data, this can take a few minutes. The second command will show the number of products in the DB (each product has multiple prices).
npm run job:init:dev && npm run data:status:dev
If there are DB changes, run
npm run db:setup:dev
to apply them. The init job runs this too so this should only be needed if you haven't run that recently. -
Prices can be kept up-to-date by running the update job once a week, for example from cron:
npm run job:update:dev # Cron: add a cron job to run every week to update the database data. The cron entry should look something like: 0 4 * * SUN npm run-script job:update >> /var/log/cron.log 2>&1
-
Start the server:
In development mode:
npm run dev
In production mode:
npm run build npm run start
curl -i http://localhost:4000/health
should show success. -
To configure the Infracost CLI to use your self-hosted Cloud Pricing API, you can use:
export INFRACOST_PRICING_API_ENDPOINT=http://localhost:4000 export INFRACOST_API_KEY=$SELF_HOSTED_INFRACOST_API_KEY infracost breakdown --path /path/to/code
You can also access the GraphQL Playground at http://localhost:4000/graphql using something like the modheader browser extension so you can set the custom HTTP header
X-API-KEY
to yourSELF_HOSTED_INFRACOST_API_KEY
.
@alikhajeh1 and @aliscott rotate release responsibilities between them.
- In
package.json
updateversion
, runnpm install
and push to master. - In the cloud-pricing-api repo, run
git tag vx.y.z && git push origin vx.y.z
- Wait for the GH Actions to complete as that creates/pushes the docker tag.
- Goto https://github.com/infracost/cloud-pricing-api/compare and find the diff between the latest and the previous version so you can create a description for the GitHub Release.
- Click Releases > Draft New Release button, set the
vx.y.z
value in the tag name and release title. Also add the release description from step 4 and click on publish. - Follow the Helm chart release steps.
- Announce the release in the infracost-community Slack announcements channel.
- Update the docs repo with any required changes.
- Close addressed issues and tag anyone who liked/commented in them to tell them it's live in version X.