docker - Canonical way to checksum downloads in a Dockerfile? -


i'm creating dockerfile downloads, builds, installs node.js source. i'd checksum download before building it, , stop or exit dockerfile if checksum fails:

# officially supported ubuntu ubuntu:12.04  # setup run cd /tmp run apt-get update -y run apt-get install wget build-essential automake -y run wget http://nodejs.org/dist/latest/node-v0.10.26.tar.gz run wget http://nodejs.org/dist/latest/shasums256.txt  # run checksum: exit on fail, continue on success ??? how ???  # install run tar -xvf node-v0.10.26.tar.gz && cd node-v0.10.26 run ./configure && make && make install  # cleanup apt-get autoremove --purge wget build-essential automake -y 

has docker community settled on 'best practices' way of doing this?

if of run commands return non-zero code, build fail.

from fedora run false 

in dockerfile above, i'm doing quick test running false. false linux utility sets non-zero return code, handy testing. can see, when build dockerfile, complains , fails out.

$ docker build . uploading context 12.29 kb uploading context step 0 : fedora  ---> 58394af37342 step 1 : run false  ---> running in a5b9a4b37e25 2014/04/22 09:41:19 command [/bin/sh -c false] returned non-zero code: 1 

therefore, it's simple matter of having file , checksums in image (which appear have via wget) , can test it. here quick , dirty version of below, in generate file , calculate checksum before verifying it. in example, not doing that, show how works.

from fedora  # create text file run echo thisisatest > echo.txt  # calculate checksum run sha1sum echo.txt > sha1sums.txt  # validate checksum (this should pass) run sha1sum -c sha1sums.txt  # alter text run echo thisshouldfail > echo.txt  # validate checksum (this should fail) run sha1sum -c sha1sums.txt 

and if run this...

$ docker build -no-cache . warning: '-no-cache' deprecated, removed soon. see usage. uploading context  12.8 kb uploading context step 0 : fedora  ---> 58394af37342 step 1 : run echo thisisatest > echo.txt  ---> running in cd158d4e6d91  ---> 4088b1b4945f step 2 : run sha1sum echo.txt > sha1sums.txt  ---> running in 5d028d901d94  ---> c97b1d31a720 step 3 : run sha1sum -c sha1sums.txt  ---> running in 44d119897164 echo.txt: ok  ---> ca01d590cadd step 4 : run echo thisshouldfail > echo.txt  ---> running in 87b575ac4052  ---> 36bb5d8cf6d1 step 5 : run sha1sum -c sha1sums.txt  ---> running in e20b7ac0c924 echo.txt: failed warning: 1 computed checksum did not match 2014/04/22 10:29:07 command [/bin/sh -c sha1sum -c sha1sums.txt] returned non-zero code: 1 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -