forked from nextflow-io/nextflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry.sh
executable file
·61 lines (54 loc) · 1.94 KB
/
entry.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
# Copyright 2013-2023, Seqera Labs
#
# 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.
#
# This script acts as a pass-through container entry point. Its main role
# is to create a user able to execute docker commands from the container
# connecting to the host docker socket at runtime.
#
# The invoker needs to pass the user ID using the variable NXF_USRMAP.
# When this variable is defined, it creates a new user in the container
# with such ID and adds it to the `docker` group, then assigns the docker
# socket file ownership to that user.
#
# Finally it switches the `nextflow` user using the `su` command and
# executes the original target command line.
#
# authors:
# Paolo Di Tommaso
# Emilio Palumbo
#
# enable debugging
[[ "$NXF_DEBUG_ENTRY" ]] && set -x
# wrap cli args with single quote to avoid wildcard expansion
cli=''; for x in "$@"; do cli+="'$x' "; done
# the NXF_USRMAP hold the user ID in the host environment
if [[ "$NXF_USRMAP" ]]; then
# create a `nextflow` user with the provided ID
groupadd docker
useradd -u "$NXF_USRMAP" -G docker -s /bin/bash nextflow
# then change the docker socket ownership to `nextflow` user
# and change the $NXF_HOME ownership to `nextflow` user
chown nextflow /var/run/docker.sock
chown -R nextflow /.nextflow
# finally run the target command with `nextflow` user
su nextflow << EOF
[[ "$NXF_DEBUG_ENTRY" ]] && set -x
exec bash -c "$cli"
EOF
# otherwise just execute the command
else
exec bash -c "$cli"
fi