Skip to content

Commit 858a9cc

Browse files
authored
Merge pull request #382 from reactioncommerce/fix-378-aldeed-node-modules-conflicts
chore: refactor Docker node_modules linking
2 parents 9a6dbbd + 8fb7ae5 commit 858a9cc

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ jobs:
189189
--env-file docker-cache/.env \
190190
-e "SNYK_TOKEN=$SNYK_TOKEN" \
191191
--name reactionapp_web_1 \
192-
-w /usr/local/src \
193192
"$DOCKER_REPOSITORY:$CIRCLE_SHA1" \
194-
sh -c "cp reaction-app/package.json ./ && cp reaction-app/.snyk ./ && snyk test"
193+
sh -c "snyk test"
195194
196195
publish-npm-package:
197196
docker:

.reaction/yarnrc-docker.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ yarn-offline-mirror-pruning true
1111

1212
--install.cache-folder /home/node/.cache/yarn
1313
--install.ignore-scripts true
14-
--install.modules-folder /usr/local/src/node_modules
1514
--install.prefer-offline true

Dockerfile

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ARG GIT_SHA1
2727
ARG LICENSE
2828

2929
ENV APP_SOURCE_DIR=/usr/local/src/reaction-app \
30-
PATH=$PATH:/usr/local/src/node_modules/.bin
30+
PATH=$PATH:/usr/local/src/reaction-app/node_modules/.bin
3131

3232
LABEL maintainer="Reaction Commerce <[email protected]>" \
3333
com.reactioncommerce.build-date=$BUILD_DATE \
@@ -57,11 +57,18 @@ LABEL maintainer="Reaction Commerce <[email protected]>" \
5757
# Because Docker Compose uses a volume for node_modules and volumes are owned
5858
# by root by default, we have to initially create node_modules here with correct owner.
5959
# Without this Yarn cannot write packages into node_modules later, when running in a container.
60-
RUN mkdir -p "/usr/local/src/node_modules" && chown node "/usr/local/src" && chown node "/usr/local/src/node_modules"
61-
RUN mkdir -p "/usr/local/src/reaction-app/node_modules" && chown node "/usr/local/src/reaction-app" && chown node "/usr/local/src/reaction-app/node_modules"
60+
RUN mkdir -p "/usr/local/src/reaction-app/node_modules"
61+
RUN mkdir -p "/usr/local/src/reaction-app/package/node_modules"
62+
RUN chown node "/usr/local/src"
63+
RUN chown node "/usr/local/src/reaction-app"
64+
RUN chown node "/usr/local/src/reaction-app/node_modules"
65+
RUN chown node "/usr/local/src/reaction-app/package/node_modules"
6266

63-
WORKDIR $APP_SOURCE_DIR/..
64-
COPY --chown=node package.json yarn.lock $APP_SOURCE_DIR/../
67+
WORKDIR $APP_SOURCE_DIR
68+
69+
# Note that the two node_modules directories will not be copied during
70+
# this due to being listed in the `.dockerignore` file.
71+
COPY --chown=node . $APP_SOURCE_DIR
6572

6673
# Build the dependencies into the Docker image in a cacheable way. Dependencies
6774
# are only rebuilt when package.json or yarn.lock is modified.
@@ -75,13 +82,20 @@ RUN set -ex; \
7582
--frozen-lockfile \
7683
--ignore-scripts \
7784
--no-cache; \
85+
cd package && yarn install \
86+
--frozen-lockfile \
87+
--ignore-scripts \
88+
--no-cache; \
7889
elif [ "$BUILD_ENV" = "test" ]; then \
7990
yarn install \
8091
--frozen-lockfile \
8192
--ignore-scripts \
8293
--no-cache; \
83-
fi; \
84-
rm package.json yarn.lock
94+
cd package && yarn install \
95+
--frozen-lockfile \
96+
--ignore-scripts \
97+
--no-cache; \
98+
fi;
8599

86100
# For development, we will yarn install on each container start.
87101
# This ensures that we use our Docker development .yarnrc config
@@ -95,15 +109,6 @@ RUN set -ex; \
95109
# we already ran yarn install above, it doesn't matter.
96110
COPY --chown=node ./.reaction/yarnrc-docker.template /home/node/.yarnrc
97111

98-
WORKDIR $APP_SOURCE_DIR
99-
COPY --chown=node . $APP_SOURCE_DIR
100-
101-
RUN set -ex; \
102-
cd package && yarn install \
103-
--frozen-lockfile \
104-
--ignore-scripts \
105-
--no-cache;
106-
107112
# Important: Make sure we're the "node" user before we begin doing things because
108113
# our tools use "/home/node" as the HOME dir.
109114
USER node

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ services:
1717
- $HOME/.cache/yarn-offline-mirror:/home/node/.cache/yarn-offline-mirror
1818
- web-yarn:/home/node/.cache/yarn
1919
- .:/usr/local/src/reaction-app # link everything from the root folder on the host machine into the container
20-
- empty_node_modules:/usr/local/src/reaction-app/node_modules # except do not link the host node_modules in because it will override the container node_modules
21-
- node_modules:/usr/local/src/node_modules # persist the node_modules that is used, which is up one folder level in the container
20+
- node_modules:/usr/local/src/reaction-app/node_modules # except do not link the host /node_modules in because it will override the container node_modules
21+
- package_node_modules:/usr/local/src/reaction-app/package/node_modules # except do not link the host /package/node_modules in because it will override the container node_modules
2222

2323
volumes:
2424
web-yarn:
25-
empty_node_modules:
2625
node_modules:
26+
package_node_modules:

0 commit comments

Comments
 (0)