Skip to content

Commit

Permalink
Merge pull request #58 from kdmccormick/kdmccormick/dev-build-speed
Browse files Browse the repository at this point in the history
perf: re-order Dockerfile stages to significantly optimize build speed
  • Loading branch information
Adolfo R. Brandes authored Aug 23, 2022
2 parents 0b695b9 + 91cd707 commit 2513088
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tutormfe/templates/mfe/build/mfe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ RUN echo "copying i18n data" \
echo "done."

{% for app in iter_values_named(suffix="MFE_APP") %}

######## {{ app["name"] }} (src)
FROM base AS {{ app["name"] }}-src
RUN git clone {{ app["repository"] }} --branch {{ app.get("version", MFE_COMMON_VERSION) }} --depth 1 .
RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)

######## {{ app["name"] }} (i18n)
FROM base AS {{ app["name"] }}-i18n
COPY --from={{ app["name"] }}-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages
COPY --from=i18n /openedx/i18n/{{ app["name"] }} /openedx/i18n/{{ app["name"] }}
COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js
RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/{{ app["name"] }} /openedx/app/src/i18n/messages

######## {{ app["name"] }} (dev)
FROM base AS {{ app["name"] }}-dev

COPY --from={{ app["name"] }}-src /openedx/app/package.json /openedx/app/package.json
COPY --from={{ app["name"] }}-src /openedx/app/package-lock.json /openedx/app/package-lock.json
ARG NPM_REGISTRY=https://registry.npmjs.org/
Expand All @@ -53,6 +55,11 @@ COPY --from={{ app["name"] }}-i18n /openedx/app/src/i18n/messages /openedx/app/s
ENV PUBLIC_PATH='/{{ app["name"] }}/'
EXPOSE {{ app['port'] }}
CMD ["npm", "run", "start"]

{% endfor %}

{% for app in iter_values_named(suffix="MFE_APP") %}

######## {{ app["name"] }} (production)
FROM {{ app["name"] }}-dev AS {{ app["name"] }}
COPY ./env/production /openedx/env/production
Expand All @@ -62,6 +69,7 @@ RUN touch /openedx/env/production.override \
{%- endfor %}
&& echo "done setting production overrides"
RUN bash -c "set -a && source /openedx/env/production && source /openedx/env/production.override && npm run build"

{% endfor %}

####### final production image with all static assets
Expand Down

0 comments on commit 2513088

Please sign in to comment.