Back to blog

How to Automate IPFS Deployments as Part of CI/CD Pipelines with Pinata

How to Automate IPFS Deployments as Part of CI/CD Pipelines with Pinata

Justin Hunter

Tired of manual IPFS deployments slowing down your workflow?

Manual deployments can get the job done, but they often lead to slower updates, potential errors, and wasted effort — especially as projects grow.

Automated deployments, on the other hand, ensure consistency and reliability every time.

But automating IPFS deployments isn’t without its hurdles. Securely managing API keys, integrating IPFS pinning into existing CI/CD workflows, and maintaining version control for decentralized content often present challenges. With Pinata, however, automation is simple, secure, and streamlined.

Pinata can be integrated into CI/CD pipelines, especially using GitHub Actions. Automating your IPFS deployments this way will help you save time, reduce errors, and ensure fast, decentralized content delivery.

5 reasons to automate IPFS deployments

While manual deployments might work for small projects, they fall short when faced with the demands of real-world applications. Automation allows you to deploy faster and more reliably at scale, making it the smarter choice for IPFS deployments. Let’s look at five reasons why.

1. Save build time and reduce errors

Manual IPFS deployments often involve tedious steps like compressing files, uploading them to IPFS, and managing metadata. These tasks consume valuable time and are prone to human error. Automation eliminates these inefficiencies and allows teams to channel their efforts into optimizing applications, enhancing user experiences, and scaling projects to handle larger datasets.

While it may be tough to calculate time savings universally, Spinamp had some compelling results. They doubled developer efficiency by automating their IPFS hosting with Pinata, enabling their team to focus on product innovation rather than repetitive deployment tasks. And that’s just one example of what automation can do for you.

2. Ensure reliable and fast updates

People expect speed and reliability from mobile and web apps. When your apps begin to crash and lag, you risk user dissatisfaction and churn. Automating IPFS deployments minimizes downtime and helps you deliver consistent updates, keeping your app available and your content fresh.

Don’t just take our word for it, though. Supercast used this strategy to achieve 99.9% uptime with Pinata. They also accelerated image uploads by 30%, ensuring their content was always reliable and accessible to users.

3. Improve workflow efficiency

Tools like GitHub Actions, webhooks, and custom scripts allow developers to integrate IPFS into their CI/CD pipelines, enhancing workflow efficiency and reducing bottlenecks. Automation also eliminates the need for manual intervention in deployment workflows. Case in point: Fileverse improved load times by 60% by using Pinata's efficient gateway and CDN, enabling a seamless integration with their deployment pipeline.

4. Scale with confidence

As projects grow, the risks and inefficiencies of manual deployments multiply. Automation handles high-volume deployments, simplifies complex workflows, and helps you scale up in ways manual deployments cannot. For example, OpenSea automated the pinning and retrieval of NFT metadata using Pinata’s IPFS gateway and CDN to handle higher traffic.

This automation keeps their metadata accessible, reliable, and fast — even during high-traffic periods. By integrating Pinata’s infrastructure into their workflows, OpenSea improved the reliability and speed of NFT metadata delivery by 99.2%, which allowed them to scale operations without interruptions or performance issues.

5. Optimize costs and resources

Manual IPFS deployments often require extensive resources, from developer hours to managing infrastructure. Automation streamlines these processes, reducing overhead and maximizing efficiency. By leveraging tools like Pinata’s IPFS gateway and CDN, teams can optimize their workflows, save costs, and allocate resources to more impactful areas of their projects.

How much money could your company save by automating IPFS deployments? For Buttrfly, the answer was significant. By migrating to Pinata, they cut storage costs by 50% and boosted performance by 20%, highlighting the dual benefits of cost efficiency and improved functionality.

How Pinata makes automated deployments easy

Pinata enables developers to securely store, manage, and deliver decentralized content with features like APIs, custom gateways, and scalable infrastructure.

Pinata simplifies automated IPFS deployments through a suite of developer-friendly tools and features designed to integrate into your CI/CD workflows. Here's how Pinata makes this process effortless:

Comprehensive API and SDK support

Pinata offers a lightweight, flexible TypeScript SDK and an API that enables developers to programmatically manage file uploads, pinning, and retrieval. This facilitates the automation of IPFS deployments directly within your application's codebase.

For example, you’d use Pinata's SDK to upload and pin files to IPFS programmatically.

import { PinataSDK } from "pinata-web3";

const pinata = new PinataSDK({
  pinataJwt: process.env.PINATA_JWT!,
  pinataGateway: "example-gateway.mypinata.cloud",
});

