`process.env.IS_PULL_REQUEST` doesn't seem to be set to `true` inside Docker build process

We’re using Docker on our Elixir + Svelte/Rollup setup. This is the code I use to configure our apollo client with the relevant API URL:

const isPr = `${process.env.IS_PULL_REQUEST}` == "true"
const apiUrlOverride = `${process.env.OUR_APP_GRAPHQL_URL}` != "undefined"

const apiUrl =
  apiUrlOverride ? `${process.env.OUR_APP_GRAPHQL_URL}` :
  !production ? 'http://localhost:4000/api' :
  isPr        ? `${process.env.RENDER_EXTERNAL_URL}/api` :
                'https://ourapp.app/api';

We’re getting CORS errors in the Broswer console on PR preview instances saying that our apollo client is configured with https://ourapp.app/api.

I did some tests in the node repl via the shell, and the output looks fine, which is leading me to conclude that the process.env.IS_PULL_REQUEST is evaluating to 'false' when the app is being built inside Docker.

> process.env.RENDER_EXTERNAL_URL
'https://ourapp-pr-114.onrender.com'

> process.env.IS_PULL_REQUEST
'true'

> const isPr = `${process.env.IS_PULL_REQUEST}` == "true"
undefined

> isPr
true

>   isPr  ? `${process.env.RENDER_EXTERNAL_URL}/api` : 'https://ourapp.app/api'
'https://ourapp-pr-114.onrender.com/api'

EDIT: I should add that without a solution for this it makes it impossible for us to do meaningful QA on PR preview instances.

Hey Ben,

Environment variables are passed in as build-args for Docker environments. You will need to set the value in your Dockerfile with ARG/ENV in order to use it in the build context.

2 Likes

@jake it doesn’t seem to work.

Here is my dockerfile.

FROM node:lts
ARG DB_URL
ARG API_URL
ARG NEXT_PUBLIC_INFURA_KEY


ENV CI=true
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
ENV DB_URL=$DB_URL
ENV API_URL=$API_URL

All and args are empty and next RUN commands I have are failing because of that. Locally on my machine everything works fine.

no matter if I have it in service envs or in shared envs it doesn’t work.

HI Andrey,

I’m not seeing that issue on a test repo I tried.

If you could share a specific example of the issue you are experiencing that may help us troubleshoot it with you, e.g. any logs/errors/output, service name/ID, reproduction steps, etc.

As this is a very old post, it might be better to start a new topic that info. Alternatively, if you don’t want to share those details on the community forum, please feel free to raise a ticket with support@render.com

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.