Skip to content

Commit e0e096b

Browse files
authored
add db-client scripts (#74)
* add db-client scripts
1 parent 28c1b0d commit e0e096b

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
source /opt/utils/script-utils.sh
2+
3+
4+
setup_postgresql_client() {
5+
local VER_PG=${VERSION_PG:-"14"}
6+
# from: https://www.postgresql.org/download/linux/ubuntu/
7+
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
8+
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
9+
sudo apt-get update
10+
# will download ~9MB files and use ~55MB disk after installation
11+
sudo apt-get -y install "postgresql-client-${VER_PG}"
12+
echo "@ Version of psql client: $(psql --version)"
13+
}
14+
15+
16+
setup_mysql_client() {
17+
sudo apt-get update
18+
# will download ~5MB files and use ~76MB disk after installation
19+
sudo apt-get -y install mysql-client
20+
echo "@ Version of mysql client: $(mysql --version)"
21+
}
22+
23+
24+
setup_mongosh_client() {
25+
# from: https://www.mongodb.com/docs/mongodb-shell/install/
26+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/6.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-6.0.list
27+
curl -sL https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
28+
sudo apt-get update
29+
# will download ~38MB files and use ~218MB disk after installation
30+
sudo apt-get -y install mongodb-mongosh
31+
echo "@ Version of mongosh client: $(mongosh --version)"
32+
}
33+
34+
35+
setup_redis_client() {
36+
# from https://redis.io/docs/getting-started/installation/install-redis-on-linux/
37+
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
38+
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
39+
sudo apt-get update
40+
sudo apt-get -y install redis-tools
41+
echo "@ Version of redis-cli: $(redis-cli --version)"
42+
}

docker_atom/work/script-setup.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trusted-host=pypi.python.org pypi.org files.pythonhosted.org
2929
EOF
3030
fi
3131

32-
echo "export PATH=$PATH:${CONDA_PREFIX}/bin" >> /etc/profile
32+
echo 'export PATH=${PATH}:${CONDA_PREFIX:-"/opt/conda"}/bin' >> /etc/profile
3333
ln -sf "${CONDA_PREFIX}/bin/conda" /usr/bin/
3434

3535
conda config --system --prepend channels conda-forge \
@@ -53,9 +53,10 @@ EOF
5353
}
5454

5555
setup_conda_with_mamba() {
56-
mkdir -pv "${CONDA_PREFIX}"
56+
local PREFIX="${CONDA_PREFIX:-/opt/conda}"
57+
mkdir -pv "${PREFIX}"
5758
VERSION_PYTHON=${1:-"3.10"}; shift 1;
58-
mamba install -y --root-prefix="${CONDA_PREFIX}" --prefix="${CONDA_PREFIX}" -c "conda-forge" conda pip python="${VERSION_PYTHON}"
59+
mamba install -y --root-prefix="${PREFIX}" --prefix="${PREFIX}" -c "conda-forge" conda pip python="${VERSION_PYTHON}"
5960
setup_conda_postprocess
6061
}
6162

docker_atom/work/script-utils.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -x
44
install_echo() { cat $1 | cut -d "%" -f 1 | sed '/^$/d' | xargs -r -n1 printf '%s\n' ; }
55

66
# function to install apt-get packages from a text file which lists package names (add comments with % char)
7-
install_apt() { apt-get -qq update -yq --fix-missing && apt-get -qq install -yq --no-install-recommends `cat $1 | cut -d '%' -f 1` ; }
7+
install_apt() { apt-get -qq update -yq --fix-missing && apt-get -qq install -yq --no-install-recommends $(cat "$1" | cut -d '%' -f 1) ; }
88

99
# function to install conda packages from a text file which lists package names (add comments with % char)
1010
install_conda() { cat $1 | cut -d "%" -f 1 | sed '/^$/d' | xargs -r -n1 conda install -yq ; }
@@ -44,8 +44,8 @@ install_mvn() { cat $1 | cut -d "%" -f 1 | xargs -r -n1 -I {} mvn dependency:cop
4444
install__clean(){
4545
which apt-get && apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*
4646
which mamba && mamba clean -ya && rm -rf ~/micromamba
47-
which conda && conda clean -ya && ( rm -rf /opt/conda/pkgs/* || true )
48-
find /opt/conda/lib | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
47+
which conda && conda clean -ya && ( rm -rf "${CONDA_PREFIX:-/opt/conda}"/pkgs/* || true )
48+
find "${CONDA_PREFIX:-/opt/conda}"/lib | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
4949
which npm && npm cache clean --force
5050
rm -rf /opt/conda/share/jupyter/lab/staging
5151
( rm -rf /tmp/.* /tmp/* /var/log/* /var/cache/* /root/.cache /root/.* || true )
@@ -72,21 +72,21 @@ list_installed_packages() {
7272
}
7373

7474
fix_permission() {
75-
DIRECTORY=$1; GROUP_ID=$2; shift 2;
76-
for d in "$DIRECTORY"; do
75+
GROUP_ID=${1:-0}; shift 1;
76+
for d in "$@"; do
7777
find "${d}" \
7878
! \( \
7979
-group "${GROUP_ID}" \
8080
-a -perm -g+rwX \
8181
\) \
82-
-exec chgrp "${GROUP_ID}" {} \; \
83-
-exec chmod g+rwX {} \;
82+
-exec chgrp "${GROUP_ID}" -- {} \+ \
83+
-exec chmod g+rwX -- {} \+
8484
# setuid, setgid *on directories only*
8585
find "${d}" \
8686
\( \
8787
-type d \
8888
-a ! -perm -6000 \
8989
\) \
90-
-exec chmod +6000 {} \;
90+
-exec chmod +6000 -- {} \+;
9191
done
9292
}

docker_base/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ RUN source /opt/utils/script-setup.sh \
1515
&& echo "Install tini:" && setup_tini \
1616
&& echo "Install Mamba:" && setup_mamba \
1717
&& echo "Install Python ${PYTHON_VERSION} and conda:" && setup_conda_with_mamba ${PYTHON_VERSION} \
18+
&& fix_permission 0 ${CONDA_PREFIX} \
1819
&& echo "Replace system Python3 with conda Python - note that /bin and /sbin are symlinks of /usr/bin in docker image ubuntu" \
1920
&& PYTHON_VERSION_DEFAULT=$(py3versions -v -i) \
2021
&& sed -i "s/${PYTHON_VERSION_DEFAULT}/${PYTHON_VERSION}/g" /usr/share/python3/debian_defaults \

docker_cuda/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG}
66

77
LABEL maintainer="haobibo@gmail.com"
88

9+
# Let NVIDIA docker ignore cuda requirement check
10+
ENV NVIDIA_DISABLE_REUIRE=1
11+
912
# For cuda version 10.0, the image is solely serverd for legacy tensorflow 1.15, which requires python 3.7
1013
# For tensorflow 2.x or torch, python>=3.9 is supported.
1114
RUN echo ${CUDA_VERSION} && nvcc --version \

0 commit comments

Comments
 (0)