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

Add directory init #58

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ the [RStudio Server Pro guide](https://docs.rstudio.com/ide/server-pro/authentic

| Variable | Description | Default |
|-----|---|---|
| `RSP_CREATE_USER` | Whether to create a user on startup. Turn off with any value other than "true" | true |
| `RSP_TESTUSER` | Test user to be created in the container, turn off with an empty value | `rstudio` |
| `RSP_TESTUSER_PASSWD` | Test user password | `rstudio` |
| `RSP_TESTUSER_UID` | Test user UID | `10000` |
Expand Down
5 changes: 4 additions & 1 deletion server-pro/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RUN curl -o /tmp/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-4.5
RUN /opt/python/${PYTHON_VERSION}/bin/pip install --no-cache-dir \
pip==20.0.2 \
jupyter==1.0.0 \
ipython==7.16.1 \
'jupyterlab<3.0.0' \
rsp_jupyter \
rsconnect_jupyter
Expand All @@ -67,6 +68,7 @@ RUN curl -L -o /usr/local/bin/wait-for-it.sh https://raw.githubusercontent.com/v
# Set default env values
ENV RSP_LICENSE ""
ENV RSP_LICENSE_SERVER ""
ENV RSP_CREATE_USER true
ENV RSP_TESTUSER rstudio
ENV RSP_TESTUSER_PASSWD rstudio
ENV RSP_TESTUSER_UID 10000
Expand All @@ -75,7 +77,8 @@ ENV RSP_LAUNCHER_TIMEOUT 10

# Copy config and startup
COPY startup.sh /usr/local/bin/startup.sh
RUN chmod +x /usr/local/bin/startup.sh
RUN chmod +x /usr/local/bin/startup.sh \
&& mkdir -p /entrypoint.d/
COPY conf/* /etc/rstudio/

# Install RStudio Server Pro --------------------------------------------------#
Expand Down
47 changes: 40 additions & 7 deletions server-pro/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ deactivate() {
}
trap deactivate EXIT

# usage: use_init_files [file [file [...]]]
# ie: use_init_files /mydir/*
# execute or source initialization files (file extensions and permissions)
use_init_files() {
echo
local file
for file; do
case "$file" in
*.sh)
if [ -x "$file" ]; then
echo "$0: executing file $file"
"$file"
else
echo "$0: sourcing file $file"
echo "$0: no execute bit set"
. "$file"
fi
;;
*) echo "$0: ignoring $file" ;;
esac
echo
done
}

# touch log files to initialize them
su rstudio-server -c 'touch /var/lib/rstudio-server/monitor/log/rstudio-server.log'
mkdir -p /var/lib/rstudio-launcher
Expand Down Expand Up @@ -51,21 +75,30 @@ unset RSP_LICENSE
unset RSP_LICENSE_SERVER

# Create one user
if [ $(getent passwd $RSP_TESTUSER_UID) ] ; then
echo "UID $RSP_TESTUSER_UID already exists, not creating $RSP_TESTUSER test user";
else
if [ -z "$RSP_TESTUSER" ]; then
echo "Empty 'RSP_TESTUSER' variables, not creating test user";
if [ "$RSP_CREATE_USER" == "true" ]; then
if [ $(getent passwd $RSP_TESTUSER_UID) ] ; then
echo "UID $RSP_TESTUSER_UID already exists, not creating $RSP_TESTUSER test user";
else
useradd -m -s /bin/bash -N -u $RSP_TESTUSER_UID $RSP_TESTUSER
echo "$RSP_TESTUSER:$RSP_TESTUSER_PASSWD" | sudo chpasswd
if [ -z "$RSP_TESTUSER" ]; then
echo "Empty 'RSP_TESTUSER' variables, not creating test user";
else
echo "Creating user $RSP_TESTUSER with UID $RSP_TESTUSER_UID"
useradd -m -s /bin/bash -N -u $RSP_TESTUSER_UID $RSP_TESTUSER
echo "$RSP_TESTUSER:$RSP_TESTUSER_PASSWD" | sudo chpasswd
fi
fi
fi

# Execute or source *.sh files from /entrypoint.d/
# - note that order should be deterministic thanks to * magic
use_init_files /entrypoint.d/*

# Start Launcher
if [ "$RSP_LAUNCHER" == "true" ]; then
/usr/lib/rstudio-server/bin/rstudio-launcher > /var/log/rstudio-launcher.log 2>&1 &
wait-for-it.sh localhost:5559 -t $RSP_LAUNCHER_TIMEOUT
else
touch /var/log/rstudio-launcher.log
fi

tail -n 100 -f \
Expand Down
3 changes: 3 additions & 0 deletions server-pro/test/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ file:
exists: true
owner: rstudio-server
group: rstudio-server
/entrypoint.d:
filetype: directory
exists: true

command:
"su rstudio-server -c 'touch /var/lib/rstudio-server/monitor/log/rstudio-server.log'":
Expand Down