Skip to content

Commit

Permalink
fix(Dockerfile): Do not use environment variables set in other layers
Browse files Browse the repository at this point in the history
In previous Docker versions, the `ENV` directive was scoped to the current
build stage [1]. While this was relaxed by now so that "a stage inherits
any environment variables that were set using ENV by its parent stage or
any ancestor" [2], a stage still cannot expand variables that just were
declared earlier in the file.

The reason why this did not result in a build error is that unset
variables are silently expanded to the quoted empty string ("") which
matches everything.

Fix that bug by hard-coding the paths. This also fixes another bug where
copying from `sbtbuild` used the `DART_SDK` variable.

[1]: moby/moby#37345 (comment)
[2]: https://docs.docker.com/engine/reference/builder/#env

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
  • Loading branch information
sschuberth committed Jul 10, 2023
1 parent d6063fa commit 90fe6b0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Expand Up @@ -196,7 +196,7 @@ RUN rbenv install $RUBY_VERSION -v \
&& gem install bundler cocoapods:$COCOAPODS_VERSION

FROM scratch AS ruby
COPY --from=rubybuild $RBENV_ROOT $RBENV_ROOT
COPY --from=rubybuild /opt/rbenv /opt/rbenv

#------------------------------------------------------------------------
# NODEJS - Build NodeJS as a separate component with nvm
Expand All @@ -219,7 +219,7 @@ RUN . $NVM_DIR/nvm.sh \
&& npm install --global npm@$NPM_VERSION bower@$BOWER_VERSION pnpm@$PNPM_VERSION yarn@$YARN_VERSION

FROM scratch AS node
COPY --from=nodebuild $NVM_DIR $NVM_DIR
COPY --from=nodebuild /opt/nvm /opt/nvm

#------------------------------------------------------------------------
# RUST - Build as a separate component
Expand Down Expand Up @@ -270,7 +270,7 @@ ENV PATH=$PATH:$HASKELL_HOME/bin
RUN curl -sSL https://get.haskellstack.org/ | bash -s -- -d $HASKELL_HOME/bin

FROM scratch AS haskell
COPY --from=haskellbuild $HASKELL_HOME $HASKELL_HOME
COPY --from=haskellbuild /opt/haskell /opt/haskell

#------------------------------------------------------------------------
# REPO / ANDROID SDK
Expand Down Expand Up @@ -302,7 +302,7 @@ RUN curl -ksS https://storage.googleapis.com/git-repo-downloads/repo | tee $ANDR
&& sudo chmod a+x $ANDROID_HOME/cmdline-tools/bin/repo

FROM scratch AS android
COPY --from=androidbuild $ANDROID_HOME $ANDROID_HOME
COPY --from=androidbuild /opt/android-sdk /opt/android-sdk

#------------------------------------------------------------------------
# Dart
Expand All @@ -322,7 +322,7 @@ RUN --mount=type=tmpfs,target=/dart \
&& unzip /dart/dart.zip

FROM scratch AS dart
COPY --from=dartbuild $DART_SDK $DART_SDK
COPY --from=dartbuild /opt/dart-sdk /opt/dart-sdk

#------------------------------------------------------------------------
# SBT
Expand All @@ -336,7 +336,7 @@ ENV PATH=$PATH:$SBT_HOME/bin
RUN curl -L https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz | tar -C /opt -xz

FROM scratch AS sbt
COPY --from=sbtbuild $DART_SDK $DART_SDK
COPY --from=sbtbuild /opt/sbt /opt/sbt

#------------------------------------------------------------------------
# ORT
Expand Down

0 comments on commit 90fe6b0

Please sign in to comment.