1

This is my simple Dockerfile. The issue is SCALA_VERSION variable in the line wget -q --no-cookies ... does not get interpolated. I am not sure how to fix that. I appreciate any help or hint.

ARG SCALA_MAJOR_VERSION="2.13"
ARG SCALA_MINOR_VERSION="7"
ARG SCALA_VERSION="$SCALA_MAJOR_VERSION.$SCALA_MINOR_VERSION"

FROM openjdk:18-jdk-alpine AS base
LABEL version="$SCALA_VERSION"

WORKDIR /usr/lib

RUN apk add --no-cache bash \
  && apk add --no-cache --virtual=build-dependencies wget ca-certificates \
  && wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x \
  && apk del build-dependencies \
  && rm -rf /tmp/*

Logs:

➜  compiler-toolchain git:(master) ✗ docker build . -t cool
Sending build context to Docker daemon  16.54MB
Step 1/18 : ARG SCALA_MAJOR_VERSION="2.13"
Step 2/18 : ARG SCALA_MINOR_VERSION="7"
Step 3/18 : ARG SCALA_VERSION="$SCALA_MAJOR_VERSION.$SCALA_MINOR_VERSION"
Step 4/18 : FROM openjdk:18-jdk-alpine AS base
 ---> c89120dcca4c
Step 5/18 : LABEL maintainer="[email protected]"
 ---> Using cache
 ---> eb84f71065ca
Step 6/18 : LABEL version="$SCALA_VERSION"
 ---> Using cache
 ---> 23f11d22b6cb
Step 7/18 : WORKDIR /usr/lib
 ---> Using cache
 ---> 8762269e3700
Step 8/18 : RUN apk add --no-cache bash   && apk add --no-cache --virtual=build-dependencies wget ca-certificates   && wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x   && apk del build-dependencies   && rm -rf /tmp/*
 ---> Running in 0cc02cf39a42
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ncurses-terminfo-base (6.3_p20211120-r0)
(2/4) Installing ncurses-libs (6.3_p20211120-r0)
(3/4) Installing readline (8.1.1-r0)
(4/4) Installing bash (5.1.8-r0)
Executing bash-5.1.8-r0.post-install
Executing busybox-1.34.1-r3.trigger
OK: 10 MiB in 24 packages
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/4) Installing libunistring (0.9.10-r1)
(2/4) Installing libidn2 (2.3.2-r0)
(3/4) Installing wget (1.21.2-r2)
(4/4) Installing build-dependencies (20211220.220536)
Executing busybox-1.34.1-r3.trigger
OK: 13 MiB in 28 packages
gunzip: invalid magic
tar: short read
The command '/bin/sh -c apk add --no-cache bash   && apk add --no-cache --virtual=build-dependencies wget ca-certificates   && wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x   && apk del build-dependencies   && rm -rf /tmp/*' returned a non-zero code: 1
4
  • Are you sure it doesn't? The build log shows the command before variable replacement, so that will show ${SCALA_VERSION}. But the actual command will have 2.13.7, I think. Commented Dec 20, 2021 at 22:03
  • @HansKilian I added an update Commented Dec 20, 2021 at 22:06
  • The update shows that the three commands combined returned an exit code of 1. gunzip had invalid magic; it never even got to the wget part. Commented Dec 20, 2021 at 22:08
  • If I don't use SCALA_VERSION and hardcode 2.13.7 it works perfectly fine. Commented Dec 20, 2021 at 22:09

1 Answer 1

3

It's FROM openjdk:18-jdk-alpine AS base that does it. The ARGs set before you base on the new image aren't carried over. You need to move the ARG statements to after the FROM like this

FROM openjdk:18-jdk-alpine AS base
ARG SCALA_MAJOR_VERSION="2.13"
ARG SCALA_MINOR_VERSION="7"
ARG SCALA_VERSION="$SCALA_MAJOR_VERSION.$SCALA_MINOR_VERSION"

LABEL version="$SCALA_VERSION"

WORKDIR /usr/lib

RUN apk add --no-cache bash \
  && apk add --no-cache --virtual=build-dependencies wget ca-certificates \
  && wget -q --no-cookies "https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz" -O - | gunzip | tar x \
  && apk del build-dependencies \
  && rm -rf /tmp/*
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.