I’ve a simple Dockerfile containing an Angular build:
FROM node:alpine AS build-env WORKDIR /app ARG BUILD_COMMAND COPY package.json ./ COPY package-lock.json ./ RUN npm i COPY projects ./projects COPY config ./config COPY angular.json ./ COPY tsconfig.json ./ COPY tailwind.config.js ./ RUN $BUILD_COMMAND
As you can see, I’ve an ARG to run a certain build command that will be a bit different depending on deploying to production or staging environment.
Locally, when I test the Dockerfile, I run:
docker build --build-arg "BUILD_COMMAND=npm run build:prod" -t frontend .
It works as expected.
The Render documentation then tells me:
- Automatic translation of environment variables to Docker build args.
As I understand this, I can simply set up an environment variable and use it as a build arg in my Dockerfile.
Therefore, I’ve setup the environment variable like this:
But when I run a deployment, the following log is outputted:
Oct 4 04:04:41 PM #19 [build-env 10/11] COPY tailwind.config.js ./ Oct 4 04:04:41 PM #19 DONE 0.1s Oct 4 04:04:41 PM Oct 4 04:04:41 PM #20 [build-env 11/11] RUN $BUILD_COMMAND Oct 4 04:04:41 PM #20 DONE 0.2s Oct 4 04:04:41 PM Oct 4 04:04:41 PM #21 [stage-1 3/4] COPY --from=build-env /app/dist/smudgy /usr/share/nginx/html Oct 4 04:04:41 PM #21 ERROR: failed to calculate checksum of ref u1af40o4ezjdscs8wd738ils6::mn7wero8o7q9bempjeowvxorf: failed to walk /home/user/.local/tmp/buildkit-mount2121883536/app/dist: lstat /home/user/.local/tmp/buildkit-mount2121883536/app/dist: no such file or directory Oct 4 04:04:41 PM ------ Oct 4 04:04:41 PM > [stage-1 3/4] COPY --from=build-env /app/dist/smudgy /usr/share/nginx/html: Oct 4 04:04:41 PM ------ Oct 4 04:04:41 PM Dockerfile:24
It looks like the arg BUILD_COMMAND has not been set. Not sure, if I should see that in the build log, but I can tell from the running duration of the command that I was not executed properly.
As said, it works locally on my machine when setting the build arg.
Any idea what I’m missing to make it work on render?