const file = new File(["hello world!"], "hello.txt", { type: "text/plain" });
const upload = await pinata.upload.file(file);

In the above example, the SDK is initialized with your credentials, including a secure JSON Web Token (JWT) stored in environment variables for security, and a custom gateway URL for accessing the content. 

A file is then created with sample content, which is uploaded to Pinata using the upload.file() method. 

Dedicated IPFS gateways with custom domains

Pinata provides dedicated IPFS gateways that ensure fast and secure content delivery. These gateways can be customized with your own domain, enhancing brand consistency and user trust. Automating deployments through these gateways ensures your content is always accessible and efficiently delivered.

Integration with CI/CD pipelines

Pinata is designed to integrate smoothly with various CI/CD environments. Whether you're using GitHub Actions, custom scripts, or other automation tools, Pinata's API and SDK provide the flexibility to incorporate IPFS deployments into your existing workflows without friction.

Advanced features for enhanced efficiency

Beyond basic pinning, Pinata offers features like:

  • Content versioning: Manage different versions of your content using IPFS hashes or commit SHAs, ensuring precise tracking and rollback capabilities.
  • Access controls: Define who can use your gateway and for what content, adding an extra layer of security to your deployments.
  • Analytics: Gain insights into your content's performance to make informed decisions about optimizing delivery.

Scalability and reliability

As the largest IPFS pinning service, Pinata offers unmatched stability and reliability. Its infrastructure is built to scale with your needs, effortlessly handling any volume of data, so you never have to worry about hitting capacity.

Integrating Pinata into your CI/CD pipelines allows for automated deployments of your decentralized content. Let’s take a look at how you can streamline your workflows using popular tools like GitHub Actions, Netlify, webhooks, and custom scripts.

Using GitHub Actions

GitHub Actions is the ideal choice for automating IPFS deployments with Pinata due to its simplicity and seamless integration into existing workflows. It automates the pinning of content directly to IPFS via Pinata and simplifies deployment by embedding it into your repository’s workflow.

For example:

  1. Add the anantaramdas/[email protected] to your .yml workflow file.
  2. Use secrets for API keys instead of hardcoding them into the configuration. 
  3. Store your PINATA_API_KEY and PINATA_SECRET_API_KEY as secrets in your GitHub repository settings.

This sample workflow snippet demonstrates how to use the GitHub Actions ipfs-pinata-deploy-action to automate IPFS deployments. Note that this is a community-built action that Pinata has no control or influence over and is not audited by Pinata.

name: Deploy to IPFS via Pinata
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Build project
        run: npm run build
      - name: Deploy to IPFS
        uses: anantaramdas/[email protected]
        with:
          pin-name: 'My IPFS Project'
          path: './dist'
          pinata-api-key: ${{ secrets.PINATA_API_KEY }}
          pinata-secret-api-key: ${{ secrets.PINATA_SECRET_API_KEY }}

It begins by triggering a push to the main branch, so the workflow only runs for production-level updates. The deploy job first checks out the repository code and builds the project using npm run build. 

Next, the Pinata GitHub Action is used to pin the built files from the ./dist directory to IPFS, with API keys securely retrieved from GitHub Secrets for authentication. 

Finally, the workflow retrieves the uploaded content's IPFS hash, which can be logged or used in subsequent steps for versioning or notifications.

Using Netlify integration

Netlify’s CI/CD capabilities make it another excellent option for automating IPFS deployments. It automates deployments via webhooks triggered by build events and offers built-in CI/CD capabilities that simplify the process of managing IPFS content.

Here’s how to use Netlify to automate IPFS deployments:

  1. Use Netlify’s webhook feature to trigger Pinata’s pinning action during your build pipeline.
  2. Link the webhook to Pinata’s REST API to upload and pin your content.
  3. Refer to Netlify’s Guide to CI/CD Automation for setup instructions.

Here’s how to trigger Pinata’s API using a webhook during the Netlify build process: 

curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS \
-H "pinata_api_key: <your-api-key>" \
-H "pinata_secret_api_key: <your-secret-api-key>" \
-F "file=@path/to/your/build/output.zip"

This code snippet uses a curl command to send a POST request to Pinata’s pinFileToIPFS endpoint, securely passing API keys as headers and uploading a file from the specified path. This will allow Netlify to automatically pin content to IPFS upon completing a build, streamlining the deployment process and ensuring up-to-date content is efficiently uploaded to the decentralized web.

Using Webhooks

