Is there a way to get/add/modify DNS records in Digital Ocean via doctl or another command line utility? I was unable to find anything that looked relevant via doctl help.

It looks like worst case I could call the HTTP API directly, although I’m not sure how I would need to get the correct authentication credentials.

curl 'https://cloud.digitalocean.com/api/v1/domains/MY_DOMAIN/records/MY_RECORD' -X PUT
...
-H 'Cookie: ... _digitalocean2_session_v4=SOME_AUTH_TOKEN?; ...'
--data-raw '{"record":{"name":"_dnslink.www.MY_DOMAIN","record_type":"TXT","created_at":"2020-08-30T22:39:51.000Z","updated_at":"2020-09-24T03:55:21.000Z","port":null,"weight":null,"ttl":"300","data_record":"dnslink=/ipfs/IPFS_HASH","priority":null,"tag":null,"flags":null,"droplet_id":null,"floating_ip_id":null,"load_balancer_id":null}}'

My use case is I have a GitHub Action that uploads a web app to IPFS (https://ipfs.io/) that is served via a dnslink.DOMAIN TXT record via CloudFlare (https://medium.com/pinata/how-to-easily-host-a-website-on-ipfs-9d842b5d6a01, section Setting Up Your DNS Records to Point to Cloudflare). After the upload happens, I need to update that _dnslink record to point to the new IPFS hash (dnslink.DOMAIN TXT “dnslink=/ipfs/IPFS_HASH”)

Action yml (modified for clarity) in case it helps:

name: web

on:
  push

jobs:
  build-deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Install Node.js
      uses: actions/setup-node@v1
      with:
        node-version: 12.x

    - name: Install npm dependencies
      run: npm install

    - name: Typescript checks
      run: npm run tsc

    - name: Webpack build 
      run: npm run build

    - name: Upload to Pinata (IPFS) 
      uses: aquiladev/ipfs-action@v0.1.4
      with:
        path: ./dist
        service: pinata
        pinataKey: ${{ secrets.PINATA_KEY }}
        pinataSecret: ${{ secrets.PINATA_SECRET }}

    - name: Install doctl
      uses: digitalocean/action-doctl@v2
      with:
        token: ${{ secrets.DIGITAL_OCEAN_DOCKER_AUTH }}

    - name: Update dnslink record
      # HELP What should I do here?
      run: doctl ...

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi, hope you’re doing well. I did a little digging and found this documentation kinda buried on DO’s site:

https://www.digitalocean.com/docs/apis-clis/doctl/reference/compute/domain/records/

It does look like you can perform the necessary DNS actions via doctl but they are under the “compute” area of functionality.

Hope this helps and let us know if you have any other questions or feedback - good luck!

  • Thanks @baraboom, worked perfectly!

    This is the command I ended up using

    doctl compute domain records update --record-id=MY_RECORD_ID --record-ttl=300 --record-data=dnslink=/ipfs/IPFS_HASH MY_DOMAIN
    

    You can get the record-id from

    doctl compute domain records list MY_DOMAIN
    
Submit an Answer