From e20fcc1fa2280ce7451584f6609bd245119b6f32 Mon Sep 17 00:00:00 2001 From: Jubal Mabaquiao Date: Thu, 29 Feb 2024 15:50:34 +0800 Subject: [PATCH 1/3] update ipfs deploy workflow --- .github/workflows/ipfs-deploy.yml | 97 +++++++++++++++++++++++++++++-- Dockerfile | 93 +++++++++++++++++++++++++---- 2 files changed, 174 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ipfs-deploy.yml b/.github/workflows/ipfs-deploy.yml index 3ed126ed8e2..f2750f87cde 100644 --- a/.github/workflows/ipfs-deploy.yml +++ b/.github/workflows/ipfs-deploy.yml @@ -1,7 +1,12 @@ -name: IPFS deploy +name: Build and Push to IPFS + on: - workflow_dispatch: push: + # Publish `master` as Docker `latest` image. + branches: + - master + + # Publish `v1.2.3` tags as releases. tags: - 'v\d+' @@ -10,10 +15,12 @@ env: REGISTRY: ghcr.io jobs: - deploy-to-prod: + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: runs-on: ubuntu-latest - environment: - name: deploy/prod + if: github.event_name == 'push' + steps: - uses: actions/checkout@v2 @@ -22,7 +29,7 @@ jobs: - name: Build image run: | - docker build . --file Dockerfile --tag $IMAGE_TAG + docker build --file Dockerfile --tag $IMAGE_TAG . # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Log in to the Container registry @@ -50,3 +57,81 @@ jobs: docker tag $IMAGE_TAG $IMAGE_ID:$VERSION docker push $IMAGE_ID:$VERSION + + # Make image reference available to subsequent steps + echo "IMAGE_RELEASE_ID=$(echo $IMAGE_ID:$VERSION)" >> $GITHUB_ENV + + # Run docker image script to publish app to nft.storage + - name: Publish to nft.storage + run: | + docker run -e NFTSTORAGE_API_KEY=${{ secrets.NFTSTORAGE_API_KEY }} $IMAGE_RELEASE_ID nft.storage + + - name: Create a reference for IPFS hash + if: github.ref_type == 'tag' + run: | + echo "IPFS_HASH=$(docker run --entrypoint /bin/sh $IMAGE_RELEASE_ID -c 'cat /ipfs_hash.txt')" >> $GITHUB_ENV + + - name: Create a release + if: github.ref_type == 'tag' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Markdown template for the release notes + RELEASE_NOTE_TEMPLATE=$(cat << EOF + #### IPFS Hash + + \`\`\` + $IPFS_HASH + \`\`\` + + You can view published versions of Horswap through any IPFS Gateway + + [ipfs://$IPFS_HASH](ipfs://$IPFS_HASH) __(Recommended)__ + _requires Brave Browser or IPFS Desktop_ + [https://$IPFS_HASH.ipfs.nftstorage.link](https://$IPFS_HASH.ipfs.nftstorage.link) + [https://$IPFS_HASH.ipfs.zoltu.io](https://$IPFS_HASH.ipfs.zoltu.io) + [https://$IPFS_HASH.ipfs.keydonix.com](https://$IPFS_HASH.ipfs.keydonix.com) + [https://$IPFS_HASH.ipfs.cf-ipfs.com](https://$IPFS_HASH.ipfs.cf-ipfs.com) + [https://$IPFS_HASH.ipfs.w3s.link](https://$IPFS_HASH.ipfs.w3s.link) + EOF + ) + + # Generate payload for creating a new release + PAYLOAD_TEMPLATE=$(cat < ipfs_hash.txt -# Copy build output -COPY --from=builder /source/build /export +# -------------------------------------------------------- +# Publish Script: Option to host app locally or on nft.storage +# -------------------------------------------------------- + +WORKDIR ~ +COPY <<'EOF' /entrypoint.sh +#!/bin/sh +set -e + +if [ $# -ne 1 ]; then + echo "Example usage: docker run --rm ghcr.io/darkflorist/horswap:latest [docker-host|nft.storage]" + exit 1 +fi + +case $1 in + + docker-host) + # Show the IFPS build hash + echo "Build Hash: $(cat /ipfs_hash.txt)" + + # Determine the IPV4 address of the docker-hosted IPFS instance + IPFS_IP4_ADDRESS=$(getent ahostsv4 host.docker.internal | grep STREAM | head -n 1 | cut -d ' ' -f 1) + + echo "Adding files to docker running IPFS at $IPFS_IP4_ADDRESS" + IPFS_HASH=$(ipfs add --api /ip4/$IPFS_IP4_ADDRESS/tcp/5001 --cid-version 1 --quieter -r /export) + echo "Uploaded Hash: $IPFS_HASH" + ;; + + nft.storage) + if [ -z $NFTSTORAGE_API_KEY ] || [ $NFTSTORAGE_API_KEY = "" ]; then + echo "NFTSTORAGE_API_KEY environment variable is not set"; + exit 1; + fi + + # Show the IFPS build hash + echo "Build Hash: $(cat /ipfs_hash.txt)" + + # Create a CAR archive from build hash + echo "Uploading files to nft.storage..." + IPFS_HASH=$(ipfs add --cid-version 1 --quieter -r /export) + ipfs dag export $IPFS_HASH > output.car + + # Upload the entire directory to nft.storage + UPLOAD_RESPONSE=$(curl \ + --request POST \ + --header "Authorization: Bearer $NFTSTORAGE_API_KEY" \ + --header "Content-Type: application/car" \ + --data-binary @output.car \ + --silent \ + https://api.nft.storage/upload) + + # Show link to nft.storage (https://xxx.ipfs.nftstorage.link) + UPLOAD_SUCCESS=$(echo "$UPLOAD_RESPONSE" | jq -r ".ok") -# add the build output to IPFS and write the hash to a file -RUN ipfs add --cid-version 1 --quieter --only-hash --recursive /export > ipfs_hash.txt + if [ "$UPLOAD_SUCCESS" = "true" ]; then + echo "Succesfully uploaded to https://"$(echo "$UPLOAD_RESPONSE" | jq -r ".value.cid")".ipfs.nftstorage.link" + else + echo "Upload Failed: " $(echo "$UPLOAD_RESPONSE" | jq -r ".error | @json") + fi + ;; -# print the hash for good measure in case someone is looking at the build logs -RUN cat ipfs_hash.txt + *) + echo "Invalid option: $1" + echo "Example usage: docker run --rm ghcr.io/darkflorist/horswap:latest [docker-host|nft.storage]" + exit 1 + ;; +esac +EOF -# this entrypoint file will execute `ipfs add` of the build output to the docker host's IPFS API endpoint, so we can easily extract the IPFS build out of the docker image -RUN printf '#!/bin/sh\nipfs --api /ip4/`getent ahostsv4 host.docker.internal | grep STREAM | head -n 1 | cut -d \ -f 1`/tcp/5001 add --cid-version 1 -r /export' >> entrypoint.sh -RUN chmod u+x entrypoint.sh +RUN chmod u+x /entrypoint.sh -ENTRYPOINT [ "./entrypoint.sh" ] +ENTRYPOINT [ "/entrypoint.sh" ] From b32433cf243983f2b0113f7f519d515ed522a53a Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 5 Mar 2024 14:03:48 +0200 Subject: [PATCH 2/3] update hashes --- .../view/__snapshots__/EmptyWalletContent.test.tsx.snap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nft/components/profile/view/__snapshots__/EmptyWalletContent.test.tsx.snap b/src/nft/components/profile/view/__snapshots__/EmptyWalletContent.test.tsx.snap index 0f3bfb6f8fe..3d9041e34b5 100644 --- a/src/nft/components/profile/view/__snapshots__/EmptyWalletContent.test.tsx.snap +++ b/src/nft/components/profile/view/__snapshots__/EmptyWalletContent.test.tsx.snap @@ -88,7 +88,7 @@ exports[`EmptyWalletContent.tsx matches base snapshot 1`] = ` />
No NFTs yet
@@ -128,7 +128,7 @@ exports[`EmptyWalletContent.tsx matches base snapshot 1`] = ` />
No tokens yet
@@ -174,7 +174,7 @@ exports[`EmptyWalletContent.tsx matches base snapshot 1`] = ` />
No activity yet
@@ -209,7 +209,7 @@ exports[`EmptyWalletContent.tsx matches base snapshot 1`] = ` />
No pools yet
From 3bbf12bdb0a998ada78cee214df59348cd93dbad Mon Sep 17 00:00:00 2001 From: Jubal Mabaquiao Date: Wed, 6 Mar 2024 00:56:39 +0800 Subject: [PATCH 3/3] Update .github/workflows/ipfs-deploy.yml Co-authored-by: KillariDev <13102010+KillariDev@users.noreply.github.com> --- .github/workflows/ipfs-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ipfs-deploy.yml b/.github/workflows/ipfs-deploy.yml index f2750f87cde..756cded6794 100644 --- a/.github/workflows/ipfs-deploy.yml +++ b/.github/workflows/ipfs-deploy.yml @@ -6,7 +6,7 @@ on: branches: - master - # Publish `v1.2.3` tags as releases. + # Publish `v1` tags as releases. tags: - 'v\d+'