Verified Commit 1f0aa19d authored by Philipp Sebastian Sommer's avatar Philipp Sebastian Sommer
Browse files

add docker files

previously they have been stored in a separate project: https://gitlab.hzdr.de/model-data-explorer/docker-workspace/
parent 39c8f3b7
......@@ -138,4 +138,13 @@ dmypy.json
cython_debug/
.vscode/settings.json
docs/workspace/build
\ No newline at end of file
# build documentation files
docs/workspace/build
# docker-related workspace and other files that are cloned during installation
workspace
!*/**/workspace
users_config/
code-server.env
!docker/workspace/templates/*.env
docker/workspace/config/extensions/*.vsix
\ No newline at end of file
# syntax=docker/dockerfile:1
FROM ghcr.io/linuxserver/code-server
ENV PYTHONUNBUFFERED=1
# install necessary libraries using apt-get
RUN apt-get update && \
apt-get install -y \
bash-completion vim \
graphviz \
libpq-dev build-essential \
python3-venv python3-dev python3-psycopg2 \
python3.8-venv python3.8-dev
# install git-mob
RUN npm i -g git-mob
COPY docker/workspace/config /config
COPY docker/workspace/git-user-management /config/git-user-management
RUN make -C /config/git-user-management install
ADD . /config/workspace_src
EXPOSE 8443
version: "3.7"
networks:
frontend:
backend:
volumes:
pgdata:
thredds-data:
thredds-config:
x-op-restart-policy: &restart_policy
restart: unless-stopped
x-mde-pg-env: &pg-env
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-changeme}"
POSTGRES_USER: "${POSTGRES_USER:-django_mde_user}"
POSTGRES_DB: "${POSTGRES_DB:-django_mde}"
services:
db:
image: postgres:13
<<: *restart_policy
stop_grace_period: "3s"
volumes:
- "pgdata:/var/lib/postgresql/data"
environment: *pg-env
networks:
- backend
cache:
image: memcached
<<: *restart_policy
networks:
- backend
code-server:
build: "."
<<: *restart_policy
volumes:
- "thredds-data:/config/workspace/thredds/data"
- "thredds-config:/config/workspace/thredds/config"
- "./workspace:/config/workspace"
- "./users_config:/config/users_config"
networks:
- frontend
- backend
expose:
- "8443"
ports:
- "${PORT:-8443}:8443"
env_file:
- code-server.env
environment:
<<: *pg-env
PUID: "${PUID:-1000}"
PGID: "${PGID:-1000}"
TZ: "${TZ:-Europe/Berlin}"
DEFAULT_GIT_USER_NAME: "${DEFAULT_GIT_USER_NAME:-}"
DEFAULT_GIT_USER_EMAIL: "${DEFAULT_GIT_USER_EMAIL:-}"
depends_on:
- db
- cache
# Model Data Explorer Workspace
Docker-based Workspace for developing the Model Data Explorer
Please checkout the docs to learn how to use and install this workspace:
https://model-data-explorer.readthedocs.io/projects/workspace
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] - \[\e[36m\]\A\[\e[m\] - \[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h - \A - \w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# add intials of current co-authors
function git_initials {
local initials=$(git mob-print --initials)
if [[ -n "${initials}" ]]; then
echo " [${initials}]"
fi
}
export PS1="\$(pwd)\$(git_initials) -> "
export GPG_TTY="$(tty || :)"
"\e[A": history-search-backward
"\e[B": history-search-forward
#!/bin/bash
# populate the workspace
#
# This script clones the workspace repository at https://gitlab.hzdr.de/model-data-explorer/workspace.git
# and installs it at /config/workspace, including the python virtual
# environment. Additionally, it starts some static file servers to host the
# documentation. They are accessible with the browser at
#
# /proxy/9001 https://gitlab.hzdr.de/model-data-explorer/model-data-explorer.pages.hzdr.de
# /proxy/9002 https://gitlab.hzdr.de/model-data-explorer/prototype
#
# NOTE: We do not overwrite any existing folder here
set -e
cd /config/workspace
cp -r /config/workspace_src/. .
if [[ ! -d venv ]]; then
echo "**** setting up python ****"
PYTHON=python3.8 install.sh
else
echo "**** python already setup. skipping ****"
fi
# build and serve the docs
source venv/bin/activate
# main repo
[ ! -d docs/main/build/html ] && sphinx-build docs/main/source docs/main/build/html
nohup python -m http.server --directory docs/main/build/html 9001 &
# prototype repo
[ ! -d docs/prototype/build/html ] && sphinx-build docs/prototype/source docs/prototype/build/html
nohup python -m http.server --directory docs/prototype/build/html 9002 &
chown -R abc: .
#!/bin/bash
code-server --extensions-dir /config/extensions --install-extension ms-python.python
code-server --extensions-dir /config/extensions --install-extension lextudio.restructuredtext
code-server --extensions-dir /config/extensions --install-extension gitlab.gitlab-workflow
code-server --extensions-dir /config/extensions --install-extension njpwerner.autodocstring
if [ ! -z "$(ls -A /config/extensions/*.vsix)" ]; then
for FNAME in /config/extensions/*.vsix; do
code-server --extensions-dir /config/extensions --install-extension ${FNAME}
done
fi
#!/bin/bash
# Configure command line git
#
# In this script, we set the global git user.name and user.email, and we add
# create the .git-coauthors file (if not already existing).
#
# We then check for GPG keys in /config/certs and add the corresponding names
# to the .git-coauthors file.
#
# Furthermore we give the user the possibility to specify the global git
# user.name via the DEFAULT_GIT_USER_NAME environment variable, and the global
# git user.email via the DEFAULT_GIT_USER_EMAIL environment variable.
set -e
git config --global commit.gpgsign true
if [[ ! -e ~/users_config/.git-coauthors ]]; then
mkdir -p ~/users_config
echo '{"coauthors": {}}' > ~/users_config/.git-coauthors
fi
if [[ ! -e ~/users_config/.gnupg ]]; then
mkdir -p ~/users_config/.gnupg
fi
chmod 700 ~/users_config/.gnupg
ln -sf ~/users_config/.git-coauthors ~/.git-coauthors
ln -sf ~/users_config/.gnupg ~/.gnupg
git add-coauthors
if [[ ${DEFAULT_GIT_USER_NAME} ]]; then
git config --global user.name ${DEFAULT_GIT_USER_NAME}
fi
if [[ ${DEFAULT_GIT_USER_EMAIL} ]]; then
git config --global user.email ${DEFAULT_GIT_USER_EMAIL}
fi
if [ "${DEFAULT_GIT_USER_NAME}" != "" ] && [ "${DEFAULT_GIT_USER_EMAIL}" != "" ]; then
INITIALS=""
for NAME in ${DEFAULT_GIT_USER_NAME}; do
INITIALS="${INITIALS}${NAME:0:1}"
done
git add-coauthor ${INITIALS,,} "${DEFAULT_GIT_USER_NAME}" ${DEFAULT_GIT_USER_EMAIL}
fi
chown -R abc: /config/users_config
{
"python.defaultInterpreterPath": "/config/workspace/venv/bin/python",
"python.pythonPath": "/config/workspace/venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": true,
"editor.defaultFormatter": "ms-python.python",
"files.trimTrailingWhitespace": true,
"editor.formatOnType": true,
"editor.rulers": [
79
],
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"79"
],
"python.formatting.autopep8Path": "/config/workspace/venv/bin/autopep8",
"python.formatting.blackPath": "/config/workspace/venv/bin/black",
"python.linting.mypyCategorySeverity.note": "Hint",
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": "/config/workspace/venv/bin/mypy",
"python.linting.pylintPath": "/config/workspace/venv/bin/pylint",
"python.linting.pycodestylePath": "/config/workspace/venv/bin/pycodestyle",
"python.linting.pydocstylePath": "/config/workspace/venv/bin/pydocstyle",
"python.linting.flake8Path": "/config/workspace/venv/bin/flake8",
"python.linting.flake8Enabled": true,
"gitlab.instanceUrl": "https://gitlab.hzdr.de",
"restructuredtext.sphinxBuildPath": "/config/workspace/venv/bin/sphinx-build",
"restructuredtext.preview.scrollEditorWithPreview": false,
"restructuredtext.preview.scrollPreviewWithEditor": false,
"restructuredtext.languageServer.disabled": true,
"autoDocstring.docstringFormat": "numpy",
"autoDocstring.includeExtendedSummary": true,
"terminal.integrated.env.linux": {
"LC_ALL": "en_US.UTF-8",
"LANG": "en_US.UTF-8",
"LANGUAGE": "en_US.UTF-8",
"DISPLAY": ":0"
},
"editor.formatOnSave": true,
"git.enableCommitSigning": true,
"git.enableSmartCommit": true
}
# PREFIX is environment variable, but if it is not set, then set default value
BINDIR = $(DESTDIR)/usr/bin
COMPLETIONDIR = $(DESTDIR)/etc/bash_completion.d
install:
install git-* $(BINDIR)/
install -m 644 git_user_management.sh $(COMPLETIONDIR)/
uninstall:
rm $(BINDIR)/git-add-user
rm $(COMPLETIONDIR)/git_user_management.sh
#!/bin/bash
# Add all GPG UIDs as git-coauthors
set -e
function Help() {
cat << EOF
Add all GPG UIDs as git-coauthors
This command looks up the GPG keys and adds one entry for each key to the
~/.git-coauthors file.
Call syntax::
git add-coauthors
Syntax: git add-coauthors [-h]
options:
h Print this Help.
EOF
}
function trim() {
local STRING="$*"
# remove leading spaces
STRING="${STRING#"${STRING%%[![:space:]]*}"}"
# remove trailing spaces
STRING="${STRING%"${STRING##*[![:space:]]}"}"
printf '%s' "$STRING"
}
while getopts ":h" option; do
case $option in
h) # display Help
Help
exit;;
\?) # incorrect option
echo "Error: Invalid option"
exit 1;;
esac
done
function get_initials() {
local INITIALS
local FULLNAME="${1}"
local INITIALS=""
for NAME in $FULLNAME; do
INITIALS="${INITIALS}${NAME:0:1}"
done
echo ${INITIALS}
}
while IFS= read -r GPG_UID; do
EMAIL=`echo "${GPG_UID}" | grep -Po '<\K[^>]+(?=>)'`
FULLNAME=`echo "${GPG_UID}" | grep -Po '.*?(?=\<)'`
FULLNAME="`trim ${FULLNAME}`"
INITIALS=$(get_initials "${FULLNAME}")
git add-coauthor ${INITIALS,,} "${FULLNAME}" "${EMAIL}"
done < <(git show-users)
#!/bin/bash
# Convenience command to create a GPG key and add a git co-author
set -e
function Help() {
cat << EOF
Convenience command to create a GPG key and add a git co-author
This command takes a full name and an email as argument and creates a
GPG key (the user is asked for a passphrase). At the end, this function
adds the newly created user to ~/.git-coauthors and opens the public
key using code-server to import it at gitlab.
Call syntax::
git add-user "Full Name" full.name@example.com
Syntax: git add-user [-h] FullName Email
mandatory arguments:
FullName The full name of the user
Email The email of the user
options:
h Print this Help.
EOF
}
function get_initials() {
local INITIALS
local FULLNAME="${1}"
local INITIALS=""
for NAME in $FULLNAME; do
INITIALS="${INITIALS}${NAME:0:1}"
done
echo ${INITIALS}
}
while getopts ":h" option; do
case $option in
h) # display Help
Help
exit;;
\?) # incorrect option
echo "Error: Invalid option"
exit 1;;
esac
done
FULLNAME="${1}"
EMAIL="${2}"
if [[ "${FULLNAME}" == "" ]] || [[ "${EMAIL}" == "" ]]; then
>&2 echo "Please specify FULLNAME and EMAIL"
echo ""
Help
exit 1
fi
GPG_UID="${FULLNAME} <${EMAIL}>"
INITIALS=$(get_initials "${FULLNAME}")
gpg --quick-generate-key "${GPG_UID}"
FPR=`git get-user-fpr "${GPG_UID}"`
echo ""
git add-coauthor ${INITIALS} "${FULLNAME}" "${EMAIL}"
echo ""
git switch-user "${GPG_UID}"
echo ""
TMPDIR=$(mktemp -d /tmp/gpg.XXXXXXXXX)
TMPFILE=${TMPDIR}/${FPR}.asc
gpg --armor --export ${FPR} > ${TMPFILE}
code-server ${TMPFILE}
cat << EOF
You are almost done! We created a file at ${TMPFILE} for you. You see it in the
editor above. Just paste the public key at https://gitlab.hzdr.de/-/profile/gpg_keys
and you're done.
EOF
#!/bin/bash
# Get the fingerprint of a UID
function Help() {
cat << EOF
Get the fingerprint of a UID
This function takes one argument, the UID as "Full Name <email>" and
returns the corresponding fingerprint (if there is one)
Call syntax::
git get-user-fpr "Full Name <full.name@example.com>"
Syntax: git get-user-fpr [-h] UID
mandatory arguments:
UIDorFile The UID of the GPG Key or the path to a key
options:
h Print this Help.
EOF
}
while getopts ":h" option; do
case $option in
h) # display Help
Help
exit;;
\?) # incorrect option
echo "Error: Invalid option"
exit 1;;
esac
done
FPR=""
GPG_UID="${1}"
if [[ "${GPG_UID}" == "" ]]; then
>&2 echo "Please specify the UID of the GPG Key to lookup"