Skip to content

Commit 7907f57

Browse files
committed
Use .runonce for rust, dotnet, mysql, postgres, vnc, yugabyte to avoid race condition
1 parent d9ec66a commit 7907f57

File tree

11 files changed

+60
-45
lines changed

11 files changed

+60
-45
lines changed

chunks/lang-rust/Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ ENV PATH=$HOME/.cargo/bin:$PATH
1111
RUN curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --no-modify-path --default-toolchain stable \
1212
-c rls rust-analysis rust-src rustfmt clippy \
1313
&& for cmp in rustup cargo; do rustup completions bash "$cmp" > "$HOME/.local/share/bash-completion/completions/$cmp"; done \
14-
&& printf '%s\n' 'export CARGO_HOME=/workspace/.cargo' \
15-
'mkdir -m 0755 -p "$CARGO_HOME/bin" 2>/dev/null' \
16-
'export PATH=$CARGO_HOME/bin:$PATH' \
17-
'test ! -e "$CARGO_HOME/bin/rustup" && mv "$(command -v rustup)" "$CARGO_HOME/bin"' > $HOME/.bashrc.d/80-rust \
1814
&& cargo install cargo-watch cargo-edit cargo-workspaces \
1915
&& rm -rf "$HOME/.cargo/registry" # This registry cache is now useless as we change the CARGO_HOME path to `/workspace`
16+
17+
COPY --chown=gitpod:gitpod rust_bashrc.sh $HOME/.bashrc.d/80-rust
18+
COPY --chown=gitpod:gitpod rust_runonce.sh $HOME/.runonce/80-rust

chunks/lang-rust/rust_bashrc.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
if test -e "${GITPOD_REPO_ROOT:-}"; then {
4+
export CARGO_HOME=/workspace/.cargo
5+
export PATH=$CARGO_HOME/bin:$PATH
6+
}; fi

chunks/lang-rust/rust_runonce.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
if test -e "${GITPOD_REPO_ROOT:-}"; then {
4+
CARGO_HOME="/workspace/.cargo"
5+
mkdir -p "$CARGO_HOME/bin" 2>/dev/null
6+
7+
if test ! -e "$CARGO_HOME/bin/rustup" && rustup="$(command -v rustup)"; then {
8+
mv "${rustup}" "$CARGO_HOME/bin"
9+
}; fi
10+
}; fi

chunks/tool-dotnet/Dockerfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,4 @@ ENV PATH=/home/gitpod/dotnet:$PATH
1313

1414
# TODO(toru): Remove this hack when the kernel bug is resolved.
1515
# ref. https://github.com/gitpod-io/gitpod/issues/8901
16-
RUN bash \
17-
&& { echo 'if [ ! -z $GITPOD_REPO_ROOT ]; then'; \
18-
echo '\tCONTAINER_DIR=$(awk '\''{ print $6 }'\'' /proc/self/maps | grep ^\/run\/containerd | head -n 1 | cut -d '\''/'\'' -f 1-6)'; \
19-
echo '\tif [ ! -z $CONTAINER_DIR ]; then'; \
20-
echo '\t\t[[ ! -d $CONTAINER_DIR ]] && sudo mkdir -p $CONTAINER_DIR && sudo ln -s / $CONTAINER_DIR/rootfs'; \
21-
echo '\tfi'; \
22-
echo 'fi'; } >> /home/gitpod/.bashrc.d/110-dotnet
23-
RUN chmod +x /home/gitpod/.bashrc.d/110-dotnet
16+
COPY --chown=gitpod:gitpod dotnet_runonce.sh $HOME/.runonce/110-dotnet

chunks/tool-dotnet/dotnet_runonce.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -n "${GITPOD_REPO_ROOT:-}" ]; then
4+
CONTAINER_DIR=$(awk '{ print $6 }' /proc/self/maps | grep '^/run/containerd' | head -n 1 | cut -d '/' -f 1-6)
5+
if [ -n "${CONTAINER_DIR}" ] && [ ! -d "${CONTAINER_DIR}" ]; then
6+
sudo sh <<-CMD
7+
mkdir -p "${CONTAINER_DIR}" && ln -s / "${CONTAINER_DIR}/rootfs"
8+
CMD
9+
fi
10+
fi

chunks/tool-mysql/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ COPY mysql-bashrc-launch.sh /etc/mysql/mysql-bashrc-launch.sh
2121

2222
USER gitpod
2323

24-
RUN echo "/etc/mysql/mysql-bashrc-launch.sh" >> /home/gitpod/.bashrc.d/100-mysql-launch
24+
RUN echo "/etc/mysql/mysql-bashrc-launch.sh" >> $HOME/.runonce/100-mysql-launch

chunks/tool-postgresql/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ ENV PATH="$HOME/.pg_ctl/bin:$PATH"
2525
ENV DATABASE_URL="postgresql://gitpod@localhost"
2626
ENV PGHOSTADDR="127.0.0.1"
2727
ENV PGDATABASE="postgres"
28-
COPY --chown=gitpod:gitpod postgresql-hook.bash $HOME/.bashrc.d/200-postgresql-launch
28+
COPY --chown=gitpod:gitpod postgresql-hook.bash $HOME/.runonce/200-postgresql-launch
2929

