Skip to content

fix: session_script.sh: magic line has to be first#1123

Merged
sambuc merged 2 commits into
feat/secrets-and-dc-in-hpc-sessionsfrom
fix-session_script.ch-interpreter-line
May 20, 2026
Merged

fix: session_script.sh: magic line has to be first#1123
sambuc merged 2 commits into
feat/secrets-and-dc-in-hpc-sessionsfrom
fix-session_script.ch-interpreter-line

Conversation

@sambuc
Copy link
Copy Markdown
Contributor

@sambuc sambuc commented May 19, 2026

The magic line/interpreter line has to be the first of the file, otherwise it is simply ignored.

@sambuc sambuc requested review from a team and olevski as code owners May 19, 2026 09:41
Copy link
Copy Markdown
Member

@leafty leafty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???
The comments are removed before submission. This script is not meant to be executed "AS IS", which is the point of the NOTE FOR AMALTHEA MAINTAINERS at the top.

See templating code:

func (c *FirecrestRemoteSessionController) renderSessionScript(sessionScript string, fileSystems *[]FileSystem, secretsPath string) string {
return renderSessionScriptStatic(sessionScript, c.partition, fileSystems, secretsPath)
}
func renderSessionScriptStatic(sessionScript, partition string, fileSystems *[]FileSystem, secretsPath string) string {
sessionScriptFinal := removeMaintainersNotesFromScript(sessionScript)
sessionScriptFinal = addSbatchDirectivesToScript(sessionScriptFinal, partition)
sessionScriptFinal = addSessionMountsToScript(sessionScriptFinal, fileSystems, secretsPath)
return sessionScriptFinal
}
func removeMaintainersNotesFromScript(sessionScript string) string {
return sessionScriptNoteRegExp.ReplaceAllString(sessionScript, "")
}
func addSbatchDirectivesToScript(sessionScript, partition string) string {
directives := []string{
"#SBATCH --nodes=1",
"#SBATCH --ntasks-per-node=1",
}
if partition != "" {
directives = append(directives, fmt.Sprintf("#SBATCH --partition=%s", partition))
}
// The slurm account can be set by the user as an environment variable
slurmAccount := os.Getenv("USER_ENV_SLURM_ACCOUNT")
if slurmAccount != "" {
directives = append(directives, fmt.Sprintf("#SBATCH --account=%s", slurmAccount))
}
directivesStr := strings.Join(directives, "\n")
return strings.Replace(sessionScript, "#{{SBATCH_DIRECTIVES_PLACEHOLDER}}", directivesStr, 1)
}
func addSessionMountsToScript(sessionScript string, fileSystems *[]FileSystem, secretsPath string) string {
if fileSystems == nil {
return strings.Replace(sessionScript, "#{{SESSION_MOUNTS_PLACEHOLDER}}", "", 1)
}
// Collect file systems we want to mount
var home *FileSystem
scratches, stores := []*FileSystem{}, []*FileSystem{}
for _, fs := range *fileSystems {
switch fs.DataType {
case Scratch:
scratches = append(scratches, &fs)
case Store:
stores = append(stores, &fs)
case Users:
home = &fs
}
}
mounts := []string{}
for _, scratch := range scratches {
mounts = append(mounts, scratch.Path)
}
for _, store := range stores {
mounts = append(mounts, store.Path)
}
// TODO: Try to mount home at its location (need to handle ~/.bashrc)
// TODO: Alternatively, copy the contents in the container
if home != nil {
mounts = append(mounts, fmt.Sprintf("%s:/home%s:ro", home.Path, home.Path))
}
// Add the secrets mount
mounts = append(mounts, fmt.Sprintf("%s:/secrets:ro", secretsPath))
// Format mount list
for i := range mounts {
mounts[i] = fmt.Sprintf(" \"%s\",", mounts[i])
}
mountsStr := fmt.Sprintf("mounts = [\n%s\n]", strings.Join(mounts, "\n"))
return strings.Replace(sessionScript, "#{{SESSION_MOUNTS_PLACEHOLDER}}", mountsStr, 1)
}

@sambuc sambuc force-pushed the fix-session_script.ch-interpreter-line branch from ca102ed to 2624da3 Compare May 19, 2026 09:48
Copy link
Copy Markdown
Member

@leafty leafty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be tested on staging.

Comment thread internal/remote/firecrest/session_script.sh
Co-authored-by: Flora Thiebaut <flora.thiebaut@sdsc.ethz.ch>
@sambuc
Copy link
Copy Markdown
Contributor Author

sambuc commented May 20, 2026

This is currently deployed on staging via SwissDataScienceCenter/renku#4261

@sambuc sambuc changed the base branch from main to feat/secrets-and-dc-in-hpc-sessions May 20, 2026 06:08
Copy link
Copy Markdown
Member

@leafty leafty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, checked rendered job script.

@sambuc sambuc merged commit 40ce1c4 into feat/secrets-and-dc-in-hpc-sessions May 20, 2026
14 checks passed
@sambuc sambuc deleted the fix-session_script.ch-interpreter-line branch May 20, 2026 12:00
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

Successfully merging this pull request may close these issues.

2 participants