Refactor deploy script and update IPNS DNSlink
This commit is contained in:
parent
ccb63da564
commit
cb6ffbac93
70
tasks.py
70
tasks.py
|
@ -3,21 +3,10 @@ from yaspin import yaspin
|
||||||
import requests as rq
|
import requests as rq
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
yaml = YAML()
|
yaml = YAML()
|
||||||
|
|
||||||
CONFIG = yaml.load(Path('deploy.yaml'))
|
CONFIG = yaml.load(Path("deploy.yaml"))
|
||||||
|
|
||||||
|
|
||||||
def pin_by_hash(hsh, name):
|
|
||||||
s = rq.Session()
|
|
||||||
s.headers = {"Authorization": f'Bearer {CONFIG["pinata-key"]}'}
|
|
||||||
params = {
|
|
||||||
"pinataMetadata": {"name": name},
|
|
||||||
"hashToPin": hsh,
|
|
||||||
}
|
|
||||||
r = s.post("https://api.pinata.cloud/pinning/pinByHash", json=params)
|
|
||||||
r.raise_for_status()
|
|
||||||
return r.json()
|
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
|
@ -39,19 +28,48 @@ def deploy(c, clean=False):
|
||||||
s.ok("[done]")
|
s.ok("[done]")
|
||||||
s.write(f"- published at {new_hash}")
|
s.write(f"- published at {new_hash}")
|
||||||
|
|
||||||
s.text = "pin at Pinata"
|
pinata(c, new_hash, "erambler")
|
||||||
s.start()
|
update_dnslink(c, f"/ipfs/{new_hash}")
|
||||||
try:
|
|
||||||
pin_result = pin_by_hash(new_hash, "erambler")
|
|
||||||
s.ok("[done]")
|
|
||||||
s.write(f'- pin status: {pin_result["status"]}')
|
|
||||||
except rq.HTTPError:
|
|
||||||
s.fail("[fail]")
|
|
||||||
|
|
||||||
s.text = "publish to IPNS"
|
|
||||||
s.start()
|
@task
|
||||||
c.run(
|
def pinata(c, new_hash, name):
|
||||||
f"ipfs name publish --key={CONFIG['ipns-key']} /ipfs/{new_hash}",
|
with yaspin(text="pin at pinata").yellow as s:
|
||||||
hide=True,
|
result = rq.post(
|
||||||
|
"https://api.pinata.cloud/pinning/pinByHash",
|
||||||
|
headers={"Authorization": f'Bearer {CONFIG["pinata-key"]}'},
|
||||||
|
json={
|
||||||
|
"pinataMetadata": {"name": name},
|
||||||
|
"hashToPin": new_hash,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
result.raise_for_status()
|
||||||
s.ok("[done]")
|
s.ok("[done]")
|
||||||
|
details = result.json()
|
||||||
|
s.write(f'- pin status: {details["status"]}')
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def update_dnslink(c, ipfs_path):
|
||||||
|
with yaspin(text="update dnslink record").yellow as s:
|
||||||
|
cf_config = CONFIG["cloudflare"]
|
||||||
|
token = cf_config["token"]
|
||||||
|
zone_id = cf_config["zone_id"]
|
||||||
|
record_id = cf_config["record_id"]
|
||||||
|
|
||||||
|
result = rq.put(
|
||||||
|
f"https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records/{record_id}",
|
||||||
|
headers={"Authorization": f"Bearer {token}"},
|
||||||
|
json={
|
||||||
|
"type": "TXT",
|
||||||
|
"name": "_dnslink.erambler.co.uk",
|
||||||
|
"content": f"dnslink={ipfs_path}",
|
||||||
|
"ttl": 1,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
result.raise_for_status()
|
||||||
|
details = result.json()
|
||||||
|
if details["success"]:
|
||||||
|
s.ok("[done]")
|
||||||
|
else:
|
||||||
|
s.fail()
|
||||||
|
|
Loading…
Reference in New Issue