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

fix: global git credentials and some other stuff #130

Merged
merged 2 commits into from
Oct 21, 2020
Merged
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
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ If you would like to add the ability to launch RenkuLab interactive environments
to your own pre-existing images, see the **Adding renku to your own images** section
below.


## Container initialization

Sometimes certain actions need to be performed on container start-up to prepare
the environment. Some of these are carried out already in the `entrypoint.sh`
script in the base image, but if you extend the image you may want to add your
own. This can be done by adding a `post-init.sh` script to the root directory of
the container. It must be executable by a non-privileged user because it will
run with the user restrictions of the container.

Projects using the base images may additionally place a `post-init.sh` script in
the root directory of the _project_. This script will also run upon initialization
of the container, but _after_ the `/entrypoint.sh` and `/post-init.sh` scripts.


## Naming Conventions

You can find these base images on
Expand Down Expand Up @@ -148,10 +163,6 @@ docker build -t <image-tag> \
https://github.com/SwissDataScienceCenter/renkulab-docker.git#docker/r
```





## Contributing

If you have any suggestions for different languages or base images you would like
Expand Down
14 changes: 14 additions & 0 deletions docker/py/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,25 @@ find /tmp/renku-env -not -path '*.git*' -type f -print0 | xargs --null -I{} sh -

if [[ -v CI_PROJECT ]];
then
# set the global git credentials
ableuler marked this conversation as resolved.
Show resolved Hide resolved
git config --global credential.helper "store --file=/work/${CI_PROJECT}/.git/credentials"

# link to the home work directory
ln -sf /work/${CI_PROJECT} ~/work
fi

# install git hooks
~/.local/bin/renku githooks install || true

# run the post-init script in the root directory (i.e. coming from the image)
if [ -f "/post-init.sh" ]; then
/post-init.sh
fi

# run the post-init script in the project directory
if [ -f "./post-init.sh" ]; then
./post-init.sh
fi

# run the command
$@
3 changes: 2 additions & 1 deletion docker/r/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ RUN apt-get update --fix-missing && \
COPY --from=renku_base /opt/conda /opt/conda
COPY --from=renku_base --chown=rstudio:rstudio \
/home/jovyan/ /home/rstudio/
COPY --from=renku_base /entrypoint.sh /entrypoint.sh

# set permissions of the R library directory to be editable by NB_USER
ADD fix-permissions.sh /usr/local/bin
Expand All @@ -90,7 +91,7 @@ RUN R --quiet -e "install.packages('IRkernel')" && \

RUN echo "source ~/.bashrc" >> ~/.bash_profile

COPY entrypoint.sh /entrypoint.sh
COPY post-init.sh /post-init.sh
ENTRYPOINT [ "/tini", "--", "/entrypoint.sh" ]
CMD [ "jupyterhub-singleuser" ]

Expand Down
28 changes: 0 additions & 28 deletions docker/r/entrypoint.sh → docker/r/post-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ for var in ${VariableArray[*]}; do
fi
done

# Setup git user
if [ -z "$(git config --global --get user.name)" ]; then
git config --global user.name "$GIT_AUTHOR_NAME"
fi
if [ -z "$(git config --global --get user.email)" ]; then
git config --global user.email "$EMAIL"
fi

# add a symlink to the project directory in /home/rstudio
[ -n "$CI_PROJECT" ] && ln -s /work/${CI_PROJECT} /home/rstudio

Expand All @@ -41,23 +33,3 @@ fi
mkdir -p /home/rstudio/.rstudio/projects_settings
echo /home/rstudio/${CI_PROJECT}/${CI_PROJECT}.Rproj | tee /home/rstudio/.rstudio/projects_settings/next-session-project
chown -R rstudio:root /home/rstudio/.rstudio/projects_settings

#
# copy the environment from renku-env repo
#

# clone the repo
proto=$(echo $GITLAB_URL | sed -e's,^\(.*://\).*,\1,g')
url=$(echo ${GITLAB_URL/$proto/})
user=$(echo ${CI_REPOSITORY_URL/$proto/} | grep @ | cut -d@ -f1)

git clone --depth 1 ${proto}${user}@${url}/${JUPYTERHUB_USER}/renku-env.git /tmp/renku-env || true

# append the contents of all the files to same files in ${HOME}
find /tmp/renku-env -not -path '*.git*' -type f -print0 | xargs --null -I{} sh -c 'cat {} >> ${HOME}/$(basename "{}")' || true

# install git hooks
~/.local/bin/renku githooks install || true

# run the command
$@