Skip to content

Commit b3b86d9

Browse files
committed
Docker debugging...
1 parent 014742d commit b3b86d9

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

Dockerfile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ FROM base AS nodejs
3232
# Install Node.js and Yarn
3333
ARG NODE_VERSION=23.7.0
3434
ARG YARN_VERSION=4.6.0
35-
ENV PATH=/usr/local/bin:$PATH
35+
ENV PATH=/usr/local/bin:$PATH \
36+
COREPACK_HOME=/root/.cache/corepack
37+
38+
RUN apt-get remove -y yarn || true && \
39+
rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg
3640

3741
RUN case "$(dpkg --print-architecture)" in \
3842
amd64) ARCH='x64' ;; \
3943
arm64) ARCH='arm64' ;; \
4044
*) echo "Unsupported architecture"; exit 1 ;; \
4145
esac \
42-
&& curl -v -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.xz" | tar -xJ -C /usr/local --strip-components=1 \
46+
&& curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.xz" | tar -xJ -C /usr/local --strip-components=1 \
4347
&& npm install -g npm@latest \
48+
&& mkdir -p ${COREPACK_HOME} \
4449
&& corepack enable \
4550
&& corepack prepare yarn@${YARN_VERSION} --activate
4651

@@ -79,18 +84,20 @@ RUN rm -rf node_modules
7984
FROM base
8085

8186
ARG NODE_VERSION=23.7.0
87+
ARG YARN_VERSION=4.6.0
8288

8389
# Set production environment for the host app (railsnew.io)
8490
ENV RAILS_ENV="production" \
8591
BUNDLE_WITHOUT="development:test" \
8692
NODE_VERSION=${NODE_VERSION} \
87-
PATH=/usr/local/bin:$PATH
93+
PATH=/usr/local/bin:$PATH \
94+
COREPACK_HOME=/home/rails/.cache/corepack
8895

8996
# Copy Node.js from nodejs stage
90-
COPY --from=nodejs /usr/local/bin/node /usr/local/bin/
91-
COPY --from=nodejs /usr/local/lib/node_modules/npm /usr/local/lib/node_modules/npm
92-
COPY --from=nodejs /usr/local/bin/npm /usr/local/bin/
93-
COPY --from=nodejs /usr/local/bin/npx /usr/local/bin/
97+
COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
98+
COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
99+
COPY --from=nodejs /usr/local/include/ /usr/local/include/
100+
COPY --from=nodejs /usr/local/share/ /usr/local/share/
94101

95102
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
96103
COPY --from=build /rails /rails
@@ -102,14 +109,24 @@ RUN groupadd --system --gid 1000 rails && \
102109
# Create base directories
103110
mkdir -p /var/lib/rails-new-io/workspaces && \
104111
mkdir -p /var/lib/rails-new-io/rails-env && \
112+
mkdir -p ${COREPACK_HOME} && \
113+
mkdir -p db log storage tmp && \
114+
# Set permissions
105115
chown -R rails:rails /var/lib/rails-new-io && \
106116
chmod -R 755 /var/lib/rails-new-io && \
107117
chown -R rails:rails /rails && \
108118
chmod -R 755 /rails && \
109-
chown -R rails:rails db log storage tmp /usr/local/bundle
119+
chown -R rails:rails db log storage tmp /usr/local/bundle && \
120+
chown -R rails:rails /home/rails/.cache
110121

111122
USER rails
112123

124+
# Set up Yarn
125+
RUN corepack enable && \
126+
corepack prepare yarn@${YARN_VERSION} --activate && \
127+
corepack use yarn@${YARN_VERSION} && \
128+
yarn --version
129+
113130
# Entrypoint prepares the database.
114131
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
115132

bin/docker-entrypoint

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ if [ ! -d "/var/lib/rails-new-io/rails-env/ruby" ] || [ "$FORCE_ISOLATED_RUBY_RE
3838
echo "DEBUG: Copying system Ruby to isolated environment"
3939
cp -a /usr/local/* /var/lib/rails-new-io/rails-env/ruby/
4040

41+
# Overwrite Node.js stuff with our properly configured versions
42+
echo "DEBUG: Overwriting Node.js binaries with symlinks to our configured versions"
43+
rm -f /var/lib/rails-new-io/rails-env/ruby/bin/{node,npm,npx,corepack,yarn,yarnpkg}
44+
rm -rf /var/lib/rails-new-io/rails-env/ruby/lib/node_modules
45+
ln -sf /usr/local/bin/node /var/lib/rails-new-io/rails-env/ruby/bin/
46+
ln -sf /usr/local/bin/npm /var/lib/rails-new-io/rails-env/ruby/bin/
47+
ln -sf /usr/local/bin/npx /var/lib/rails-new-io/rails-env/ruby/bin/
48+
ln -sf /usr/local/bin/corepack /var/lib/rails-new-io/rails-env/ruby/bin/
49+
50+
# Create our own yarn wrapper that bypasses Corepack
51+
echo '#!/bin/bash
52+
echo "DEBUG: yarn called from $(pwd) with args: $@"
53+
echo "DEBUG: PATH=$PATH"
54+
echo "DEBUG: which yarn=$(which yarn)"
55+
echo "DEBUG: readlink -f $(which yarn)=$(readlink -f $(which yarn))"
56+
export COREPACK_ENABLE=0
57+
export NODE_OPTIONS="--no-corepack"
58+
exec "/usr/local/lib/node_modules/yarn/bin/yarn.js" "$@"
59+
' > /var/lib/rails-new-io/rails-env/ruby/bin/yarn
60+
chmod +x /var/lib/rails-new-io/rails-env/ruby/bin/yarn
61+
ln -sf /var/lib/rails-new-io/rails-env/ruby/bin/yarn /var/lib/rails-new-io/rails-env/ruby/bin/yarnpkg
62+
4163
# Run the isolated environment setup in a subshell to avoid polluting the parent environment
4264
(
4365
# Unset any existing bundler environment variables that might interfere
@@ -57,6 +79,9 @@ if [ ! -d "/var/lib/rails-new-io/rails-env/ruby" ] || [ "$FORCE_ISOLATED_RUBY_RE
5779
export BUNDLE_USER_HOME=/var/lib/rails-new-io/rails-env/bundle # Fix: Update path to match CommandExecutionService
5880
export BUNDLE_APP_CONFIG=/var/lib/rails-new-io/rails-env/bundle # Fix: Update path to match CommandExecutionService
5981

82+
# Install Yarn globally first
83+
npm install -g yarn@4.6.0
84+
6085
echo "DEBUG: Updating RubyGems to 3.6.3"
6186
/var/lib/rails-new-io/rails-env/ruby/bin/gem update --system 3.6.3
6287

0 commit comments

Comments
 (0)