feat(buildah): align script with target functionality

correct variable names, add whitespaces
This commit is contained in:
phoenix 2025-04-17 13:39:14 +01:00
parent b53cd0b1c0
commit 6b0d3525cd

64
build-analytics-backend-workspace.sh Normal file → Executable file
View File

@ -5,54 +5,48 @@
set -euo pipefail set -euo pipefail
IMG_NAME="analytics-backend-workspace" IMG_NAME="analytics-backend-workspace"
DEV_USER=devuser
SECURE=/opt/secure SECURE=/opt/secure
DEV_HOME=/home/devuser DEV_HOME=/home/$DEV_USER
ctr=$(buildah from registry.fedoraproject.org/fedora-minimal:40) ctr=$(buildah from registry.fedoraproject.org/fedora-minimal:42)
buildah run "$ctr" -- bash -c "microdnf update -y && buildah run "$ctr" -- bash -c "
microdnf install -y && microdnf update -y && microdnf install -y neovim git zsh tmux podman \
neovim git zsh tmux podman fzf fd ripgrep && fzf fd ripgrep java-devel maven gnupg attr && \
java-17-openjdk maven shadow-utils gnupg attr && microdnf clean all && useradd -ms /bin/zsh $DEV_USER && \
microdnf clean all && useradd --system --no-create-home --shell /usr/sbin/nologin viewer && \
useradd -ms /bin/zsh devuser && usermod -aG $DEV_USER viewer && mkdir -p /tmp/tmux-shared && \
echo 'devuser ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/devuser && chmod 750 /tmp/tmux-shared && chown $DEV_USER:$DEV_USER /tmp/tmux-shared \
mkdir -p $DEV_HOME/.gnupg $DEV_HOME/.git-credentials mkdir -p $DEV_HOME/.gnupg && chmod 700 $DEV_HOME/.gnupg && \
chown $DEV_USER:$DEV_USER $DEV_HOME/.gnupg
" "
# copy start script
buildah copy "$ctr" start.sh /start.sh
# copy ssh setup # copy ssh setup
buildah copy "$ctr" ssh /"$SECURE"/ssh buildah copy "$ctr" ssh /"$SECURE"/ssh
# copy neovim and tmux setup # copy zshrc, neovim and tmux setup
buildah copy "$ctr" config /home/devuser/.config buildah copy "$ctr" zshrc $DEV_HOME/.zshrc
buildah copy "$ctr" local /home/devuser/.local buildah copy "$ctr" config $DEV_HOME/.config
buildah copy "$ctr" local $DEV_HOME/.local
# zsh and tmux config (immutable) # zsh and tmux config (immutable)
buildah copy "$ctr" zshrc /home/devuser/.zshrc buildah run "$ctr" -- bash -c "
buildah run "$ctr" -- chmod -R 600 /home/devuser/.zshrc find $DEV_HOME -type f -exec chmod 400 {} + && \
buildah run "$ctr" -- chattr +i /home/devuser/.zshrc find $DEV_HOME -type d -exec chmod 500 {} + && \
buildah run "$ctr" -- bash -c 'echo "set -g mouse on" > /home/devuser/.tmux.conf' find $DEV_HOME -mindepth 1 -exec chattr +i {} + && \
buildah run "$ctr" -- chattr +i /home/devuser/.config/tmux/tmux.conf.local chmod -R 500 $SECURE && \
chattr -R +i $SECURE && \
# Git config and secrets placeholder (immutable) chmod 511 /start.sh
buildah run "$ctr" -- mkdir -p /home/devuser/.gnupg /home/devuser/.git-credentials "
buildah copy "$ctr" ./gitconfig /home/devuser/.gitconfig
buildah copy "$ctr" ./gpg-key.asc /home/devuser/.gnupg/gpg-key.asc
buildah run "$ctr" -- chattr +i /home/devuser/.gitconfig
buildah run "$ctr" -- chattr +i /home/devuser/.gnupg/gpg-key.asc
# Neovim config (immutable)
buildah run "$ctr" -- chmod -R 600 /home/devuser/.config/nvim
buildah run "$ctr" -- chattr -R +i /home/devuser/.config
buildah run "$ctr" -- chown -R devuser:devuser /home/devuser
buildah config \ buildah config \
--user devuser \ --user $DEV_USER \
--workingdir /home/devuser \ --workingdir /app \
--env CONTAINER_HOST=unix:///run/podman/podman.sock \ --env CONTAINER_HOST=unix:///run/podman/podman.sock \
--env GIT_SSH=/usr/local/bin/git-ssh-wrapper.sh \ --cmd ["$DEV_HOME/start.sh"] \
--cmd '["/home/devuser/start.sh"]' \
"$ctr" "$ctr"
buildah commit "$ctr" $IMG_NAME buildah commit "$ctr" $IMG_NAME