Skip to content

Commit

Permalink
fix: escape env variables
Browse files Browse the repository at this point in the history
With this change, we avoid the problem of having to escape env variables
altogether. Previously, env variables were loaded both by bash (in development)
and docker-compose (in production). This meant that we had to deal with
escaping in both contexts, which was the source of trouble. We resolve this by
loading env vars only with bash.

Close #61.
  • Loading branch information
regisb committed Oct 3, 2022
1 parent e2f2e2f commit 497851d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
11 changes: 0 additions & 11 deletions tutormfe/patches/local-docker-compose-dev-services
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,4 @@
tty: true
volumes:
- ../plugins/mfe/apps/mfe/webpack.dev.config.js:/openedx/app/webpack.dev.config.js:ro
env_file:
- ../plugins/mfe/build/mfe/env/production
- ../plugins/mfe/build/mfe/env/development
environment:
- "PORT={{ app['port'] }}"
{%- for key, value in app.get("env", {}).get("production", {}).items() %}
- "{{ key }}={{ value }}"
{% endfor %}
{%- for key, value in app.get("env", {}).get("development", {}).items() %}
- "{{ key }}={{ value }}"
{%- endfor %}
{% endfor %}
31 changes: 23 additions & 8 deletions tutormfe/templates/mfe/build/mfe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,36 @@ COPY --from={{ app["name"] }}-src /openedx/app /openedx/app
COPY --from={{ app["name"] }}-i18n /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages
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
RUN touch /openedx/env/production.override \
{%- for key, value in app.get("env", {}).get("production", {}).items() %}
&& echo "{{ key }}='{{ value }}'" >> /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"
COPY ./env/development /openedx/env/development
RUN touch /openedx/env/development.override \
{%- for key, value in app.get("env", {}).get("development", {}).items() %}
&& echo "{{ key }}='{{ value }}'" >> /openedx/env/development.override \
{%- endfor %}
&& echo "done setting development overrides"

CMD ["/bin/bash", "-c", "set -a && \
source /openedx/env/production && \
source /openedx/env/production.override && \
source /openedx/env/development && \
source /openedx/env/development.override && \
npm run start"]
{% endfor %}

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

######## {{ app["name"] }} (production)
FROM {{ app["name"] }}-dev AS {{ app["name"] }}
RUN bash -c "set -a && \
source /openedx/env/production && \
source /openedx/env/production.override && \
npm run build"

{% endfor %}

Expand Down
2 changes: 1 addition & 1 deletion tutormfe/templates/mfe/build/mfe/env/production
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NODE_ENV=production
PUBLISHER_BASE_URL=
REFRESH_ACCESS_TOKEN_ENDPOINT={% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/login_refresh
SEGMENT_KEY=
SITE_NAME={{ PLATFORM_NAME|replace("'", "'\\''")|replace(" ", "\ ") }}
SITE_NAME="{{ PLATFORM_NAME }}"
STUDIO_BASE_URL={{ "https" if ENABLE_HTTPS else "http" }}://{{ CMS_HOST }}
USER_INFO_COOKIE_NAME=user-info

Expand Down

0 comments on commit 497851d

Please sign in to comment.