diff --git a/README.md b/README.md
index 3914394..4838c71 100644
--- a/README.md
+++ b/README.md
@@ -6,10 +6,10 @@ When you run containers (e.g. in Docker), you usually run a system that has a wh
The purpose of **minicon** is better understood with the use cases explained in depth in the section [Use Cases](#use-cases).
-1. **Basic Example ([direct link](#use-case-basic-example))**, that distributes only the set of tools, instead of distributing a whole Linux image. In this case the size is reduced from 123Mb. to about 8Mb.
-1. **Basic _user interface_ that need to access to other servers ([direct link](#use-case-basic-user-interface-ssh-cli-wget-vim))**. In this case we have reduced from 222Mb. to about 16Mb., and also we have made that the users only can use a reduced set of tools (ssh, ping, wget, etc.).
-1. **Node.JS+Express application ([direct link](#use-case-nodejsexpress-application))**: The size of the defaut NodeJS Docker image (i.e. node:latest), ready to run an application is about from 691MB. Applying **minicon** to that container, the size is reduced to about 45.4MB.
-1. **Use case: FFMPEG ([direct link](#use-case-ffmpeg))**: The size of a common _Ubuntu+FFMPEG_ image is about 387Mb., but if you apply **minicon** on that image, you will get a working _ffmpeg_ container whose size is only about 119Mb.
+1. **Basic Example ([direct link](#use-case-basic-example))**, that distributes only the set of tools, instead of distributing a whole Linux image. In this case the size is reduced from 123Mb. to about 5.54Mb.
+1. **Basic _user interface_ that need to access to other servers ([direct link](#use-case-basic-user-interface-ssh-cli-wget))**. In this case we have reduced from 222Mb. to about 11Mb., and also we have made that the users only can use a reduced set of tools (ssh, ping, wget, etc.).
+1. **Node.JS+Express application ([direct link](#use-case-nodejsexpress-application))**: The size of the defaut NodeJS Docker image (i.e. node:latest), ready to run an application is about from 691MB. Applying **minicon** to that container, the size is reduced to about 45.3MB.
+1. **Use case: FFMPEG ([direct link](#use-case-ffmpeg))**: The size of a common _Ubuntu+FFMPEG_ image is about 388Mb., but if you apply **minicon** on that image, you will get a working _ffmpeg_ container whose size is only about 119Mb.
## Why **minicon**?
@@ -150,6 +150,8 @@ To activate the strace plugin you can use the option ```--plugin```. Some exampl
$ ./minicon -t tarfile --plugin=scripts ./minicon
```
+> **DISCLAIMER**: take into account that the _scripts_ plugin is an automated tool and tries to make its best. If a interpreter is detected, all the default include folder for that interpreter will be added to the final filesystem. If you know your app, you can reduce the number of folders to include.
+
## Use Cases
This section includes the whole process to re-produce two use cases in which **minicon** can reduce the footprint of the size of the Docker containers.
@@ -175,40 +177,40 @@ Digest: sha256:7c67a2206d3c04703e5c23518707bdd4916c057562dd51c74b99b2ba26af0f79
Status: Downloaded newer image for ubuntu:latest
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
-ubuntu latest 20c44cd7596f 2 weeks ago 123MB
+ubuntu latest 20c44cd7596f 3 weeks ago 123MB
```
A simple example will be to create a container that only contains a few commands (e.g. _bash_, _ls_, _mkdir_, etc.):
```bash
-$ docker run --rm -it -v $PWD:/tmp/minicon ubuntu:latest /tmp/minicon/minicon -t /tmp/minicon/minibash.tar bash ls mkdir less cat find
+$ docker run --rm -it -v $PWD:/tmp/minicon ubuntu:latest /tmp/minicon/minicon -t /tmp/minicon/usecases/uc1/uc1.tar bash ls mkdir less cat find
[WARNING] 2017.12.05-12:45:24 disabling strace plugin because strace command is not available
[WARNING] 2017.12.05-12:45:24 disabling scripts plugin because file command is not available
```
Then you can import the container in Docker and check the difference of sizes:
```bash
-$ docker import minibash.tar ubuntu:minibash
-sha256:e4b5fa4f772d47b19ebe41544c52fd6c048a5a5d5abcac1d1e1efc30e3237025
+$ docker import usecases/uc1/uc1.tar minicon:uc1
+sha256:267c7ff2b27eabaaf931e5b0a7948c6545c176737cc2953bb030a696ef42d83d
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
-ubuntu minibash e4b5fa4f772d 20 seconds ago 9.44MB
-ubuntu latest 20c44cd7596f 2 weeks ago 123MB
+minicon uc1 267c7ff2b27e Less than a second ago 5.54MB
+ubuntu latest 20c44cd7596f 3 weeks ago 123MB
```
The size has been reduced dramatically, but **of course** you only have the requested files inside the container.
```bash
-$ tar tf minibash.tar
-$ docker run --rm -it ubuntu:minibash find /bin /lib /usr /lib64
-$ docker run --rm -it ubuntu:minibash ls /
+$ tar tf usecases/uc1/uc1.tar
+$ docker run --rm -it minicon:uc1 find /bin /lib /usr /lib64
+$ docker run --rm -it minicon:uc1 ls /
```
Click to show the whole execution (for verification purposes).
```bash
-$ tar tf minibash.tar
+$ tar tf usecases/uc1/uc1.tar
./
./bin/
./bin/cat
@@ -239,7 +241,7 @@ $ tar tf minibash.tar
./lib64/
./lib64/ld-linux-x86-64.so.2
./dev/
-$ docker run --rm -it ubuntu:minibash find /bin /lib /usr /lib64
+$ docker run --rm -it minicon:uc1 find /bin /lib /usr /lib64
/bin
/bin/cat
/bin/ls
@@ -266,16 +268,16 @@ $ docker run --rm -it ubuntu:minibash find /bin /lib /usr /lib64
/usr/bin/find
/lib64
/lib64/ld-linux-x86-64.so.2
-$ docker run --rm -it ubuntu:minibash ls /
+$ docker run --rm -it minicon:uc1 ls /
bin dev etc lib lib64 proc sys tmp usr
```
Welcome to Express
``` -If you inspect the size of the miniapp image, you will see something like the next: +If you inspect the size of the built image, you will see something like the next: ```bash $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE +minicon uc3fat 80168974cfa4 4 minutes ago 685MB node latest c1d02ac1d9b4 13 days ago 676MB -miniapp latest feb69da10e8b 43 minutes ago 691MB ``` The _node:latest_ image contains a whole debian distribution, but we only want to run a NodeJS+Express application @@ -412,16 +414,16 @@ We are using **minicon** to strip out any other things but the files that we nee And now run **minicon** to get only the files needed (take into account that now we need the interpreter (node) and the app folder (i.e. /usr/src/app)): ``` -root@2ed82c5454a9:/tmp/minicon# ./minicon -l -t miniapp.tar node /usr/src/app +root@2ed82c5454a9:/tmp/minicon# ./minicon -l -t /tmp/minicon/usecases/uc3/uc3.tar node /usr/src/app [WARNING] 2017.11.29-18:15:18 disabling strace plugin because strace command is not available root@2ed82c5454a9:/tmp/minicon# exit ``` And finally we can create the container that only contains the NodeJS interpreter and our NodeJS+Express application: ``` -~/minicon$ docker import miniapp.tar miniapp:lean -sha256:82624eebfc0b0b9f7cdb9959c8d372ccf06573f94578d4ef717f463a70f5fcb7 -~/minicon$ docker run --rm -it -w /usr/src/app -p 3000:3000 miniapp:lean node bin/www +~/minicon$ docker import usecases/uc3/uc3.tar minicon:uc3 +sha256:73f77fa9fca0192e843523e6fb12c5bdcb79fb85768de751435dbfe642a4b611 +~/minicon$ docker run --rm -it -w /usr/src/app -p 3000:3000 minicon:uc3 node bin/www ``` And it is possible to interact with the application. @@ -431,19 +433,19 @@ The difference comes when you check the size of the new image compared to the pr ```bash $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE -miniapp lean 82624eebfc0b 5 minutes ago 45.4MB +minicon uc3 73f77fa9fca0 Less than a second ago 45.3MB +minicon uc3fat 80168974cfa4 4 minutes ago 685MB node latest c1d02ac1d9b4 13 days ago 676MB -miniapp latest feb69da10e8b 43 minutes ago 691MB ``` -In this case we have reduced the size of the container from 691MB to 45.4MB. +In this case we have reduced the size of the container from 691MB to 45.3MB. ### Use case: FFMPEG -**TL;DR:** The size of a common _Ubuntu+FFMPEG_ image is about 387Mb., but if you apply **minicon** on that image, you will get a working _ffmpeg_ container whose size is only about 119Mb. +**TL;DR:** The size of a common _Ubuntu+FFMPEG_ image is about 388Mb., but if you apply **minicon** on that image, you will get a working _ffmpeg_ container whose size is only about 119Mb. Imagine that you want to run the latest version of the app _ffmpeg_ to convert your video files. The usual way to proceed will consist of: -1. Creating a Docker file with a content like the next one: +1. Creating a Docker file with a content like the next one (located in ```./usecases/uc4```): ```Dockerfile FROM ubuntu @@ -453,13 +455,13 @@ RUN apt-get -y update && apt-get -y install ffmpeg 2. Building the container ```bash -$ docker build . -t ubuntu:ffmpeg +$ docker build . -t minicon:uc4fat ``` 3. Run the application ```bash -$ docker run --rm -it -v /myvideos:/tmp/myvideos ubuntu:ffmpeg ffmpeg /tmp/myvideos ... +$ docker run --rm -it -v /myvideos:/tmp/myvideos minicon:uc4fat ffmpeg /tmp/myvideos ... ``` This usual procedure is ok, but if you take a look at the size of the image, you will find something as follows: @@ -467,57 +469,43 @@ This usual procedure is ok, but if you take a look at the size of the image, you ```bash $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE -ubuntu ffmpeg 816069cb64a1 5 days ago 387MB -ubuntu latest 2fa927b5cdd3 18 months ago 122MB +minicon uc4fat 1ce54cdefdce Less than a second ago 388MB +ubuntu latest 20c44cd7596f 3 weeks ago 123MB ``` The problem is that in the image ```ubuntu:ffmpeg``` you have both _ffmpeg_ and the whole _ubuntu:latest_ base operating system. You will not run any other app appart from _ffmpeg_ (i.e. you do not need _mount_, _ssh_, _tar_, _rm_, etc.), but they are there: ```bash -$ docker run --rm -it ubuntu:ffmpeg ls -l /bin -total 7360 --rwxr-xr-x 1 root root 1037464 Aug 31 2015 bash --rwxr-xr-x 1 root root 52080 Feb 18 2016 cat --rwxr-xr-x 1 root root 60272 Feb 18 2016 chgrp --rwxr-xr-x 1 root root 56112 Feb 18 2016 chmod --rwxr-xr-x 1 root root 64368 Feb 18 2016 chown --rwxr-xr-x 1 root root 151024 Feb 18 2016 cp +$ docker run --rm -it minicon:uc4fat ls -l /bin +total 7364 +-rwxr-xr-x 1 root root 1037528 May 16 2017 bash +-rwxr-xr-x 1 root root 52080 Mar 2 2017 cat +-rwxr-xr-x 1 root root 60272 Mar 2 2017 chgrp +-rwxr-xr-x 1 root root 56112 Mar 2 2017 chmod +-rwxr-xr-x 1 root root 64368 Mar 2 2017 chown +-rwxr-xr-x 1 root root 151024 Mar 2 2017 cp -rwxr-xr-x 1 root root 154072 Feb 17 2016 dash --rwxr-xr-x 1 root root 68464 Feb 18 2016 date --rwxr-xr-x 1 root root 72632 Feb 18 2016 dd --rwxr-xr-x 1 root root 97912 Feb 18 2016 df --rwxr-xr-x 1 root root 126584 Feb 18 2016 dir --rwxr-xr-x 1 root root 60680 Apr 13 2016 dmesg +-rwxr-xr-x 1 root root 68464 Mar 2 2017 date +-rwxr-xr-x 1 root root 72632 Mar 2 2017 dd +-rwxr-xr-x 1 root root 97912 Mar 2 2017 df +-rwxr-xr-x 1 root root 126584 Mar 2 2017 dir +-rwxr-xr-x 1 root root 60680 Jun 14 21:51 dmesg lrwxrwxrwx 1 root root 8 Nov 24 2015 dnsdomainname -> hostname lrwxrwxrwx 1 root root 8 Nov 24 2015 domainname -> hostname --rwxr-xr-x 1 root root 31376 Feb 18 2016 echo --rwxr-xr-x 1 root root 28 Apr 5 2016 egrep +-rwxr-xr-x 1 root root 31376 Mar 2 2017 echo +-rwxr-xr-x 1 root root 28 Apr 29 2016 egrep ... ``` **minicon** can reduce the footprint of the filesystem by only including the application _ffmpeg_ and those libraries and files needed by _ffmpeg_. #### Stripping all the unneeded files -From the **minicon** commandline you can start a container that has the _ffmpeg_ application, and map the **minicon** folder: +From the **minicon** commandline you can start a container that has the _ffmpeg_ application, start the minimization of the filesystem by issuing the next command: ```bash -$ docker run --rm -it -v $PWD:/tmp/minicon ubuntu:ffmpeg bash -``` - -There you will get to the shell inside the container. And now you can start the minimization of the filesystem by issuing the next command: - -``` -root@c41b836e6f77:/# /tmp/minicon/minicon --ldconfig --tarfile /tmp/minicon/miniffmpeg.tar ffmpeg +$ docker run --rm -it -v $PWD:/tmp/minicon minicon:uc4fat /tmp/minicon/minicon --ldconfig --tarfile /tmp/minicon/usecases/uc4/uc4.tar ffmpeg [WARNING] 2017.11.29-15:30:47 disabling strace plugin because strace command is not available [WARNING] 2017.11.29-15:30:47 disabling scripts plugin because file command is not available -root@c41b836e6f77:/# exit -user@ubuntu:~/minicon$ ls -l -total 116116 --rw-rw-r-- 1 user user 11357 nov 29 15:20 LICENSE --rwxrwxr-x 1 user user 11988 nov 29 16:30 minicon --rwxrwxr-x 1 user user 2418 nov 29 16:08 minicondocker --rw-r--r-- 1 root root 118886400 nov 29 16:30 miniffmpeg.tar --rw-rw-r-- 1 user user 3408 nov 29 16:31 README.md ``` The result is that you have a tar file that contains a filesystem that only includes _ffmpeg_ and the libraries needed to run it. @@ -525,9 +513,9 @@ The result is that you have a tar file that contains a filesystem that only incl Now you can import the filesystem into Docker and run _ffmpeg_ but this time from the new minified container: ``` -user@ubuntu:~/minicon$ docker import miniffmpeg.tar ffmpeg:mini +user@ubuntu:~/minicon$ docker import usecases/uc4/uc4.tar minicon:uc4 sha256:3eac8bc3a29bcffb462b1b24dbd6377b4f94b009b18a1846dd83022beda7e3f8 -user@ubuntu:~/minicon$ docker run --rm -it ffmpeg:mini ffmpeg +user@ubuntu:~/minicon$ docker run --rm -it minicon:uc4 ffmpeg ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609 configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv @@ -551,9 +539,9 @@ You can verify that the footprint of the container has been reduced: ```bash $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE -ubuntu ffmpeg 816069cb64a1 5 days ago 387MB -ubuntu latest 2fa927b5cdd3 18 months ago 122MB -ffmpeg mini 3eac8bc3a29b About a minute ago 119MB +minicon uc4 c3ae3608e431 1 second ago 119MB +minicon uc4fat 1ce54cdefdce Less than a second ago 388MB +ubuntu latest 20c44cd7596f 3 weeks ago 123MB ``` -The size of the common _Ubuntu+FFMPEG_ image is about 387Mb., but if you apply **minicon** on that image, you will get a working _ffmpeg_ container whose size is only about 119Mb. +The size of the common _Ubuntu+FFMPEG_ image is about 388Mb., but if you apply **minicon** on that image, you will get a working _ffmpeg_ container whose size is only about 119Mb. diff --git a/minicon b/minicon index a30de70..6684572 100755 --- a/minicon +++ b/minicon @@ -216,7 +216,12 @@ function copy() { # copies one file (or folder) to the same destination in the root filesystem # - it does not overwrite contents local SRC="$1" - local FILE="$2" + + if [ "$SRC" == "." -o "$SRC" == ".." ]; then + p_warning "cowardly refusing to copy folder $SRC" + return + fi + local DST if [ "$VERBOSE" == "true" ]; then p_info " processing $SRC... " @@ -224,15 +229,9 @@ function copy() { if [ ! -e "$SRC" ]; then p_error 1 "failed to read $SRC" fi - if [ "$FILE" != "" ]; then - mkdir -p "$(dirname "$ROOTFS/$FILE")" - fi local SRCDIR="$(dirname "$SRC")" DST="$ROOTFS/$SRCDIR" mkdir -p "$DST" - if [ "$FILE" != "" ]; then - echo "$SRCDIR" >> "$ROOTFS/$FILE" - fi p_debug " copying $SRC to $DST" if [ -d "$SRC" ]; then cp -n -r "$SRC" "$DST" @@ -241,6 +240,19 @@ function copy() { fi } +# Credits fot this function go to https://stackoverflow.com/a/18898782 +# Return relative path from canonical absolute dir path $1 to canonical +# absolute dir path $2 ($1 and/or $2 may end with one or no "/"). +# Does only need POSIX shell builtins (no external command) +function relPath () { + local common path up + common=${1%/} path=${2%/}/ + while test "${path#"$common"/}" = "$path"; do + common=${common%/*} up=../$up + done + path=$up${path#"$common"/}; path=${path%/}; printf %s "${path:-.}" +} + function is_plugin_active() { # Checks whether a plugin is activated or not if [[ "$PLUGINS_ACTIVATED" =~ (^|,)$1(|:[^,]+)(,|$) ]]; then @@ -271,7 +283,41 @@ function plugin_parameter() { return 1 } -function PLUGIN_00_folder() { +function PLUGIN_00_link() { + # If the path is a link to other path, we will create the link and analyze the real path + local L_PATH="$1" + + if [ -h "$L_PATH" ]; then + local L_DST="$ROOTFS/$(dirname "$L_PATH")" + local R_PATH="$(readlink -f "$L_PATH")" + local R_DST="$ROOTFS/$(dirname "$R_PATH")" + mkdir -p "$L_DST" + + if [ ! -e "$L_DST/$(basename $L_PATH)" ]; then + local REL_PATH="$(relPath "$L_DST" "$R_DST")" + p_debug "$L_PATH is a link to $REL_PATH/$(basename $R_PATH)" + ln -s $REL_PATH/$(basename $R_PATH) $L_DST/$(basename $L_PATH) + fi + + add_command "$R_PATH" + return 1 + fi +} + +function PLUGIN_01_which() { + # This plugin tries to guess whether the command to analize is in the path or not. + # If the command can be obtained calling which, we'll analyze the actual command and not the short name. + local S_PATH="$1" + local W_PATH="$(which $S_PATH)" + + if [ "$W_PATH" != "" -a "$W_PATH" != "$S_PATH" ]; then + p_debug "$1 is $W_PATH" + add_command "$W_PATH" + return 1 + fi +} + +function PLUGIN_02_folder() { # If it is a folder, just copy it to its location in the new FS local S_PATH="$1" @@ -289,6 +335,7 @@ function PLUGIN_09_ldd() { local S_PATH="$1" local LIBS= LIB= local COMMAND="$(which -- $S_PATH)" + local LIB_DIR= if [ "$COMMAND" == "" ]; then COMMAND="$S_PATH" fi @@ -304,7 +351,12 @@ function PLUGIN_09_ldd() { if [ $? -eq 0 ]; then LIBS="$(ldd "$COMMAND" | grep -v 'linux-vdso' | grep -v 'statically' | sed 's/^[ \t]*//g' | sed 's/^.* => //g' | sed 's/(.*)//' | sed '/^[ ]*$/d')" for LIB in $LIBS; do - copy "$LIB" "$LDCONFIGGILE" + # Here we build the ld config file to add the new paths where the libraries are located + if [ "$LDCONFIGFILE" != "" ]; then + LIB_DIR="$(dirname "$LIB")" + mkdir -p "$ROOTFS/$(dirname $LDCONFIGFILE)" + echo "$LIB_DIR" >> "$ROOTFS/$LDCONFIGFILE" + fi add_command "$LIB" done fi @@ -465,7 +517,8 @@ function PLUGIN_11_scripts() { # If it is, adds the interpreter to the list of commands to add to the container p_debug "trying to guess if $1 is a interpreted script" - local S_PATH="$(which -- $1)" + local S_PATH="$(which $1)" + local ADD_PATHS= if [ "$S_PATH" == "" ]; then p_warning "$1 cannot be executed (if it should, please check the path)" @@ -477,9 +530,11 @@ function PLUGIN_11_scripts() { FILE_RES="${FILE_RES,,}" local SHELL_EXEC= case "$FILE_RES" in - python) SHELL_EXEC=$(which python);; + python) SHELL_EXEC=$(which python) + ADD_PATHS="$(python -c 'import sys;print "\n".join(sys.path)' | grep -v '/home')";; "bourne-again shell") SHELL_EXEC=$(which bash);; - "a /usr/bin/perl") SHELL_EXEC=$(which perl);; + "a /usr/bin/perl") SHELL_EXEC=$(which perl) + ADD_PATHS="$(perl -e "print qq(@INC)" | tr ' ' '\n' | grep -v '/home')";; esac # If we found a known interpreter, we'll add to the list of dependencies @@ -487,6 +542,14 @@ function PLUGIN_11_scripts() { p_debug "found that $S_PATH needs $SHELL_EXEC" add_command "$SHELL_EXEC" fi + # The include folders + if [ "$ADD_PATHS" != "" ]; then + p_debug "found that $S_PATH needs $ADD_PATHS" + local P + while read P; do + add_command "$P" + done <<< "$ADD_PATHS" + fi return 0 } @@ -504,7 +567,7 @@ function plugin_list() { } # Now we are activating the basic plugins -PLUGINS_ACTIVATED=folder,ldd +PLUGINS_ACTIVATED=link,which,folder,ldd COMMANDS_TO_ADD=() FORCEFOLDER=false ROOTFS= @@ -533,7 +596,7 @@ while [ $n -lt ${#ARR[@]} ]; do --quiet|-q) QUIET=true;; --tarfile|-t) n=$(($n+1)) TARFILE="${ARR[$n]}";; - --ldconfig|-l) LDCONFIGGILE=/etc/ld.so.conf;; + --ldconfig|-l) LDCONFIGFILE=/etc/ld.so.conf;; --verbose|-v) VERBOSE=true;; --debug) DEBUG=true;; --force|-f) FORCEFOLDER=true;; @@ -606,8 +669,11 @@ while [ $i_current -lt ${#COMMANDS_TO_ADD[@]} ]; do i_current=$(($i_current+1)) done -if [ "$LDCONFIGGILE" != "" -a -e "$ROOTFS/$LDCONFIGGILE" ]; then +if [ "$LDCONFIGFILE" != "" -a -e "$ROOTFS/$LDCONFIGFILE" ]; then p_debug "creating ldconfig" + TMPFILE=$(tempfile) + awk '!a[$0]++' "$ROOTFS/$LDCONFIGFILE" > "$TMPFILE" + mv "$TMPFILE" "$ROOTFS/$LDCONFIGFILE" ldconfig -r "$ROOTFS" fi diff --git a/usecases/uc1/uc1.sh b/usecases/uc1/uc1.sh new file mode 100755 index 0000000..6f47ef9 --- /dev/null +++ b/usecases/uc1/uc1.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# minicon - Minimization of filesystems for containers +# https://github.com/grycap/minicon +# +# Copyright (C) GRyCAP - I3M - UPV +# Developed by Carlos A. caralla@upv.es +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +UC=1 +UCFOLDER=usecases/uc${UC} +CURDIR=$(dirname $0) +MINICONDIR=$(readlink -f $CURDIR/../..) + +set -x +docker images ubuntu:latest +docker run --rm -it -v $MINICONDIR:/tmp/minicon ubuntu:latest /tmp/minicon/minicon -t /tmp/minicon/$UCFOLDER/uc${UC}.tar bash ls mkdir less cat find +docker import $MINICONDIR/$UCFOLDER/uc${UC}.tar minicon:uc${UC} +docker images minicon:uc${UC} diff --git a/usecases/uc2/Dockerfile b/usecases/uc2/Dockerfile new file mode 100644 index 0000000..20f1eb2 --- /dev/null +++ b/usecases/uc2/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu +RUN apt-get update && apt-get install -y ssh iproute2 iputils-ping wget diff --git a/usecases/uc2/uc2.sh b/usecases/uc2/uc2.sh new file mode 100755 index 0000000..fef717d --- /dev/null +++ b/usecases/uc2/uc2.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# minicon - Minimization of filesystems for containers +# https://github.com/grycap/minicon +# +# Copyright (C) GRyCAP - I3M - UPV +# Developed by Carlos A. caralla@upv.es +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +UC=2 +UCFOLDER=usecases/uc${UC} +REFIMAGE=minicon:uc${UC}fat +MINICONIMAGE=minicon:uc${UC} + +CURDIR=$(dirname $0) +MINICONDIR=$(readlink -f $CURDIR/../..) + +docker build $UCFOLDER -t $REFIMAGE + +cat > $UCFOLDER/execfile-cmd <<\EOF +ssh localhost +/usr/bin/ssh localhost +/bin/ping -c 1 www.google.es +EOF + +set -x +docker images $REFIMAGE +docker run --privileged --rm -it -v $MINICONDIR:/tmp/minicon $REFIMAGE bash -c "apt-get install -y strace && /tmp/minicon/minicon -t /tmp/minicon/$UCFOLDER/uc${UC}.tar -l --plugin=strace:execfile=/tmp/minicon/$UCFOLDER/execfile-cmd bash ssh ip id cat ls mkdir ping wget" +docker import $MINICONDIR/$UCFOLDER/uc${UC}.tar $MINICONIMAGE +docker images $MINICONIMAGE diff --git a/usecases/uc3/Dockerfile b/usecases/uc3/Dockerfile new file mode 100644 index 0000000..4881c3d --- /dev/null +++ b/usecases/uc3/Dockerfile @@ -0,0 +1,14 @@ +FROM node:latest + +# Create app directory +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +# Install app dependencies +COPY miniapp/package.json /usr/src/app/ +RUN npm install + +# Bundle app source +COPY miniapp /usr/src/app + +EXPOSE 3000 \ No newline at end of file diff --git a/usecases/uc3/uc3.sh b/usecases/uc3/uc3.sh new file mode 100755 index 0000000..3fddf4e --- /dev/null +++ b/usecases/uc3/uc3.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# minicon - Minimization of filesystems for containers +# https://github.com/grycap/minicon +# +# Copyright (C) GRyCAP - I3M - UPV +# Developed by Carlos A. caralla@upv.es +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +UC=3 +UCFOLDER=usecases/uc${UC} +REFIMAGE=minicon:uc${UC}fat +MINICONIMAGE=minicon:uc${UC} + +CURDIR=$(dirname $0) +MINICONDIR=$(readlink -f $CURDIR/../..) + +set -x +express -f ./usecases/uc3/miniapp +docker build $UCFOLDER -t $REFIMAGE +docker images $REFIMAGE +docker run --rm -it -v $MINICONDIR:/tmp/minicon $REFIMAGE /tmp/minicon/minicon -l -t /tmp/minicon/$UCFOLDER/uc${UC}.tar node /usr/src/app +docker import $MINICONDIR/$UCFOLDER/uc${UC}.tar $MINICONIMAGE +docker images $MINICONIMAGE diff --git a/usecases/uc4/Dockerfile b/usecases/uc4/Dockerfile new file mode 100644 index 0000000..94792c0 --- /dev/null +++ b/usecases/uc4/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu +RUN apt-get update && apt-get install -y ffmpeg diff --git a/usecases/uc4/uc4.sh b/usecases/uc4/uc4.sh new file mode 100755 index 0000000..631d6fa --- /dev/null +++ b/usecases/uc4/uc4.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# minicon - Minimization of filesystems for containers +# https://github.com/grycap/minicon +# +# Copyright (C) GRyCAP - I3M - UPV +# Developed by Carlos A. caralla@upv.es +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +UC=4 +UCFOLDER=usecases/uc${UC} +REFIMAGE=minicon:uc${UC}fat +MINICONIMAGE=minicon:uc${UC} + +CURDIR=$(dirname $0) +MINICONDIR=$(readlink -f $CURDIR/../..) + +set -x +docker build $UCFOLDER -t $REFIMAGE +docker images $REFIMAGE +docker run --rm -it -v $MINICONDIR:/tmp/minicon $REFIMAGE /tmp/minicon/minicon -l -t /tmp/minicon/$UCFOLDER/uc${UC}.tar ffmpeg +docker import $MINICONDIR/$UCFOLDER/uc${UC}.tar $MINICONIMAGE +docker images $MINICONIMAGE