From 1af375bab8c1768cbb66fe0d7266bbc006ca0bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20M=C5=82odzikowski?= Date: Tue, 20 Jun 2023 14:49:39 +0200 Subject: [PATCH] feat(ci): setup fleek deployments for testnet for console (#4138) --- .github/workflows/publish-dist.yml | 55 ++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish-dist.yml b/.github/workflows/publish-dist.yml index f750c5470..9ff24abe2 100644 --- a/.github/workflows/publish-dist.yml +++ b/.github/workflows/publish-dist.yml @@ -40,7 +40,7 @@ jobs: - name: Log in to the Container registry (docker hub) uses: docker/login-action@v2 - if: ${{ matrix.app == 'trading' && github.event_name == 'push' && endsWith(github.ref, 'main') }} + if: ${{ matrix.app == 'trading' && github.event_name == 'push' && ( endsWith(github.ref, 'main') || endsWith(github.ref, 'release/testnet') ) }} with: # registry: registry.hub.docker.com username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -183,7 +183,7 @@ jobs: ENV_NAME=${{ env.ENV_NAME }} tags: | vegaprotocol/${{ matrix.app }}:${{ github.sha }} - vegaprotocol/${{ matrix.app }}:mainnet + vegaprotocol/${{ matrix.app }}:${{ endsWith(github.ref, 'main') && 'mainnet' || endsWith(github.ref, 'release/testnet') && 'testnet' || '' }} - name: Publish dist as docker image (ghcr - retry) uses: docker/build-push-action@v3 @@ -210,13 +210,13 @@ jobs: ENV_NAME=${{ env.ENV_NAME }} tags: | vegaprotocol/${{ matrix.app }}:${{ github.sha }} - vegaprotocol/${{ matrix.app }}:mainnet + vegaprotocol/${{ matrix.app }}:${{ endsWith(github.ref, 'main') && 'mainnet' || endsWith(github.ref, 'release/testnet') && 'testnet' || '' }} # bucket creation in github.com/vegaprotocol/terraform//frontend - name: Publish dist to s3 uses: jakejarvis/s3-sync-action@master # s3 releases are not happening for trading on mainnet - it's IPFS - if: ${{ github.event_name == 'push' && ( matrix.app != 'trading' || (matrix.app == 'trading' && !endsWith(github.ref, 'main') ) ) }} + if: ${{ github.event_name == 'push' && ( matrix.app != 'trading' || (matrix.app == 'trading' && !( endsWith(github.ref, 'main') || endsWith(github.ref, 'release/testnet') ) ) ) }} with: args: --acl private --follow-symlinks --delete env: @@ -235,18 +235,23 @@ jobs: - name: Trigger fleek deployment # release to ipfs happens only on mainnet (represented by main branch) for trading - if: ${{ matrix.app == 'trading' && github.event_name == 'push' && endsWith(github.ref, 'main') }} + if: ${{ matrix.app == 'trading' && github.event_name == 'push' && ( endsWith(github.ref, 'main') || endsWith(github.ref, 'release/testnet') ) }} run: | + if echo ${{ github.ref }} | grep -q main; then + fleek_id='f8f2e051-f18e-49e6-b876-0a39369dc0d8' + elif echo ${{ github.ref }} | grep -q release/testnet; then + fleek_id='79baaeca-1952-4ae7-a256-f668cfc1d68e' + fi # display info about app curl -H "Authorization: ${{ secrets.FLEEK_API_KEY }}" \ -H "Content-Type: application/json" \ - -d '{"query": "query{getSiteById(siteId:\"f8f2e051-f18e-49e6-b876-0a39369dc0d8\"){id latestDeploy{id status}}}"}' \ + -d '{"query": "query{getSiteById(siteId:\"$fleek_id\"){id latestDeploy{id status}}}"}' \ https://api.fleek.co/graphql # trigger new deployment as base image is always set to vegaprotocol/trading:mainnet curl -H "Authorization: ${{ secrets.FLEEK_API_KEY }}" \ -H "Content-Type: application/json" \ - -d '{"query": "mutation{triggerDeploy(siteId:\"f8f2e051-f18e-49e6-b876-0a39369dc0d8\"){id status}}"}' \ + -d '{"query": "mutation{triggerDeploy(siteId:\"$fleek_id\"){id status}}"}' \ https://api.fleek.co/graphql - name: Check out ipfs-redirect @@ -295,3 +300,39 @@ jobs: sleep 5 gh pr merge "${pr_url}" --delete-branch --squash --admin ) + + - name: Update console.fairground.wtf DNS to redirect to the new console + if: ${{ matrix.app == 'trading' && github.event_name == 'push' && endsWith(github.ref, 'testnet') }} + run: | + curl -L https://dist.ipfs.tech/kubo/v0.20.0/kubo_v0.20.0_linux-amd64.tar.gz -o kubo.tgz + tar -xzf kubo.tgz + export PATH="$PATH:$PWD/kubo" + which ipfs + new_hash=$(cat ${{ matrix.app }}-ipfs-hash) + new_cid=$(ipfs cid format -v 1 -b base32 $new_hash) + + # Generate console URL + + new_console_url_type=ipfs + # new_console_url_type=ipns + + new_console_url_domain=cf-ipfs.com + # new_console_url_domain=dweb.link + + new_console_url="https://${new_cid}.${new_console_url_type}.${new_console_url_domain}/" + echo "new_console_url=${new_console_url}" + + # Update record in DNSimple + # docs: https://developer.dnsimple.com/v2/zones/records/#updateZoneRecord + dnsimple_account_id=84895 + dnsimple_zone_name=fairground.wtf + dnsimple_record_id=44571545 + # see: https://dnsimple.com/a/84895/domains/fairground.wtf/records/44571545/edit + curl -H 'Authorization: Bearer ${{ secrets.DNSIMPLE_API_TOKEN }}' \ + -H 'Accept: application/json' \ + -H 'Content-Type: application/json' \ + -X PATCH \ + -d "{ + \"content\": \"${new_console_url}\" + }" \ + https://api.dnsimple.com/v2/${dnsimple_account_id}/zones/${dnsimple_zone_name}/records/${dnsimple_record_id}