Webhooks are flexible and compatible with various CI/CD environments and ideal for event-driven workflows because they respond immediately to specific triggers, such as the completion of a build or the deployment of new content. As HTTP callbacks triggered by specific events in your CI/CD pipeline, webhooks allow you to automate Pinata’s pinning actions without manual intervention.

To use webhooks to automate your deployments:

  1. Configure your CI/CD tool (e.g., Jenkins, GitLab) to trigger a webhook on build completion.
  2. Use Pinata’s REST API to programmatically pin files:
curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS \
-H "pinata_api_key: <your-api-key>" \
-H "pinata_secret_api_key: <your-secret-api-key>" \
-F "file=@path/to/your/build/output.zip"

We have used the same curl command code here as in the example about Netlify integration. The Netlify integration focuses on triggering Pinata’s API through its webhook feature as part of Netlify’s build process, whereas here it’s about the general use of HTTP callbacks in CI/CD pipelines. However, the action of pinning content to IPFS using Pinata’s API remains the same.

Using custom scripts

For unique CI/CD environments, custom scripts provide a tailored solution for interacting with Pinata’s API. They give you total flexibility for custom workflows and help you combine multiple tasks, such as compressing files and pinning them, into a single automated step.

Here’s how custom scripts can work in this use case:

  1. Use scripting languages like Python, Bash, or Node.js to interact with Pinata’s API.
  2. Place the script into your CI/CD pipeline configuration.

This Python code snippet shows how to use Python to automate the process of pinning files to IPFS via Pinata’s API. 

Python

import requests

PINATA_API_KEY = '<your-api-key>'
PINATA_SECRET_API_KEY = '<your-secret-api-key>'

with open('build/output.zip', 'rb') as file:
    response = requests.post(
        'https://api.pinata.cloud/pinning/pinFileToIPFS',
        headers={
            'pinata_api_key': PINATA_API_KEY,
            'pinata_secret_api_key': PINATA_SECRET_API_KEY,
        },
        files={'file': file},
    )
    print(f"Pinned with hash: {response.json()['IpfsHash']}")

This will initialize the API keys securely, read a file from the local system, and send a POST request to the pinFileToIPFS endpoint using the requests library. Upon successful upload, the script retrieves and prints the IPFS hash, which can be used for tracking or integration into other workflows. This provides flexibility to tailor the script to unique CI/CD environments or specific automation needs.

4 advanced configuration and tactical tips for Pinata

Taking your IPFS deployment automation to the next level requires using advanced configurations and features. To help you optimize your workflows using Pinata’s tools and capabilities, we’ve put together this detailed guide.

1. Set up custom domains via dedicated gateways

Pinata allows you to set up a custom domain for your IPFS gateway, giving you complete control over how your content is accessed. Using a custom domain lets you create a branded, professional, and cohesive user experience. This improves accessibility by giving users easy access to your content without long, complex gateway URLs.

Here’s how to set it up:

  1. Purchase a domain or use an existing one.
  2. Point your domain to Pinata’s gateway by creating a CNAME DNS record pointing to gateway.pinata.cloud.
  3. Configure the custom domain in your Pinata dashboard under "Dedicated Gateways.”

2. Implement version control

Versioning allows you to track changes and manage multiple iterations of your IPFS content, ensuring a clear history and quick rollback capabilities. To implement version control:

  • Use IPFS hashes: Each pinned file generates a unique hash; use that as a version identifier.
  • Combine with commit SHAs: Pair the IPFS hash with your Git commit SHA for precise versioning in your repository.

For example, you can generate the IPFS hash during the deployment process:

- name: Get IPFS hash
  run: echo "Deployed to IPFS with hash ${{ steps.deploy.outputs.hash }}"

In the above code, we capture the hash output from the deployment step, which allows teams to track and reference specific versions of the content. This hash can be paired with Git commit SHAs for precise version control, ensuring a clear history of changes and enabling easy rollbacks or updates when needed. After deploying the code, simply save the hash in your version control system or deployment logs for future reference.

3. Automate your content testing

Automated testing ensures the quality and reliability of your content before deployment. This reduces the risk of broken links, incorrect files, or other errors making it to production. To automate testing, add this step to your CI/CD pipeline:

- name: Run Tests
  run: npm test

