From a51a745ab1fadb439f68e339577daeea0c61d089 Mon Sep 17 00:00:00 2001 From: paypes <43441600+abbesBenayache@users.noreply.github.com> Date: Thu, 16 Apr 2026 16:07:26 +0200 Subject: [PATCH] feat(dapp): inject WEB3MAIL_IPFS_GATEWAY from GitHub Environment into image --- .github/workflows/dapp-deploy.yml | 15 +++++++++++++-- dapp/Dockerfile | 2 ++ dapp/src/decryptEmailContent.js | 12 +++++++++--- dapp/tests/e2e/app.test.js | 2 ++ dapp/tests/unit/decryptEmailContent.test.js | 7 ++++++- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dapp-deploy.yml b/.github/workflows/dapp-deploy.yml index 0663dd83..fd62aa42 100644 --- a/.github/workflows/dapp-deploy.yml +++ b/.github/workflows/dapp-deploy.yml @@ -43,14 +43,26 @@ jobs: echo "clean_tag=dev" | tee -a $GITHUB_OUTPUT fi + read-ipfs-gateway: + runs-on: ubuntu-latest + environment: ${{ github.event.inputs.environment }} + outputs: + web3mail_ipfs_gateway: ${{ vars.WEB3MAIL_IPFS_GATEWAY }} + steps: + - name: WEB3MAIL_IPFS_GATEWAY + run: echo "WEB3MAIL_IPFS_GATEWAY=$WEB3MAIL_IPFS_GATEWAY" + env: + WEB3MAIL_IPFS_GATEWAY: ${{ vars.WEB3MAIL_IPFS_GATEWAY }} + docker-publish: uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/docker-build.yml@docker-build-v3.3.0 - needs: [extract-tag] + needs: [extract-tag, read-ipfs-gateway] with: image-name: 'iexechub/web3mail-dapp' registry: 'docker.io' dockerfile: 'dapp/Dockerfile' context: 'dapp' + build-args: WEB3MAIL_IPFS_GATEWAY=${{ needs.read-ipfs-gateway.outputs.web3mail_ipfs_gateway }} security-scan: false hadolint: true push: true @@ -61,7 +73,6 @@ jobs: dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }} dockerhub-password: ${{ secrets.DOCKERHUB_PAT }} - sconify: if: startsWith(github.event.inputs.environment, 'bellecour-') uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/sconify.yml@sconify-v2.0.0 diff --git a/dapp/Dockerfile b/dapp/Dockerfile index 2f0040a1..25439ee8 100644 --- a/dapp/Dockerfile +++ b/dapp/Dockerfile @@ -1,4 +1,6 @@ FROM node:22-alpine3.22 +ARG WEB3MAIL_IPFS_GATEWAY +ENV WEB3MAIL_IPFS_GATEWAY=$WEB3MAIL_IPFS_GATEWAY WORKDIR /app COPY package*.json ./ RUN npm ci --production diff --git a/dapp/src/decryptEmailContent.js b/dapp/src/decryptEmailContent.js index c51eb49d..e588ebf0 100644 --- a/dapp/src/decryptEmailContent.js +++ b/dapp/src/decryptEmailContent.js @@ -2,17 +2,23 @@ const { Buffer } = require('buffer'); const forge = require('node-forge'); const fetch = require('node-fetch'); -const DEFAULT_IPFS_GATEWAY = 'https://ipfs-gateway.v8-bellecour.iex.ec'; +const resolveIpfsGatewayUrl = () => { + const url = process.env.WEB3MAIL_IPFS_GATEWAY; + if (url == null || String(url).trim() === '') { + throw new Error('WEB3MAIL_IPFS_GATEWAY environment variable is not set.'); + } + return String(url).trim(); +}; const downloadEncryptedContent = async ( multiaddr, - { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {} + { ipfsGateway = resolveIpfsGatewayUrl() } = {} ) => { const publicUrl = `${ipfsGateway}${multiaddr}`; const modifiedMultiaddr = publicUrl.replace('/p2p/', '/ipfs/'); const res = await fetch(modifiedMultiaddr); if (!res.ok) { - throw Error(`Failed to load content from ${publicUrl}`); + throw new Error(`Failed to load content from ${publicUrl}`); } const arrayBuffer = await res.arrayBuffer(); return new Uint8Array(arrayBuffer); diff --git a/dapp/tests/e2e/app.test.js b/dapp/tests/e2e/app.test.js index f47480de..b89ecedc 100644 --- a/dapp/tests/e2e/app.test.js +++ b/dapp/tests/e2e/app.test.js @@ -29,6 +29,8 @@ async function cleanOutputs(outputDir) { describe('sendEmail', () => { beforeEach(async () => { // worker env setup + process.env.WEB3MAIL_IPFS_GATEWAY = + 'https://ipfs-gateway.v8-bellecour.iex.ec'; process.env.IEXEC_IN = './tests/_test_inputs_'; process.env.IEXEC_OUT = './tests/_test_outputs_/iexec_out'; // clean IEXEC_OUT diff --git a/dapp/tests/unit/decryptEmailContent.test.js b/dapp/tests/unit/decryptEmailContent.test.js index cdc45428..d9ba0df8 100644 --- a/dapp/tests/unit/decryptEmailContent.test.js +++ b/dapp/tests/unit/decryptEmailContent.test.js @@ -24,9 +24,14 @@ describe('decryptContent', () => { expect(decryptedEmailContent).toEqual(emailContent); }); }); -const DEFAULT_IPFS_GATEWAY = 'https://ipfs-gateway.v8-bellecour.iex.ec'; describe('downloadEncryptedContent', () => { + const DEFAULT_IPFS_GATEWAY = 'https://ipfs-gateway.v8-bellecour.iex.ec'; + + beforeEach(() => { + process.env.WEB3MAIL_IPFS_GATEWAY = DEFAULT_IPFS_GATEWAY; + }); + it('should return the encrypted content', async () => { const content = `{"JSONPath":"$['rates']['GBP']","body":"","dataType":"number","dataset":"0x0000000000000000000000000000000000000000","headers":{},"method":"GET","url":"https://api.exchangerate.host/latest?base=USD&symbols=GBP"}`; const textEncoder = new TextEncoder();