Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/dapp-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions dapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 9 additions & 3 deletions dapp/src/decryptEmailContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions dapp/tests/e2e/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion dapp/tests/unit/decryptEmailContent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading