Whilst learning about IPFS and web3, I decided to try and deploy a static website using Gitlab CI/CD and this is how I did it. I have made a repository template so this should only take around 5 minutes to deploy your first static website to the IPFS network.
Head over to https://gitlab.com/ahuntuk/ipfs-cf-pinata and clone the repository.
Creating Cloudflare Records
Go to cloudflare and create a CNAME that points ipfs.yourdomain.com -> cloudflare-ipfs.com, you will also need to create a TXT record that is “_dnslink.ipfs.yourdomain.com” with the contents “dnslink=/ipfs/”
You will now need to gather the following information:
IPFS_DEPLOY_CLOUDFLARE__API_EMAIL = Cloudflare Account Email
IPFS_DEPLOY_CLOUDFLARE__API_KEY = Cloudflare API Key
IPFS_DEPLOY_CLOUDFLARE__API_TOKEN = Cloudflare API Token
IPFS_DEPLOY_CLOUDFLARE__RECORD = _dnslink.ipfs.yourdomain.com
IPFS_DEPLOY_CLOUDFLARE__ZONE = yourdomain.com
IPFS_DEPLOY_PINATA__API_KEY = Pinata Account API Key
IPFS_DEPLOY_PINATA__SECRET_API_KEY = Pinata Account Secret Key
We use variables so your real information will never be exposed in the CI/CD jobs.
Gitlab CI/CD Variables
Now that you have your information logged and cloned the repository, you can go to Settings > CI/CD > Variables and place the corresponding variables to data. You should end up with something looking like this.
All set up
Now if you have done it correctly, whenever you modify the contents in the public folder of the repository it will automatically pin the new data on IPFS using pinata and then the new CID will be updated in the TXT record you created pointing to your new pinned content.
It works! https://ipfs.ahunt.uk