3030
USER gitpod
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
#!/usr/bin/env bash
22
# Auto-start PostgreSQL server
3-
(
4-
if mkdir /tmp/.pgsql_lock 2>/dev/null; then {
5-
target="${PGWORKSPACE}"
6-
source="${target//\/workspace/$HOME}"
3+
target="${PGWORKSPACE}"
4+
source="${target//\/workspace/$HOME}"
75

8-
if test -e "$source"; then {
6+
if test -e "$source"; then {
97

10-
if test ! -e "$target"; then {
11-
mv "$source" "$target"
12-
}; fi
8+
if test ! -e "$target"; then {
9+
mv "$source" "$target"
10+
}; fi
1311

14-
if ! [[ "$(pg_ctl status)" =~ PID ]]; then {
15-
printf 'INFO: %s\n' "Executing command: pg_start"
16-
pg_start
17-
trap "pg_stop" TERM EXIT
18-
exec {sfd}<> <(:)
19-
printf 'INFO: %s\n' \
20-
"Please create another terminal" \
21-
"this one is monitoring postgres server for gracefully shutting down when needed"
22-
until read -r -t 3600 -u $sfd; do continue; done
23-
}; fi
12+
if ! [[ "$(pg_ctl status)" =~ PID ]]; then {
13+
printf 'INFO: %s\n' "Executing command: pg_start"
14+
pg_start
15+
(
16+
trap "pg_stop" TERM EXIT
17+
exec {sfd}<> <(:)
18+
# printf 'INFO: %s\n' \
19+
# "Please create another terminal" \
20+
# "this one is monitoring postgres server for gracefully shutting down when needed"
21+
until read -r -t 3600 -u $sfd; do continue; done
22+
) &
23+
disown
24+
}; fi
2425

25-
}; fi
26-
}; fi &
27-
)
26+
}; fi

chunks/tool-vnc/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ COPY novnc-index.html /opt/novnc/index.html
2121

2222
# Add VNC startup script
2323
COPY gp-vncsession /usr/bin/
24-
RUN chmod 0755 "$(which gp-vncsession)" \
25-
&& printf '%s\n' 'export DISPLAY=:0' \
26-
'test -e "$GITPOD_REPO_ROOT" && gp-vncsession' >> "$HOME/.bashrc"
24+
RUN printf 'export DISPLAY=:%s\n' '0' > "$HOME/.bashrc.d/1000-vnc" \
25+
&& printf '%s\n' 'gp-vncsession' > "$HOME/.runonce/1000-vnc"
2726
# Add X11 dotfiles
2827
COPY --chown=gitpod:gitpod .xinitrc $HOME/
2928

chunks/tool-vnc/gp-vncsession

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function log::info() {
1313
printf 'info[%s]: %s\n' "${0##*/}" "$@"
1414
}
1515

16-
if test ! -e /tmp/.X0-lock; then {
16+
if test ! -d /tmp/.X11-unix; then {
1717
: "${DISPLAY:=":0"}"
1818
export DISPLAY
1919
VNC_PORT=5900
@@ -47,12 +47,12 @@ if test ! -e /tmp/.X0-lock; then {
4747
## Create .xinit
4848
# log::info 'Creating .xinit script'
4949
# printf '%s\n' '#!/bin/sh' 'exec dbus-launch --exit-with-session xfce4-session;' > $HOME/.xinitrc;
50-
chmod 755 "$HOME/.xinitrc"
50+
# chmod 755 "$HOME/.xinitrc"
5151

5252
# Start vncserver
5353
log::info "Starting tigerVNC server on port $VNC_PORT"
5454
# vncserver -kill "${DISPLAY}"
55-
start_service "$(command -v vncserver)" -geometry "${TIGERVNC_GEOMETRY:-1920x1080}" -SecurityTypes None $DISPLAY
55+
start_service "$(command -v vncserver)" -geometry "${TIGERVNC_GEOMETRY:-1920x1080}" -SecurityTypes None "${DISPLAY}"
5656

5757
# Wait
5858
log::info "Waiting for the desktop to be fully loaded ..."

chunks/tool-yugabytedb/Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ ENV YSQL_API_PORT=13000
4949
ENV YCQL_API_PORT=12000
5050

5151
# re-initialization is automatically handled
52-
RUN echo "\n# yugabytedb start command" >> /home/gitpod/.bashrc.d/100-yugabyedb-launch
53-
RUN echo "[[ -f \${GITPOD_REPO_ROOT}/.nopreload ]] || yugabyted start --base_dir=$STORE --listen=$HOST > /dev/null" >> /home/gitpod/.bashrc.d/100-yugabyedb-launch
54-
55-
RUN chmod +x /home/gitpod/.bashrc.d/100-yugabyedb-launch
52+
RUN printf '%s\n' \
53+
"\n# yugabytedb start command" \
54+
"[[ -f \${GITPOD_REPO_ROOT}/.nopreload ]] || yugabyted start --base_dir=$STORE --listen=$HOST > /dev/null" > $HOME/.runonce/100-yugabyedb-launch
5655

5756
EXPOSE ${YSQL_PORT} ${YCQL_PORT} ${WEB_PORT} ${TSERVER_WEB_PORT} ${YSQL_API_PORT} ${YCQL_API_PORT}

0 commit comments

Comments
 (0)