The above code adds a test (e.g., npm test) to the CI/CD pipeline that validates the quality and reliability of the project before deployment, ensuring only error-free content is deployed to IPFS. You’ll run two tests:

  • Integrations: Verify that your IPFS content interacts correctly with other application components by creating test cases that simulate real-world interactions, such as fetching and rendering IPFS-hosted data within your app.
  • Snapshots: During each test run, generate snapshots of your content and compare them with expected outputs. This will ensure consistent structure and integrity for your IPFS content.

4. Enable deployment notifications

Deployment notifications keep your team informed about the status of automated workflows, helping you address issues promptly and confirm successful updates.

First, configure GitHub Actions to send notifications to Slack or email upon success or failure.

- name: Notify Slack on success
  if: success()
  run: |
    curl -X POST -H 'Content-type: application/json' \
    --data '{"text":"Deployment succeeded!"}' \
    https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

- name: Notify Slack on failure
  if: failure()
  run: |
    curl -X POST -H 'Content-type: application/json' \
    --data '{"text":"Deployment failed!"}' \
    https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

This code will send deployment status notifications to your specified Slack channel. It uses curl to post a message to a Slack webhook URL, with conditional logic to send a notification if the deployment succeeds or an alert if it fails. This ensures that your team is immediately informed about the deployment's status, enabling quick responses to issues or confirmation of successful updates.

End-to-end example workflow

For automated, reliable deployment to IPFS with real-time status updates, you need code that:

  1. Pulls the latest version of your repository for deployment.
  2. Installs required project dependencies using npm install.
  3. Builds your project, creating a production-ready version in the ./dist folder.
  4. Uses the Pinata GitHub Action to pin the built files to IPFS.
  5. Logs the IPFS hash of the pinned content for tracking and reference.
  6. Sends status notifications: “On success” sends the deployment's IPFS hash to Slack, and “Onfailure” sends a Slack notification about the failed deployment.

This workflow enables an automated, reliable deployment to IPFS while giving your team real-time status updates. Use this sample snippet to get started:

name: Deploy to IPFS via Pinata

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      # Step 1: Checkout the repository
      - name: Checkout code
        uses: actions/checkout@v3

      # Step 2: Install dependencies
      - name: Install dependencies
        run: npm install

      # Step 3: Build the project
      - name: Build project
        run: npm run build

      # Step 4: Deploy to IPFS via Pinata
      - name: Deploy to IPFS
        id: deploy
        uses: anantaramdas/[email protected]
        with:
          pin-name: 'My IPFS Project'
          path: './dist'
          pinata-api-key: ${{ secrets.PINATA_API_KEY }}
          pinata-secret-api-key: ${{ secrets.PINATA_SECRET_API_KEY }}

      # Step 5: Retrieve the IPFS hash and log it
      - name: Retrieve IPFS hash
        run: echo "Deployed to IPFS with hash ${{ steps.deploy.outputs.hash }}"

      # Step 6: Notify on success
      - name: Notify Slack on success
        if: success()
        run: |
          curl -X POST -H 'Content-type: application/json' \
          --data '{"text":"Deployment succeeded! IPFS Hash: ${{ steps.deploy.outputs.hash }}"}' \
          https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

      # Step 7: Notify on failure
      - name: Notify Slack on failure
        if: failure()
        run: |
          curl -X POST -H 'Content-type: application/json' \
          --data '{"text":"Deployment failed! Please check the logs."}' \
          https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Ready to get started with Pinata?

Setting up Pinata is quick and straightforward.

Step 1: Follow the quickstart guide

Pinata’s quickstart guide provides everything you need, from creating your account to pinning your first files to IPFS. The guide is beginner-friendly and provides clear instructions for setting up and exploring Pinata’s powerful features.

Step 2: Try the GitHub Action

Automate your deployments with the IPFS Pinata Deploy GitHub Action. This action integrates into your existing CI/CD workflows, allowing you to pin content directly to IPFS with just a few lines of configuration.

Step 3: Set up API keys and secrets

Pinata makes it easy to securely manage your API keys:

  • Generate your API keys in the Pinata dashboard. Navigate to your Pinata account settings, select the API Keys section, and create a new key by specifying the required permissions for your workflow.
  • Add them as secrets in your GitHub repository or CI/CD tool for secure access during workflows. In your GitHub repository settings, go to the Secrets section under Security, create new secrets for your Pinata API key and secret key, and reference them in your workflow file using ${{ secrets.YOUR_SECRET_NAME }}.

Ready to take your decentralized projects to the next level? Start for free  with Pinata today to discover how easy it is to automate your IPFS deployments.


Subscribe to paid plan image

Share this post:

Stay up to date

Join our newsletter for the latest stories & product updates from the Pinata community.