Skip to content

Commit

Permalink
more updates to apptainer guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristinaLK committed Nov 13, 2024
1 parent 9adbcb1 commit 2edef52
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Apptainer to convert it to a SIF image:

After converting the Docker image to a sif format, you can use the
image in your job as described in the
[Apptainer/Singularity Guide](../containers-singularity).
[Apptainer/Singularity Guide](../containers-singularity#using-singularity-or-apptainer-images-in-an-htcondor-job).

## Special Cases

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,30 @@ in the Open Science Pool. You can use your own custom container to run
jobs in the Open Science Pool. This guide describes how to create your
own Apptainer/Singularity container "image" (the blueprint for the container).

## Identify Components
## Do You Need to Build a Container?

If there is an existing Docker container or Apptainer/Singularity container with
the software you need, you can proceed with using these options to submit a job.
* [See OSPool-provided containers here](../available-containers-list/)
* [Using an existing Docker container](../containers-docker/)
* [Using an existing Apptainer/Singularity container](#using-singularity-or-apptainer-images-in-an-htcondor-job)

If you can't find a good option among existing containers, you may need to
build your own. See [this section of the guide](#building-your-own-apptainer-singularity-container) for more information.

## OSG-Provided Apptainer/Singularity Images

The OSG Team maintains a set of images that are already in the OSG
Apptainer/Singularity repository. [A list of ready-to-use containers can be found on this page](../available-containers-list/).

If the software you need isn't already supported in a listed container,
you can create your own container or use any container image in Docker Hub.

How to explore these containers is shown [below](#exploring-apptainer-singularity-images-on-the-access-points).

## Building Your Own Apptainer/Singularity Container

### Identify Components

What software do you want to install? Make sure that you have either the source
code or a command that can be used to install it through Linux (like `apt-get` or
Expand All @@ -22,15 +45,7 @@ as your starting point. See the available containers on Docker Hub here:
[OSG Docker Containers](https://hub.docker.com/u/opensciencegrid)
The best candidates for you will be containers that have "osgvo" in the name.

## OSG-Provided Apptainer/Singularity Images

The OSG Team maintains a set of images that are already in the OSG
Apptainer/Singularity repository. [A list of ready-to-use containers can be found on this page](../available-containers-list/).

If the software you need isn't already supported in a listed container,
you can create your own container or any container image in Docker Hub.

## Apptainer/Singularity Build
### Apptainer/Singularity Build

If you are building an image for the first time, the temporary cache directory of the apptainer image needs to be defined. The following commands define the cache location of the apptainer image to be built. Please run the commands in the terminal of your access point.

Expand Down Expand Up @@ -128,8 +143,7 @@ Once your build spec is ready, you can "build" the container image by running th
Once the image is built, test it on an OSG-managed access point,
and use it in your HTCondor jobs.


### Exploring Apptainer/Singularity Images on the Access Points
## Exploring Apptainer/Singularity Images on the Access Points

Just like it is important to test your codes and jobs at a small scale,
you should make sure that your Apptainer/Singularity container is working correctly before using it in jobs. One way
Expand All @@ -142,31 +156,42 @@ to how containers are started for jobs, is:

apptainer shell my-container.sif

If you want to test an existing container produced by OSG Staff, use the
full path provided in [this guide](../available-containers-list/).

This example will give you an interactive shell. You can explore the
container and test your code with your own inputs from your `/home`
directory, which is automatically mounted (but note - $HOME will not be
available to your jobs later). Once you are down exploring, exit the
container by running `exit` or with `CTRL+D`
container by running `exit` or with `CTRL+D`.

## Using Singularity or Apptainer Images in an HTCondor Job

## Pre-existing .sif Apptainer/Singularity Images
Once you have a ".sif" container image file with all your needed software,
you can use this file as part of an HTCondor job.

### Upload the Container Image to the OSDF

The image will be resused for
each job, and thus the preferred transfer method is [OSDF](../../managing_data/osdf/).
Store the .sif file under the "protected" area on your access point
(see table [here](../../managing_data/overview/)), and then use the OSDF
Store the .sif file under your personal data area on your access point
(see table [here](../../managing_data/osdf/#where-to-put-your-files)).

### Use the Container in an HTCondor Job

Once the image is placed in your OSDF space, you can use an OSDF
url directly in the `+SingularityImage` attribute. Note that you can not
use shell variable expansion in the submit file - be sure to replace the
username with your actual OSPool username. Example:

+SingularityImage = "osdf:///ospool/protected/USERNAME/my-custom-image-v1.sif"
+SingularityImage = "osdf:///ospool/apXX/data/USERNAME/my-custom-image-v1.sif"

<other usual submit file lines>
queue

Be aware that OSDF aggressively caches the image based on file naming.
**Be aware that OSDF aggressively caches the image based on file naming.
If you need to do quick changes, please use versioning of the .sif file
so that the caches see a "new" name. In this example, replacing
so that the caches see a "new" name.** In this example, replacing
`my-custom-image-v1.sif` with new content will probably mean that some
nodes get the old version and some nodes the new version. Prevent this
by creating a new file named with v2.
Expand Down

0 comments on commit 2edef52

Please sign in to comment.