Skip to content

Commit

Permalink
[front] - refactor: reorganize ARG and ENV instructions in Dockerfile
Browse files Browse the repository at this point in the history
 - Move ARG instructions for build arguments to the top of the Dockerfile
 - Declare and echo build arguments before setting them as environment variables
  • Loading branch information
JulesBelveze committed Dec 16, 2024
1 parent ed85d83 commit 740de67
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions front/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ FROM node:20.13.0 AS front

RUN apt-get update && apt-get install -y vim redis-tools postgresql-client htop

ARG COMMIT_HASH
ARG NEXT_PUBLIC_VIZ_URL
ARG NEXT_PUBLIC_GA_TRACKING_ID
ARG NEXT_PUBLIC_DUST_CLIENT_FACING_URL

RUN echo "Build arguments received:" && \
echo "COMMIT_HASH=$COMMIT_HASH" && \
echo "NEXT_PUBLIC_VIZ_URL=$NEXT_PUBLIC_VIZ_URL" && \
echo "NEXT_PUBLIC_GA_TRACKING_ID=$NEXT_PUBLIC_GA_TRACKING_ID" && \
echo "NEXT_PUBLIC_DUST_CLIENT_FACING_URL=$NEXT_PUBLIC_DUST_CLIENT_FACING_URL"

ENV NEXT_PUBLIC_COMMIT_HASH=$COMMIT_HASH
ENV NEXT_PUBLIC_VIZ_URL=$NEXT_PUBLIC_VIZ_URL
ENV NEXT_PUBLIC_GA_TRACKING_ID=$NEXT_PUBLIC_GA_TRACKING_ID
ENV NEXT_PUBLIC_DUST_CLIENT_FACING_URL=$NEXT_PUBLIC_DUST_CLIENT_FACING_URL

WORKDIR /types
COPY /types/package*.json ./
COPY /types/ .
Expand All @@ -21,16 +37,6 @@ RUN npm ci

COPY /front .

ARG COMMIT_HASH
ARG NEXT_PUBLIC_VIZ_URL
ARG NEXT_PUBLIC_GA_TRACKING_ID
ARG NEXT_PUBLIC_DUST_CLIENT_FACING_URL

ENV NEXT_PUBLIC_COMMIT_HASH=$COMMIT_HASH
ENV NEXT_PUBLIC_VIZ_URL=$NEXT_PUBLIC_VIZ_URL
ENV NEXT_PUBLIC_GA_TRACKING_ID=$NEXT_PUBLIC_GA_TRACKING_ID
ENV NEXT_PUBLIC_DUST_CLIENT_FACING_URL=$NEXT_PUBLIC_DUST_CLIENT_FACING_URL

# fake database URIs are needed because Sequelize will throw if the `url` parameter
# is undefined, and `next build` imports the `models.ts` file while "Collecting page data"
RUN FRONT_DATABASE_URI="sqlite:foo.sqlite" npm run build
Expand Down

0 comments on commit 740de67

Please sign in to comment.