| 1 |
#!/bin/sh |
| 2 |
#? |
| 3 |
#? NAME |
| 4 |
#? $0 - wrapper script to build O-Saft in a Docker image |
| 5 |
#? |
| 6 |
#? SYNOPSIS |
| 7 |
#? $0 build [build options] |
| 8 |
#? $0 load [load options] |
| 9 |
#? $0 pull [pull options] |
| 10 |
# ? $0 config |
| 11 |
#? |
| 12 |
#? OPTIONS |
| 13 |
#? -help got it |
| 14 |
#? -n do not execute, just show what would be done |
| 15 |
#? -v be a bit verbose |
| 16 |
#? -- pass all remaining parameters to docker |
| 17 |
#? |
| 18 |
#? To create a Docker image, following additional options can be used: |
| 19 |
#? --force-rm pass --force-rm option to "docker build" |
| 20 |
#? --rm pass --rm option to "docker build" |
| 21 |
#? -del delete saved image file after "docker load" |
| 22 |
#? -clean shortcut for: --no-force-rm --no-rm -no-del |
| 23 |
#? -save save and then load created image (removes layers) |
| 24 |
#? -tag create addition tag for image (alias) o-saft |
| 25 |
#? --no-force-rm do not pass --force-rm option to "docker build" |
| 26 |
#? --no-rm do not pass --rm option to "docker build" |
| 27 |
#? -no-del do not delete saved image file after "docker load" |
| 28 |
#? -no-clean shortcut for: --force-rm --rm -del |
| 29 |
#? -no-save do not save and then load created image |
| 30 |
#? -no-tag do notcreate addition tag for image |
| 31 |
#? -alpine build image based on alpine |
| 32 |
#? -debian build image based on debian |
| 33 |
#? -from=BASE build image based on BASE (value used for FROM key) |
| 34 |
#? -author set MAINTAINER in Dockerfile |
| 35 |
#? |
| 36 |
#? Options for image content |
| 37 |
#? -apt=CMD use CMD as command for package manager |
| 38 |
# ? -tar=TAR use TAR file to build image instead of wget ... |
| 39 |
# ? -sha256sum check SHA256 checksum of tar archive |
| 40 |
# ? -no-sha256sum do not check SHA256 checksum of tar archive |
| 41 |
#? -openssl install openssl-chacha in image |
| 42 |
#? -iosocket install IO::Socket::SSL in image |
| 43 |
#? -ssleay install Net::SSLeay in image |
| 44 |
#? -tcl install Tcl/Tk (wish) in image |
| 45 |
#? -no-openssl do not install openssl-chacha |
| 46 |
#? -no-iosocket do not install IO::Socket::SSL |
| 47 |
#? -no-ssleay do not install Net::SSLeay |
| 48 |
#? -no-tcl do not install Tcl/Tk (wish) |
| 49 |
#? TODO: need option to pass SHA256 values |
| 50 |
# ? -pull [name[:tag] |
| 51 |
# ? Pulls specified image from hub.docker.net. [name[:tag] is |
| 52 |
# ? the same as for Docker's pull command. This command implies |
| 53 |
# ? the options: -no-save -no-tag -no-del |
| 54 |
#? |
| 55 |
#? The defaults are: -f ./Dockerfile --force-rm --rm -del -save -tag |
| 56 |
#? which results in: |
| 57 |
#? docker build -f ./Dockerfile --force-rm --rm ... |
| 58 |
#? |
| 59 |
#? DESCRIPTION |
| 60 |
#? The purpose of this script is to provide various modes to creates an |
| 61 |
#? O-Saft Docker image. It's a more powerful version of o-saft-docker's |
| 62 |
#? build command (mode) and provides some options mainly for debugging. |
| 63 |
#? |
| 64 |
#? It can operate in following modes: |
| 65 |
#? build - use Docker's build command to create the image |
| 66 |
#? load - use Docker's load command to create the image |
| 67 |
#? pull - use Docker's pull command to create the image |
| 68 |
#? |
| 69 |
#? In build mode it generates a Dockerfile and then calls docker build |
| 70 |
#? with. The Dockerfile consists mainly of five parts: |
| 71 |
#? 1. initial data |
| 72 |
#? 2. setup O-Saft |
| 73 |
#? 3. setup IO::Socket::SSL (if necessary) |
| 74 |
#? 4. setup special openssl (if enabled) |
| 75 |
#? 5. final data |
| 76 |
#? |
| 77 |
#? It is highly recommended to use this script with the -n option first |
| 78 |
#? and verify that the printed commands are correct. |
| 79 |
#? |
| 80 |
#? TERMINOLOGY |
| 81 |
#? Please see also: o-saft-docker -help |
| 82 |
#? |
| 83 |
#? del(ete) vs. rm (remove) vs. clean |
| 84 |
#? The term "remove" herein is used when objects, files, etc. inside |
| 85 |
#? Docker images or containers are removed. The term "delete" is used |
| 86 |
#? when objects, files, etc. on the host are deleted. The term "clean" |
| 87 |
#? is used when both, targets inside Docker and on the host, are meant. |
| 88 |
#? Options are named accordingly. |
| 89 |
#? |
| 90 |
#? build vs. load vs. pull |
| 91 |
#? These terms are used as Docker does. "build" creates the image on |
| 92 |
#? the local host. It uses the sources specified in the corresponding |
| 93 |
#? Dockerfile. "load" creates an image from a local (on the host) tar |
| 94 |
#? archive. And finally "pull" creates an image from a registry. |
| 95 |
#? Please refer to WHY? and SECURITY below, to understand why this |
| 96 |
#? difference is important. |
| 97 |
#? |
| 98 |
#? WHY? |
| 99 |
#? Why using a script, which finally generates a Dockerfile, to create |
| 100 |
#? Docker images, when simply using the Dockerfile would do the same? |
| 101 |
#? Some reasons are: |
| 102 |
#? used sources - Commands of the Dockerfile itself must be changed |
| 103 |
#? when a source will be provided by the host (local |
| 104 |
#? filesystem) instead of fetching from an internet |
| 105 |
#? archive (such as hub.docker.com). The difference |
| 106 |
#? is using COPY instead of RUN with wget. |
| 107 |
#? trustworth - I.g. creating your own image on your host is more |
| 108 |
#? trustworthy than downloading and blindly using an |
| 109 |
#? preconfigured image from resources not under your |
| 110 |
#? control. Using build provides full control over |
| 111 |
#? all used resources. Contrary, using pull from |
| 112 |
#? remote resources provides no control at all.. |
| 113 |
#? clean-up - After creating images, a proper clean-up must be |
| 114 |
#? done at three places: while creating the image by |
| 115 |
#? using proper option (like --force-rm), inside the |
| 116 |
#? image (mainly the RUN commands) and on the host. |
| 117 |
#? tagging - The name (registry:tag) for images must be given |
| 118 |
#? to the build command, it is not possible to write |
| 119 |
#? it inside the Dockerfile. Hence there is at least |
| 120 |
#? one program call (docker build ...) which must be |
| 121 |
#? closely related to the whole process of creating |
| 122 |
#? a Docker image. |
| 123 |
#? identity - Inside an image, it is hard, probably impossible, |
| 124 |
#? to identify how and when the image was build. |
| 125 |
#? |
| 126 |
#? MODES |
| 127 |
#? build |
| 128 |
#? Build image from a Dockerfile. |
| 129 |
#? |
| 130 |
#? load |
| 131 |
#? Install image with Docker's load command. |
| 132 |
#? |
| 133 |
#? pull |
| 134 |
#? Install image with Docker's pull command. Remember WHY? above. |
| 135 |
#? |
| 136 |
#? SECURITY |
| 137 |
#? Please see: o-saft-docker -help |
| 138 |
#? That's why this script provides different modes to create an image. |
| 139 |
#? The purpose is to make the build process as transparent as possible. |
| 140 |
#? please refer to the "build" modes described above |
| 141 |
#? |
| 142 |
#? HACKER's INFO |
| 143 |
# The purpose of this script is to build Docker images for o-saft.pl. |
| 144 |
# Hence all default settings support this. |
| 145 |
# |
| 146 |
# Docker's ADD command promisses to fetch archives from a URL and also |
| 147 |
# extract it. Unfortunately, modern archives can have various filename |
| 148 |
# extensions and also may be compressed with different algorithms. So |
| 149 |
# only COPY or wget is used to provide externa archives. |
| 150 |
# |
| 151 |
# The generated RUN commands to get and unpack archives depend on the |
| 152 |
# source. If it is a tarball, this must be copied or mounted into the |
| 153 |
# docker image. Unfortunately, this requires different syntax elements |
| 154 |
# in the Dockerfile, i.e. "COPY ..." vs. "RUN wget ...". To generate |
| 155 |
# the appropriate code, following functions take care of that: |
| 156 |
# _copy_src $_src $_tar |
| 157 |
# _run_wget $_src $_tar |
| 158 |
# _run_sha2 $_tar $_sha |
| 159 |
# _run_untar $_tar $_tmp |
| 160 |
# |
| 161 |
# Using sevaral independent Docker RUN commands, as the documentation |
| 162 |
# recommends, is not a wice idea, because it results in one layer for |
| 163 |
# each RUN command containing anything from the previous Docker layer. |
| 164 |
# Hence each generated RUN command contains as much internal commands |
| 165 |
# as possible (concatenated with &&). |
| 166 |
# |
| 167 |
# Docker itself provides no functionality to shrink an image while it |
| 168 |
# is build. This must be done by additional Docker commands (save and |
| 169 |
# load). |
| 170 |
# |
| 171 |
# Empty lines in Docker RUN commands may result in |
| 172 |
# [WARNING]: Empty continuation lines will become errors in a future release. |
| 173 |
# hence a single \ is used as "empty line". |
| 174 |
# |
| 175 |
#? LIMITATIONS |
| 176 |
#? The options -n -v and -help must be specified first (leftmost) |
| 177 |
#? if they should apply for this script. |
| 178 |
#? |
| 179 |
#? ENVIONMENT VARIABLES |
| 180 |
#? Following environment variables can be used to pass settings to the |
| 181 |
#? script: |
| 182 |
#? |
| 183 |
#? OSAFT_VERSION - version to be passed to Dockerfile |
| 184 |
#? o_saft_docker_name - contains an image registry name |
| 185 |
#? o_saft_docker_tag - contains an image tag |
| 186 |
#? |
| 187 |
#? SEE ALSO |
| 188 |
#? o-saft-docker |
| 189 |
#? |
| 190 |
#? EXAMPLES |
| 191 |
#? # FROM command sources openssl Tcl/Tk ... options |
| 192 |
#? +-----+-------+-------+-------+-------+-------+----------------------- |
| 193 |
#? alpine pull reg:tag -alpine -pull |
| 194 |
#? alpine build http:// openssl -alpine |
| 195 |
#? alpine build .tgz -alpine -tar=o-saft.tgz |
| 196 |
#? debian build http:// wish -debian |
| 197 |
#? debian build .tgz wish -debian -tar=o-saft.tgz |
| 198 |
#? |
| 199 |
#? VERSION |
| 200 |
#? @(#) 1.7 19/08/01 16:34:26 |
| 201 |
#? |
| 202 |
#? AUTHOR |
| 203 |
#? 17-jul-17 Achim Hoffmann |
| 204 |
#? |
| 205 |
# ----------------------------------------------------------------------------- |
| 206 |
|
| 207 |
try= |
| 208 |
cmd=unknown |
| 209 |
|
| 210 |
VERSION="${OSAFT_VERSION:-19.01.19}" |
| 211 |
registry="${o_saft_docker_name}"; registry="${registry:-owasp/o-saft}" |
| 212 |
image_tag="${o_saft_docker_tag}"; image_tag="${image_tag:-`date +%y.%m.%d`}" |
| 213 |
image_name="${registry}:${image_tag}" |
| 214 |
image_save="o-saft_docker.tar" |
| 215 |
image_from="alpine:edge" |
| 216 |
dockerfile="Dockerfile" |
| 217 |
maintainer="" # must be set with -author |
| 218 |
buildfrm="--force-rm" |
| 219 |
build_rm="--rm=true" |
| 220 |
buildtag=1 |
| 221 |
buildsav=1 |
| 222 |
inst_tcl=0 |
| 223 |
instwget=1 |
| 224 |
host_del=1 |
| 225 |
host_tar="" |
| 226 |
hostdate=`date +%y%m%d%"H%"M%S` |
| 227 |
apt="apk" |
| 228 |
upd="$apt update" |
| 229 |
apt_add="add" |
| 230 |
apt_del="del" |
| 231 |
apt__dev="" |
| 232 |
apt__gcc="gcc make" |
| 233 |
apt__tcl="" |
| 234 |
apt_wget="" |
| 235 |
check_sha256=1 |
| 236 |
make_o_saft=1 |
| 237 |
make_openssl= |
| 238 |
make_iosocket= |
| 239 |
make_ssleay= |
| 240 |
dir__o_saft="/O-Saft" |
| 241 |
dir_openssl="/openssl" |
| 242 |
# sources |
| 243 |
# NOTE: empty checksum must be specified as "-" |
| 244 |
url__o_saft="https://github.com/OWASP/O-Saft/raw/master/o-saft.tgz" |
| 245 |
sha__o_saft="29d4faa2ed3025ed18d31175e868d6be9312b36ba486c6e5f305afeb34947f68" |
| 246 |
url_openssl="https://github.com/PeterMosmans/openssl/archive/1.0.2-chacha.tar.gz" |
| 247 |
sha_openssl="-" |
| 248 |
urliosocket="http://search.cpan.org/CPAN/authors/id/S/SU/SULLR/IO-Socket-SSL-2.049.tar.gz" |
| 249 |
shaiosocket="-" |
| 250 |
url__ssleay="" |
| 251 |
sha__ssleay="-" |
| 252 |
|
| 253 |
_dbx_config () { |
| 254 |
cat <<EoConfig |
| 255 |
#=== internal configuration { |
| 256 |
# == commands and variables |
| 257 |
# cmd = $cmd |
| 258 |
# buildtag = $buildtag |
| 259 |
# buildsav = $buildsav |
| 260 |
# host_del = $host_del |
| 261 |
# host_tar = $host_tar |
| 262 |
# inst_tcl = $inst_tcl |
| 263 |
# instwget = $instwget |
| 264 |
# host_del = $host_del |
| 265 |
# host_tar = $host_tar |
| 266 |
# hostdate = $hostdate |
| 267 |
# image_save = $image_save |
| 268 |
# check_sha256 = $check_sha256 |
| 269 |
# make_o_saft = $make_o_saft |
| 270 |
# make_openssl = $make_openssl |
| 271 |
# make_iosocket = $make_iosocket |
| 272 |
# make_ssleay = $make_ssleay |
| 273 |
# dir__o_saft = $dir__o_saft |
| 274 |
# dir_openssl = $dir_openssl |
| 275 |
# == sources |
| 276 |
# url__o_saft = $url__o_saft |
| 277 |
# sha__o_saft = $sha__o_saft |
| 278 |
# url_openssl = $url_openssl |
| 279 |
# sha_openssl = $sha_openssl |
| 280 |
# urliosocket = $urliosocket |
| 281 |
# shaiosocket = $shaiosocket |
| 282 |
# url__ssleay = $url__ssleay |
| 283 |
# sha__ssleay = $sha__ssleay |
| 284 |
# == docker |
| 285 |
# cmd = $cmd |
| 286 |
# options = $buildfrm $build_rm |
| 287 |
# aliases = $buildtag |
| 288 |
# image = $image_name |
| 289 |
# dockerfile = $dockerfile |
| 290 |
# image_from = $image_from |
| 291 |
# maintainer = $maintainer |
| 292 |
# == packages |
| 293 |
# apt = $apt |
| 294 |
# upd = $upd |
| 295 |
# apt_add = $apt_add |
| 296 |
# apt_del = $apt_del |
| 297 |
# apt__dev = $apt__dev |
| 298 |
# apt__gcc = $apt__gcc |
| 299 |
# apt__tcl = $apt__tcl |
| 300 |
# apt_wget = $apt_wget |
| 301 |
#=== internal configuration } |
| 302 |
EoConfig |
| 303 |
} |
| 304 |
|
| 305 |
_cfg_alpine () { |
| 306 |
#? set global variables for alpine |
| 307 |
_typ="$1" |
| 308 |
image_from="${image_from:-alpine:3.6}" |
| 309 |
make_openssl=${make_openssl:-1} |
| 310 |
make_iosocket=${make_iosocket:-1} |
| 311 |
make_ssleay=${make_ssleay:-0} |
| 312 |
apt="apk" |
| 313 |
upd="echo 'no update'" # alpine doesn't need it |
| 314 |
apt__dev="perl perl-net-dns perl-net-ssleay ncurses" # alpine:3.6 |
| 315 |
apt__gcc="musl-dev gcc make zlib-dev" |
| 316 |
adduser="adduser -D osaft -h $dir__o_saft" |
| 317 |
[ $inst_tcl -eq 1 ] && apt__tcl="tcl tk xvfb" |
| 318 |
[ $instwget -eq 1 ] && apt_wget="wget" |
| 319 |
if [ "$_typ" = "alpine:edge" ]; then |
| 320 |
# dirty hack |
| 321 |
apt__dev="$apt__dev perl-io-socket-ssl" |
| 322 |
make_iosocket=0 |
| 323 |
fi |
| 324 |
#[ -z "$host_tar" ] && wget=wget |
| 325 |
} |
| 326 |
_cfg_debian () { |
| 327 |
#? set global variables for debian |
| 328 |
image_from="${image_from:-debian:stretch-slim}" |
| 329 |
make_openssl=${make_openssl:-1} |
| 330 |
make_iosocket=${make_iosocket:-0} |
| 331 |
make_ssleay=${make_ssleay:-0} |
| 332 |
apt="apt" |
| 333 |
upd="$apt update" |
| 334 |
apt__dev="libperl5.24 libio-socket-ssl-perl libnet-dns-perl libnet-ssleay-perl" |
| 335 |
apt__gcc="gcc make" |
| 336 |
adduser="adduser --disabled-password --gecos '' osaft" |
| 337 |
# debian's adduser complains if GECOS is missing |
| 338 |
[ $inst_tcl -eq 1 ] && apt__tcl="wish" |
| 339 |
# debian installs X11 with Tcl/Tk, grrr ... |
| 340 |
[ $instwget -eq 1 ] && apt_wget=wget |
| 341 |
} |
| 342 |
|
| 343 |
_copy_src () { |
| 344 |
#? return Docker COPY command to get tarball |
| 345 |
# src=${1} tar=${2} |
| 346 |
echo "$1" | \egrep -q ^http && return; # return if URL |
| 347 |
echo "COPY $1 /$2" |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
_run_wget () { |
| 352 |
#? return part for Docker RUN command to get tarball |
| 353 |
# url=${1} tar=${2} |
| 354 |
echo "$1" | \egrep -q ^http || return; # return if not URL |
| 355 |
cat <<EoRUN |
| 356 |
wget --no-check-certificate $1 -O $2 && \\ |
| 357 |
EoRUN |
| 358 |
} |
| 359 |
|
| 360 |
_run_sha2 () { |
| 361 |
#? return part for Docker RUN command to check SHA256 checksum |
| 362 |
# tar=${1} sha=${2} |
| 363 |
[ -z $2 ] && return |
| 364 |
[ "$2" = "-" ] && return |
| 365 |
# only generate code if checksum was given |
| 366 |
cat <<EoRUN |
| 367 |
echo "$2 $1" | sha256sum -c && \\ |
| 368 |
EoRUN |
| 369 |
} |
| 370 |
|
| 371 |
_run_untar () { |
| 372 |
#? return part for Docker RUN command to extract tarball and cd to dir |
| 373 |
# tar=${1} sha=${2} tmp=${3} |
| 374 |
cat <<EoRUN |
| 375 |
mkdir $2 && \\ |
| 376 |
tar -C $2 --strip-components=1 -xzf $1 && \\ |
| 377 |
cd $2 && \\ |
| 378 |
EoRUN |
| 379 |
} |
| 380 |
|
| 381 |
_run_iosocket $urliosocket $shaiosocket $__tar /iosocket |
| 382 |
_run_iosocket () { |
| 383 |
#? return Docker RUN command to build IO::Socket::SSL |
| 384 |
_src_1=${1} |
| 385 |
_sha_1=${2} |
| 386 |
_tar_1=${3:-iosocket.tgz} |
| 387 |
_dir_1=${4:-/iosocket} # not used |
| 388 |
_tmp_1=${5:-/src_iosocket} |
| 389 |
_copy_src $_src_1 $_tar_1 |
| 390 |
cat <<EoRUN |
| 391 |
|
| 392 |
# Pull and build IO::Socket::SSL |
| 393 |
RUN \\ |
| 394 |
# pull and extract module |
| 395 |
EoRUN |
| 396 |
_run_wget $_src_1 $_tar_1 |
| 397 |
_run_sha2 $_tar_1 $_sha_1 |
| 398 |
_run_untar $_tar_1 $_tmp_1 |
| 399 |
cat <<EoRUN |
| 400 |
# install development tools |
| 401 |
$apt $apt_add make && \\ |
| 402 |
# build iosocket |
| 403 |
echo n | perl Makefile.PL && \\ |
| 404 |
make && make test && make install && \\ |
| 405 |
# cleanup |
| 406 |
$apt $apt_del make && \\ |
| 407 |
cd / && rm -r $_tmp_1 && \\ |
| 408 |
EoRUN |
| 409 |
} |
| 410 |
|
| 411 |
_run__openssl () { |
| 412 |
#? return Docker RUN command to build openssl |
| 413 |
_src_2=${1} |
| 414 |
_sha_2=${2} |
| 415 |
_tar_2=${3:-openssl.tgz} |
| 416 |
_dir_2=${4:-/openssl} |
| 417 |
_tmp_2=${5:-/src_openssl} |
| 418 |
_copy_src $_src_2 $_tar_2 |
| 419 |
cat <<EoRUN |
| 420 |
|
| 421 |
# Pull and build enhanced openssl |
| 422 |
RUN \\ |
| 423 |
# pull and extract module |
| 424 |
EoRUN |
| 425 |
_run_wget $_src_2 $_tar_2 |
| 426 |
_run_sha2 $_tar_2 $_sha_2 |
| 427 |
_run_untar $_tar_2 $_tmp_2 |
| 428 |
cat <<EoRUN |
| 429 |
# install development tools |
| 430 |
$apt $apt_add $apt__gcc && \\ |
| 431 |
# build openssl |
| 432 |
./config --prefix=$_dir_2 --openssldir=$_dir_2/ssl \\ |
| 433 |
enable-zlib enable-ssl3 enable-rc5 enable-rc2 enable-GOST \\ |
| 434 |
enable-cms enable-md2 enable-mdc2 enable-ec enable-ec2m \\ |
| 435 |
enable-ecdh enable-ecdsa enable-seed enable-idea enable-camellia \\ |
| 436 |
enable-rfc3779 enable-ec_nistp_64_gcc_128 \\ |
| 437 |
-static experimental-jpake -DOPENSSL_USE_BUILD_DATE && \\ |
| 438 |
make depend && make && make report && make install && \\ |
| 439 |
# simple test |
| 440 |
echo -e "# number of ciphers $_dir_2/bin/openssl: " && \\ |
| 441 |
$_dir_2/bin/openssl ciphers -V ALL:COMPLEMENTOFALL:aNULL|wc -l && \\ |
| 442 |
# cleanup |
| 443 |
$apt $apt_del $apt__gcc && \\ |
| 444 |
cd / && rm -r $_tmp_2 && \\ |
| 445 |
EoRUN |
| 446 |
} |
| 447 |
|
| 448 |
_run_osaftrc () { |
| 449 |
#? return partial command to patch .o-saft.pl |
| 450 |
_dir_8=${1:-/O-Saft} |
| 451 |
_openssl=${2:-/openssl} |
| 452 |
cat <<EoRUN |
| 453 |
mv $_dir_8/.o-saft.pl $_dir_8/.o-saft.pl-orig && \ |
| 454 |
sed -e "s:^#--openssl=.*:--openssl=$_openssl/bin/openssl:" \ |
| 455 |
< $_dir_8/.o-saft.pl-orig \ |
| 456 |
> $_dir_8/.o-saft.pl && \ |
| 457 |
EoRUN |
| 458 |
} |
| 459 |
|
| 460 |
_run_osaft () { |
| 461 |
#? return Docker RUN command to build /O-Saft |
| 462 |
_src_9=${1} |
| 463 |
_sha_9=${2} |
| 464 |
_tar_9=${3:-o-saft} |
| 465 |
_dir_9=${4:-/O-Saft} |
| 466 |
_copy_src $_src_9 $_tar_9 |
| 467 |
cat <<EoRUN |
| 468 |
|
| 469 |
# Install O-Saft |
| 470 |
RUN \\ |
| 471 |
EoRUN |
| 472 |
_run_wget $_src_9 $_tar_9 |
| 473 |
_run_sha2 $_tar_9 $_sha_9 |
| 474 |
cat <<EoRUN |
| 475 |
\\ |
| 476 |
tar -xzf $_tar_9 && \\ |
| 477 |
chown -R root:root $_dir_9 && \\ |
| 478 |
chown osaft:osaft $_dir_9 && \\ |
| 479 |
chown -R osaft:osaft $_dir_9/contrib && \\ |
| 480 |
chown osaft:osaft $_dir_9/.o-saft.pl && \\ |
| 481 |
EoRUN |
| 482 |
_run_osaftrc $_dir_9 /openssl |
| 483 |
echo " chmod 666 $_dir_9/.o-saft.pl && \\" |
| 484 |
} |
| 485 |
|
| 486 |
dockerfile () { |
| 487 |
# generate a Dockerfile; for options see general description above |
| 488 |
_path='$PATH' # avoid \\ in strings |
| 489 |
|
| 490 |
cat <<EoDockerfile |
| 491 |
#!/usr/bin/docker build --force-rm --rm -f |
| 492 |
FROM $image_from |
| 493 |
$maintainer |
| 494 |
LABEL VERSION="$image_tag" DESCRIPTION="O-Saft docker image build by $0 1.7" |
| 495 |
|
| 496 |
ENV o-saft-docker-build.$hostdate "$0 $args" |
| 497 |
ENV TERM xterm |
| 498 |
ENV PATH ${dir__o_saft}:${dir__o_saft}/contrib:${dir_openssl}/bin:$_path |
| 499 |
|
| 500 |
RUN $upd && $apt $apt_add $apt__dev $apt__tcl $apt_wget |
| 501 |
WORKDIR / |
| 502 |
RUN $adduser |
| 503 |
EoDockerfile |
| 504 |
|
| 505 |
if [ $make_o_saft -eq 1 ]; then |
| 506 |
__tar=o-saft.tgz |
| 507 |
_run_osaft $url__o_saft $sha__o_saft $__tar $dir__o_saft |
| 508 |
echo " rm $__tar" |
| 509 |
fi |
| 510 |
|
| 511 |
if [ $make_iosocket -eq 1 ]; then |
| 512 |
__tar=iosocket.tgz |
| 513 |
_run_iosocket $urliosocket $shaiosocket $__tar /iosocket |
| 514 |
echo " rm $__tar" |
| 515 |
fi |
| 516 |
|
| 517 |
if [ $make_openssl -eq 1 ]; then |
| 518 |
__tar=openssl.tgz |
| 519 |
_run__openssl $url_openssl $sha_openssl $__tar $dir_openssl |
| 520 |
echo " rm $__tar" |
| 521 |
fi |
| 522 |
|
| 523 |
cat <<EoDockerfile |
| 524 |
|
| 525 |
WORKDIR ${dir__o_saft} |
| 526 |
USER osaft |
| 527 |
RUN o-saft-docker usage |
| 528 |
ENTRYPOINT ["perl", "${dir__o_saft}/o-saft.pl"] |
| 529 |
CMD ["--norc", "--help=docker"] |
| 530 |
EoDockerfile |
| 531 |
} |
| 532 |
|
| 533 |
docker_clean () { |
| 534 |
$try \docker image save -o ${image_save} ${image_name} |
| 535 |
$try \docker image rm `$try docker image ls -q ${image_name}` |
| 536 |
$try \docker image load -i ${image_save} |
| 537 |
} |
| 538 |
|
| 539 |
docker_build_file () { |
| 540 |
name="$1"; shift |
| 541 |
_file_f="$2"; shift |
| 542 |
_dir_f="" |
| 543 |
|
| 544 |
_dockerfile_f=./tmp-Dockerfile |
| 545 |
make=`perl -ne 'print if m(# build {)..m(# build })' Dockerfile` |
| 546 |
|
| 547 |
cat > $_dockerfile_f <<EoDockerfile |
| 548 |
FROM $name |
| 549 |
LABEL VERSION="$image_tag" DESCRIPTION="O-Saft docker image build by $0 1.7" \ |
| 550 |
SOURCE="$_file_f" |
| 551 |
WORKDIR / |
| 552 |
COPY $_file_f / |
| 553 |
USER root |
| 554 |
RUN $apt $apt_add |
| 555 |
RUN $make |
| 556 |
RUN $apt $apt_del |
| 557 |
ENV o-saft-docker-build.$hostdate "$0 $args" |
| 558 |
EoDockerfile |
| 559 |
|
| 560 |
$try \docker image build --build-arg "OSAFT_VERSION=$VERSION" \ |
| 561 |
$buildfrm $build_rm -f $_dockerfile_f . |
| 562 |
|
| 563 |
if [-d $_dir_f ]; then |
| 564 |
echo |
| 565 |
fi |
| 566 |
} |
| 567 |
|
| 568 |
docker_build () { |
| 569 |
# create an image; for options see general description above |
| 570 |
_dockerfile_b=$host_tmp/$dockerfile |
| 571 |
# while [ $# -gt 0 ]; do |
| 572 |
# case "$1" in |
| 573 |
# *) _dockerfile_b=$1; break; ;; |
| 574 |
# esac |
| 575 |
# shift |
| 576 |
# done |
| 577 |
|
| 578 |
# für Osaft: wenn ein .tar-File da ist, das benutzen statt wget |
| 579 |
# betrifft: osaft.tgz iosocket.tgz openssl.tgz $apt_wget |
| 580 |
dockerfile > $_dockerfile_b |
| 581 |
|
| 582 |
[ "$try" = "echo" ] && echo && cat $_dockerfile_b && echo |
| 583 |
|
| 584 |
for file in $host_tar; do |
| 585 |
$try docker_build_file ${image_name} $_dockerfile_b |
| 586 |
done |
| 587 |
|
| 588 |
$try \docker image build --build-arg "OSAFT_VERSION=$VERSION" \ |
| 589 |
$buildfrm $build_rm -f $_dockerfile_b -t ${image_name} . |
| 590 |
[ $buildsav -eq 1 ] && docker_clean |
| 591 |
[ $host_del -eq 1 ] && [ -f ${image_save} ] && $try \rm ${image_save} |
| 592 |
[ $buildtag -eq 1 ] && $try \docker image tag ${image_name} o-saft |
| 593 |
} |
| 594 |
|
| 595 |
docker_pull () { |
| 596 |
$try \docker image pull $@ |
| 597 |
} |
| 598 |
|
| 599 |
docker_load () { |
| 600 |
$try \docker image load $@ |
| 601 |
} |
| 602 |
|
| 603 |
my_help () { |
| 604 |
ich=${0##*/} |
| 605 |
\sed -ne "s/\$0/$ich/g" -e '/^#?/s/#?//p' $0 |
| 606 |
} |
| 607 |
|
| 608 |
_cfg_alpine # set defaults |
| 609 |
args="$*" |
| 610 |
while [ $# -gt 0 ]; do |
| 611 |
case "$1" in |
| 612 |
'-n') try=echo; ;; |
| 613 |
'-v') set -x ; ;; |
| 614 |
'-help') cmd=help; ;; |
| 615 |
'build') cmd=build; ;; |
| 616 |
'load') cmd=load; ;; |
| 617 |
'pull') cmd=pull; ;; |
| 618 |
'config') cmd=config; ;; |
| 619 |
'dockerfile') cmd=config; ;; |
| 620 |
'-alpine') _cfg_alpine alpine ; ;; |
| 621 |
'-debian') _cfg_debian debian ; ;; |
| 622 |
-from=*) image_from="`expr "$1" ':' '-from=\(.*\)'`"; ;; |
| 623 |
-tar=*) host_tar="$host_tar `expr "$1" ':' '-tar=\(.*\)'`"; ;; |
| 624 |
-apt=*) apt="`expr "$1" ':' '-apt=\(.*\)'`"; ;; |
| 625 |
'-author') maintainer="MAINTAINER Achim <[email protected]>"; ;; |
| 626 |
'-sha256sum') check_sha256=1; ;; |
| 627 |
'-no-sha256sum') check_sha256=0; ;; |
| 628 |
'-openssl') make_openssl=1; ;; |
| 629 |
'-no-openssl') make_openssl=0; ;; |
| 630 |
'-iosocket') make_iosocket=1; ;; |
| 631 |
'-no-iosocket') make_iosocket=0; ;; |
| 632 |
'-ssleay') make_ssleay=1; ;; |
| 633 |
'-no-ssleay') make_ssleay=0; ;; |
| 634 |
'-save') buildsav=1; ;; |
| 635 |
'-no-save') buildsav=0; ;; |
| 636 |
'-tag') buildtag=1; ;; |
| 637 |
'-no-tag') buildtag=0; ;; |
| 638 |
'-tcl' | '-wish') inst_tcl=1; ;; |
| 639 |
'-no-tcl' | '-no-wish') inst_tcl=0; ;; |
| 640 |
'-force-rm' | '--force-rm') buildfrm="--force-rm"; ;; |
| 641 |
'-no-force-rm' | '--no-force-rm') buildfrm=""; ;; |
| 642 |
'-rm' | '--rm') build_rm="--rm"; ;; |
| 643 |
'-no-rm' | '--no-rm') build_rm=""; ;; |
| 644 |
'-del' | '--delete') host_del=1; ;; |
| 645 |
'-no-del' | '--no-delete') host_del=0; ;; |
| 646 |
'-clean') host_del=1; build_rm="--rm"; buildfrm="--force-rm"; ;; |
| 647 |
'-no-clean') host_del=0; build_rm=""; buildfrm=""; ;; |
| 648 |
|
| 649 |
'--') shift; break; ;; |
| 650 |
*) break; ;; |
| 651 |
esac |
| 652 |
shift |
| 653 |
done |
| 654 |
# TODO: options need to be documented |
| 655 |
|
| 656 |
# adapt platform-specific settings according options |
| 657 |
case "$image_from" in |
| 658 |
alpine*) _cfg_alpine "$image_from"; ;; |
| 659 |
debian*) _cfg_debian "$image_from"; ;; |
| 660 |
esac |
| 661 |
|
| 662 |
# commands for package manager |
| 663 |
case "$apt" in |
| 664 |
'apk') apt_add="add --no-cache"; apt_del="del --purge"; ;; |
| 665 |
'apt') apt_add="install"; apt_del="purge"; ;; |
| 666 |
esac |
| 667 |
|
| 668 |
[ "$try" = "echo" ] && _dbx_config && echo |
| 669 |
|
| 670 |
[ "$cmd" = "help" ] && my_help && exit 0; # just help, ready |
| 671 |
|
| 672 |
# make temp. directory, avoids: |
| 673 |
# unable to prepare context: the Dockerfile must be within the build context |
| 674 |
host_tmp=/tmp/$hostdate |
| 675 |
[ -d $host_tmp ] && echo "**ERROR: $host_tmp exists; aborted" && exit 2 |
| 676 |
\mkdir $host_tmp # no $try, because we need the dir |
| 677 |
if [ $? -ne 0 ]; then |
| 678 |
echo "**ERROR: create $host_tmp faild; aborted" |
| 679 |
exit 2 |
| 680 |
fi |
| 681 |
$try \cd $host_tmp |
| 682 |
|
| 683 |
case "$cmd" in |
| 684 |
'help') my_help $0; ;; |
| 685 |
'config') dockerfile $@; ;; |
| 686 |
'build') docker_build $@; ;; |
| 687 |
'load') docker_load $@; ;; |
| 688 |
'pull') docker_pull $@; ;; |
| 689 |
*) echo && echo "**WARNING: $0 $cmd ... unknown mode, ignored" && echo ; ;; |
| 690 |
esac |
| 691 |
|
| 692 |
[ $host_del -eq 1 ] && \rm -r $host_tmp # # no $try, because we used the dir |
| 693 |
|
| 694 |
exit |