Skip to content

Commit

Permalink
chore: Fix CocoaPods install on Linux (MetaMask#9545)
Browse files Browse the repository at this point in the history
- Enable `pod install` step in `yarn setup` script on all platforms
- Failing installation is still only treated as actual failure on macOS
- Apply `react-native` patch that resolves installation error due to
attempt at patching missing Xcode
  - Upstream PR: facebook/react-native#44417
- Add developer `Dockerfile` which can be used locally to run routine
development tasks like `yarn setup`.
- Add CI job that builds docker image and tests it with metamask-mobile
- In order for the new job to run, the newly used actions must be
enabled in repository settings.
legobeat authored May 29, 2024
1 parent c648912 commit a788661
Showing 6 changed files with 166 additions and 4 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: docker
on:
push:
branches: main
pull_request:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- uses: actions/checkout@v3

- name: Build and load
uses: docker/build-push-action@v5
with:
context: .
file: scripts/docker/Dockerfile
# test with nonstandard uid and gid
build-args: |
UID=1234
GID=1235
load: true
tags: metamask-mobile-builder:latest
# could enable push to gh registry
push: false
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test yarn setup
run: |
sudo chown -R 1234:1235 .
docker run \
--rm \
-v "$(pwd):/app" -w /app \
metamask-mobile-builder:latest \
bash -c 'yarn && yarn setup --build-ios'
# restore ownership for cleanup
sudo chown -R "$(id -u):$(id -g)" .
19 changes: 17 additions & 2 deletions patches/react-native+0.71.15.patch
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ index 1379ffd..f2825f5 100644
// We could just call GlobalPerformanceLogger.markPoint at the top of the file,
diff --git a/node_modules/react-native/Libraries/Core/setUpSes.js b/node_modules/react-native/Libraries/Core/setUpSes.js
new file mode 100644
index 0000000..6013411
index 0000000..5dc1859
--- /dev/null
+++ b/node_modules/react-native/Libraries/Core/setUpSes.js
@@ -0,0 +1,60 @@
@@ -237,4 +237,19 @@ index 290bd23..20d85e0 100644
+ }
}
return inputConnection;
}
}
diff --git a/node_modules/react-native/scripts/react_native_pods.rb b/node_modules/react-native/scripts/react_native_pods.rb
index 78b187a..d9d0be5 100644
--- a/node_modules/react-native/scripts/react_native_pods.rb
+++ b/node_modules/react-native/scripts/react_native_pods.rb
@@ -224,7 +224,9 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer)
ReactNativePodsUtils.fix_library_search_paths(installer)
ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path)
- ReactNativePodsUtils.apply_xcode_15_patch(installer)
+ if Environment.new().ruby_platform().include?('darwin')
+ ReactNativePodsUtils.apply_xcode_15_patch(installer)
+ end
ReactNativePodsUtils.updateIphoneOSDeploymentTarget(installer)

NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
64 changes: 64 additions & 0 deletions scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# syntax=docker/dockerfile:1.4
FROM node:20-bookworm

RUN apt-get update \
&& apt-get install -y \
git curl jq time \
sudo locales \
build-essential ccache cmake cmake-format distcc \
&& sed -i '/en_US.UTF-8/s/^# //' /etc/locale.gen \
&& locale-gen

ENV YARN_VERSION 1.22.22
# replace base image yarn 1.19
# checksums and sigs for 1.22 not available as of now...
# https://github.com/nodejs/docker-node/blob/07bd7414c9eeb7a134951122e1105e8c849f770e/Dockerfile-debian.template
COPY scripts/docker/yarn-v$YARN_VERSION.tar.gz.sha256 .
RUN curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
&& sha256sum yarn-v$YARN_VERSION.tar.gz.sha256 \
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
&& ln -sf /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
&& ln -sf /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
&& rm yarn-v$YARN_VERSION.tar.gz.sha256 yarn-v$YARN_VERSION.tar.gz \
&& yarn --version

ARG UID=1000
ARG GID=1000
# if UID differs from default: create new user/group; take over /home/node
RUN bash -c "[ ${GID} != \"1000\" ] && groupadd -g ${GID} -U node userz || true" \
&& bash -c "[ ${UID} != \"1000\" ] && useradd -u ${UID} -g ${GID} -d /home/node user && chown -R ${UID}:${GID} /home/node || true" \
&& usermod -G sudo -a $(id -un ${UID}) \
&& echo '%sudo ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

# install ruby deps
COPY --chown=${UID}:${GID} Gemfile* .ruby-version /tmp/app/
WORKDIR /tmp/app

####
USER $UID:$GID
ENV BUNDLE_PATH=/home/node/.bundle
ENV HOME=/home/node
# distro rbenv and ruby are out of date - install rbenv from git and manage ruby
# RUBY_BUILD_VERSION=v20240501
ARG RBENV_COMMIT=c3ba994ec2daccf4d160aea7f55dd5cc6fc873ef
ARG RUBY_BUILD_COMMIT=263640c9fe1d44e6fc8f86fc56a67ee58e7b22f7
RUN (mkdir /home/node/.rbenv \
&& curl -sL https://github.com/rbenv/rbenv/archive/${RBENV_COMMIT}.tar.gz \
| tar --strip-components=1 -C /home/node/.rbenv/ -xzf - \
) && (mkdir -p /home/node/.rbenv/plugins/ruby-build \
&& curl -sL https://github.com/rbenv/ruby-build/archive/${RUBY_BUILD_COMMIT}.tar.gz \
| tar --strip-components=1 -C /home/node/.rbenv/plugins/ruby-build -xzf - \
) \
&& echo 'eval "$(/home/node/.rbenv/bin/rbenv init -)"' >> /home/node/.bashrc

RUN bash -c 'eval "$(/home/node/.rbenv/bin/rbenv init -)" \
&& rbenv install \
&& gem install bundler -v 2.5.8 \
&& gem install bigdecimal cocoapods \
&& bundle install'

# fix broken ipv6 on nodejs v20
env NODE_OPTIONS="--no-network-family-autoselection --trace-warnings"
env PATH=/home/node/.rbenv/shims/:$PATH

WORKDIR /app
38 changes: 38 additions & 0 deletions scripts/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
The Dockerfile in this directory is intended for local dev.

It has a `docker.io/node` debian base, with MetaMask Mobile build dependencies installed and sudo for the default user enabled.

## Using
### Building
```
$ docker buildx build --pull --build-arg UID=$(id -u) --build-arg GID=$(id -g) -t mm-mobile-build:debian -f scripts/docker/Dockerfile .
```

### Running
```
$ docker run --rm -it \
-u $(id -u) \
-v "$(pwd)":/app -w /app \
mm-mobile-build:debian \
/bin/bash
# To reuse host yarn cache
$ docker run --rm -it \
-u $(id -u) \
-v "$(pwd)":/app -w /app \
-v ~/.cache/yarn:/home/node/.cache/yarn \
mm-mobile-build:debian \
/bin/bash
# shell inside container
$ yarn setup --build-ios
```

### Filesystem permissions
Building the image locally maps the default user UID and GID to the `UID` and `GID` build-args (default `1000`). This means that when you run and mount the image with your local git repository with the same owner, permissions will map semlessly.
You may need to adjust the `--build-arg UID=` and `--build-arg GID=` flags in the following cases:

- The UID/GID of the user running the image is different from the one building it
- You are running rootless docker or podman
- You are getting filesystem permission errors when running the image
- You are using some exotic container runtime
1 change: 1 addition & 0 deletions scripts/docker/yarn-v1.22.22.tar.gz.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
88268464199d1611fcf73ce9c0a6c4d44c7d5363682720d8506f6508addf36a0 yarn-v1.22.22.tar.gz
4 changes: 2 additions & 2 deletions scripts/setup.mjs
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ const mainSetupTask = {
title: 'Dependencies setup',
task: (_, task) => task.newListr([
{
title: 'Install iOS Pods',
title: 'Install CocoaPods',
task: async (_, podInstallTask) => {
if (!BUILD_IOS) {
return podInstallTask.skip('Skipping iOS.')
@@ -205,9 +205,9 @@ const patchModulesTask = {
}
const tasks = new Listr([
gemInstallTask,
patchModulesTask,
mainSetupTask,
ppomBuildTask,
patchModulesTask
],
{
exitOnError: true,

0 comments on commit a788661

Please sign in to comment.