From 7439ddc2821a780fdd0a795cb77f6bbc1b751bcc Mon Sep 17 00:00:00 2001 From: Pedro Rezende Date: Mon, 16 Dec 2024 16:51:15 -0300 Subject: [PATCH 1/4] feat(extension): docker image and build instructions for firefox --- apps/extension/FIREFOX_README.md | 52 ++++++++------------------------ docker/extension/Dockerfile | 30 ++++++++++++++++++ 2 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 docker/extension/Dockerfile diff --git a/apps/extension/FIREFOX_README.md b/apps/extension/FIREFOX_README.md index 783c98913c..cc8191f879 100644 --- a/apps/extension/FIREFOX_README.md +++ b/apps/extension/FIREFOX_README.md @@ -13,44 +13,25 @@ exactly as they are described below. ## Build instructions -**NOTE**: You _must_ use `yarn` to install dependencies! This is due to the fact that this is configured as a monorepo -using yarn workspaces. If you install via `npm install` or `npm i`, it will not resolve dependencies correctly. - -If you don't already have Node v22 LTS and NPM v10, please follow these [instructions](#setting-up-node-and-npm) - -These instructions should work for the default reviewer build environment. +1. Certify that Docker 27+ is installed in your system before proceeding with the build: ```bash -sudo apt install protobuf-compiler build-essential curl pkg-config libssl-dev binaryen -y -curl https://sh.rustup.rs -sSf | sh - -# Proceed with standard installation when prompted - -# Make sure to pull cargo into your current environment: -. "$HOME/.cargo/env" - -# You must use yarn to install dependencies: -npm install -g yarn -export PUPPETEER_SKIP_DOWNLOAD=true - -# Run yarn to install dependencies -yarn +docker --version +``` -# Move into extension app directory -cd apps/extension +2. From the **repository root**, build the Docker image: -# Build wasm dependency: -yarn wasm:build +```bash +docker build . -t namada-keychain -f docker/extension/Dockerfile ``` -Then, issue the final build command for the Firefox add-on: +3. Wait for the build to complete, and then copy the files from the container by executing the following command in the **repository root**: ```bash -# Build the addon: -yarn build:firefox +docker run --rm -v ./apps/extension/build:/shared namada-keychain cp -r /app/apps/extension/build/. /shared/ ``` -The resulting extension is the ZIP file in `apps/extension/build/firefox`. +4. The resulting extension is the ZIP file in `apps/extension/build/firefox`. [ [Table of Contents](#table-of-contents) ] @@ -63,25 +44,16 @@ This build was produced using the following environment: - Ubuntu 24.04 LTS (Desktop edition) - 10GB of system memory (RAM) - 6 cores of vCPU -- Node 22 LTS and npm 10 - 35GB of storage +- Docker version 27+ installed and running Please ensure that this matches your environment! [ [Table of Contents](#table-of-contents) ] -### Setting up Node and NPM - -```bash -wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash - -# Enable nvm in current shell -export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +### Installing Docker -# Install v22 LTS -nvm install v22.0.0 -``` +If Docker is not currently installed in your environment, please refer to the [instructions of the official Docker documentation](https://docs.docker.com/engine/install/ubuntu/). [ [Table of Contents](#table-of-contents) ] diff --git a/docker/extension/Dockerfile b/docker/extension/Dockerfile new file mode 100644 index 0000000000..8968c201fa --- /dev/null +++ b/docker/extension/Dockerfile @@ -0,0 +1,30 @@ +FROM rust:1.79 AS builder + +WORKDIR /app + +# Installing required packages +RUN apt update && apt install -y nodejs npm clang pkg-config libssl-dev protobuf-compiler curl +RUN npm install -g yarn +RUN rustup target add wasm32-unknown-unknown +RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -y + +# Copying packages and scripts related to the monorepo +COPY .yarnrc.yml tsconfig.base.json package.json yarn.lock . +COPY ./.yarn ./.yarn +COPY ./packages ./packages +COPY ./scripts ./scripts +COPY ./apps/extension/package.json ./apps/extension/package.json + +# Installing packages +RUN yarn +WORKDIR /app/apps/extension + +# Building wasm files +COPY ./apps/extension/scripts ./scripts +RUN yarn wasm:build + +# Building extension dist files +COPY ./apps/extension . +RUN yarn +RUN yarn build + From 00b07786f770d58e272bf0c2947ee5faa27297a2 Mon Sep 17 00:00:00 2001 From: Pedro Rezende Date: Tue, 17 Dec 2024 11:53:01 -0300 Subject: [PATCH 2/4] feat(firefox): separating build in different stages and updating docs --- apps/extension/FIREFOX_README.md | 4 ++-- docker/extension/Dockerfile | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/extension/FIREFOX_README.md b/apps/extension/FIREFOX_README.md index cc8191f879..63e4cfa2a8 100644 --- a/apps/extension/FIREFOX_README.md +++ b/apps/extension/FIREFOX_README.md @@ -22,13 +22,13 @@ docker --version 2. From the **repository root**, build the Docker image: ```bash -docker build . -t namada-keychain -f docker/extension/Dockerfile +docker build . --target firefox -t namada-keychain-firefox -f docker/extension/Dockerfile ``` 3. Wait for the build to complete, and then copy the files from the container by executing the following command in the **repository root**: ```bash -docker run --rm -v ./apps/extension/build:/shared namada-keychain cp -r /app/apps/extension/build/. /shared/ +docker run --rm -v ./apps/extension/build:/shared namada-keychain-firefox cp -r /app/apps/extension/build/. /shared/ ``` 4. The resulting extension is the ZIP file in `apps/extension/build/firefox`. diff --git a/docker/extension/Dockerfile b/docker/extension/Dockerfile index 8968c201fa..2ddc3cd6b6 100644 --- a/docker/extension/Dockerfile +++ b/docker/extension/Dockerfile @@ -26,5 +26,11 @@ RUN yarn wasm:build # Building extension dist files COPY ./apps/extension . RUN yarn -RUN yarn build + +FROM builder AS firefox +RUN yarn build:firefox + +FROM builder AS chrome +RUN yarn build:chrome + From 96ef06f43986363b85aa9f5c592602fbcb5da432 Mon Sep 17 00:00:00 2001 From: Pedro Rezende Date: Tue, 17 Dec 2024 14:25:37 -0300 Subject: [PATCH 3/4] feat: ensure amd64 architecture --- docker/extension/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/extension/Dockerfile b/docker/extension/Dockerfile index 2ddc3cd6b6..7fa5495d1d 100644 --- a/docker/extension/Dockerfile +++ b/docker/extension/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.79 AS builder +FROM --platform=linux/amd64 rust:1.79 AS builder WORKDIR /app From d7937d0798b3beb46a91c86b8b23d65693bc7d22 Mon Sep 17 00:00:00 2001 From: Pedro Rezende Date: Tue, 17 Dec 2024 17:18:47 -0300 Subject: [PATCH 4/4] feat: tweaking options on webpack --- apps/extension/webpack.config.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/extension/webpack.config.js b/apps/extension/webpack.config.js index 26e242d706..af267d0673 100644 --- a/apps/extension/webpack.config.js +++ b/apps/extension/webpack.config.js @@ -13,12 +13,7 @@ const { getProcessEnv } = require("@namada/config/webpack.js"); // Load .env from namadillo: require("dotenv").config({ path: "./.env" }); -const { - NODE_ENV, - TARGET, - BUNDLE_ANALYZE, - BETA_RELEASE: isBeta, -} = process.env; +const { NODE_ENV, TARGET, BUNDLE_ANALYZE, BETA_RELEASE: isBeta } = process.env; const OUTPUT_PATH = resolve(__dirname, `./build/${TARGET}`); const MANIFEST_VERSION = TARGET === "firefox" ? "v2" : "v3"; @@ -159,6 +154,8 @@ module.exports = { path: OUTPUT_PATH, //TODO: this might lead to problems with caching filename: "[name].namada.js", + chunkFilename: "[id].[contenthash].js", + hashFunction: "xxhash64", }, module: { rules: [ @@ -166,7 +163,9 @@ module.exports = { test: /\.tsx?$/, loader: "ts-loader", exclude: /node_modules/, - options: {}, + options: { + happyPackMode: false, // Ensure single-threaded processing + }, }, { test: /\.css$/i, @@ -226,4 +225,9 @@ module.exports = { // We want to ignore wasm-bindgen-rayon circular dependency warning warningsFilter: [/dependency between chunks.+wasm-bindgen-rayon/], }, + optimization: { + minimize: false, + moduleIds: "deterministic", // Ensures consistent module IDs + chunkIds: "deterministic", // Ensures consistent chunk IDs + }, };