Reputation: 4908
I'm creating a Dockerfile and part of the process is to ADD
the latest version of a package, which can be downloaded as a text file.
ADD http://example.com/latest-version.txt
package1 = AB1.0.0
package2 = 32.4132
package3 = 123.456
Search for the string package1
, set the variable packageVersion
to AB1.0.0
and ADD
the file.
ADD http://example.com/package1.${packageVersion}.tar.gz
Can I achieve this in the Dockerfile or will I need some help from a Bash script?
Upvotes: 2
Views: 1554
Reputation: 6956
I don't think the Dockerfile
syntax will support what you want out of the box currently. I would suggest you create a simple bash
script to do the downloading/renaming for you and then just ADD
the static file pointers to your Dockerfile
.
ADD http://example.com/latest-version.txt
latest-version.txt
file and downloads the relevant files, eg.
wget http://example.com/package1.${packageVersion1}.tar.gz -O /tmp/package1.tar.gz
wget http://example.com/package2.${packageVersion2}.tar.gz -O /tmp/package2.tar.gz
ADD /tmp/package1.tar.gz
ADD /tmp/package2.tar.gz
I would suggest you employ some kind of Configuration Management (CM) to make your life easier as this method of solving issues can get messy quickly. CM has the upside of providing not only more structure to solve problems like this, but also two other important attributes namely idempotence
and convergence
when building an artifact.
while IFS='' read -r line || [[ -n "$line" ]]; do
NAME=`echo $line | cut -d '=' -f1`; VERSION=`echo $line | cut -d '=' -f2`; echo $NAME; echo $VERSION;
done < latest-version.txt
Upvotes: 1