Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using docker2singularity to build images from Singularity definition files #98

Open
nathanweeks opened this issue Feb 25, 2021 · 2 comments

Comments

@nathanweeks
Copy link
Contributor

Would it be a bad idea to use docker2singularity to build Singularity images from Singularity definition files with singularity build? Lightly modifying the example in the Singularity 3.7 User Guide
, modifying the %files section to copy some file ("test.py") in the current working directory, and using the docker engine from Docker Desktop for Mac 20.10.3:

$ cat singularity.def 
Bootstrap: library
From: ubuntu:18.04
Stage: build

%setup
    touch /file1
    touch ${SINGULARITY_ROOTFS}/file2

%files
    test.py /opt

%environment
    export LISTEN_PORT=12345
    export LC_ALL=C

%post
    apt-get update && apt-get install -y netcat
    NOW=`date`
    echo "export NOW=\"${NOW}\"" >> $SINGULARITY_ENVIRONMENT

%runscript
    echo "Container was created $NOW"
    echo "Arguments received: $*"
    exec echo "$@"

%startscript
    nc -lp $LISTEN_PORT

%test
    grep -q NAME=\"Ubuntu\" /etc/os-release
    if [ $? -eq 0 ]; then
        echo "Container base is Ubuntu as expected."
    else
        echo "Container base is not Ubuntu."
        exit 1
    fi

%labels
    Author d@sylabs.io
    Version v0.0.1

%help
    This is a demo container used to illustrate a def file that uses all
    supported sections.
$ docker run -t --rm --privileged -v /etc/localtime -v $(pwd):/mnt -w /mnt --entrypoint=singularity quay.io/singularity/docker2singularity:v3.7.1 build ubuntu.sif singularity.def 
INFO:    Starting build...
INFO:    Downloading library image
52.1MiB / 52.1MiB [==============================================================================] 100 % 18.3 MiB/s 0s
INFO:    Verifying bootstrap image /root/.singularity/cache/library/sha256.35055a42993db1469734fd488feddc747bdaabc0956b3aabf72c9b1f9385b209
WARNING: integrity: signature not found for object group 1
WARNING: Bootstrap image could not be verified, but build will continue.
INFO:    Running setup scriptlet
+ touch /file1
+ touch /tmp/build-temp-471078291/rootfs/file2
INFO:    Copying test.py to /tmp/build-temp-471078291/rootfs/opt
INFO:    Running post scriptlet
+ apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu bionic/main Translation-en [516 kB]
Fetched 516 kB in 1s (693 kB/s)        
Reading package lists... Done
+ apt-get install -y netcat
Reading package lists... Done
Building dependency tree... Done
Note, selecting 'netcat-openbsd' instead of 'netcat'
The following additional packages will be installed:
  libbsd0
The following NEW packages will be installed:
  libbsd0 netcat-openbsd
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 81.0 kB of archives.
After this operation, 270 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 libbsd0 amd64 0.8.7-1 [41.5 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 netcat-openbsd amd64 1.187-1 [39.6 kB]
Fetched 81.0 kB in 0s (322 kB/s)     
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libbsd0:amd64.
(Reading database ... 4006 files and directories currently installed.)
Preparing to unpack .../libbsd0_0.8.7-1_amd64.deb ...
Unpacking libbsd0:amd64 (0.8.7-1) ...
Selecting previously unselected package netcat-openbsd.
Preparing to unpack .../netcat-openbsd_1.187-1_amd64.deb ...
Unpacking netcat-openbsd (1.187-1) ...
Setting up libbsd0:amd64 (0.8.7-1) ...
Setting up netcat-openbsd (1.187-1) ...
update-alternatives: using /bin/nc.openbsd to provide /bin/nc (nc) in auto mode
Processing triggers for libc-bin (2.27-3ubuntu1) ...
+ date
+ NOW=Thu Feb 25 21:21:31 UTC 2021
+ echo export NOW="Thu Feb 25 21:21:31 UTC 2021"
INFO:    Adding help info
INFO:    Adding labels
INFO:    Adding environment to container
INFO:    Adding startscript
INFO:    Adding runscript
INFO:    Adding testscript
INFO:    Running testscript
Container base is Ubuntu as expected.
INFO:    Creating SIF file...
INFO:    Build complete: ubuntu.sif
$ docker run -it --rm --privileged -v /etc/localtime -v $(pwd):/mnt -w /mnt --entrypoint=singularity quay.io/singularity/docker2singularity:v3.7.1 shell ubuntu.sif
Singularity> cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Singularity> ls /opt
test.py

If there aren't too many drawbacks to this approach (I realize this use of %setup wouldn't impact the "real" host), maybe it could be mentioned in the README.md (with an example)? Or would there be a more preferable base image to use?

@vsoch
Copy link
Member

vsoch commented Feb 25, 2021

That's a cool idea - and I don't see why not! Would you like to create and add a contributed example?

@nathanweeks
Copy link
Contributor Author

Sure thing! I'll do some additional experimentation over & try to come up with a suitable example within the next 2-3 weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants