Skip to content

Commit

Permalink
Fix permissions (hopefully) and get aliases working again
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed May 30, 2024
1 parent 695bbd3 commit 326a243
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 54 deletions.
33 changes: 19 additions & 14 deletions docker/dev_env/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
FROM docker.io/library/fedora:latest
FROM docker.io/library/fedora:latest AS base-system

# We want to keep all important things in `/opt` as we will preserve the
# `/opt` directory as a volume.

# location where pipx installs its tools
ENV PIPX_HOME="/opt/pipx"
# location where pipx symlinks the binaries, must be on the path
ENV PIPX_BIN_DIR="/opt/pipx/bin"
# Set HOME to /opt so XDG-respecting utilities automatically use it
# without additional configuration
# This gets chmodded with wide open permissions, so that
# on Linux hosts, the explicitly passed user (with docker group)
# is able to read/write from here, as well as the root user used by
# macOS hosts (who don't have Docker permissions or host filesystem
# permissions issues to contend with and as such run the container as root)
ENV HOME="/opt"

# location where PDM installs Python interpreters
ENV PDM_PYTHONS="/opt/pdm/bin"
ENV PDM_PYTHONS="${HOME}/pdm/bin"
# location where `n` installs Node.js versions
ENV N_PREFIX="/opt/n"
# location where pre-commit stores environments
ENV PRE_COMMIT_HOME="/opt/pre-commit"
ENV N_PREFIX="${HOME}/n"

# Add tooling installed in custom locations to `PATH`.
ENV PATH="${N_PREFIX}/bin:${PDM_PYTHONS}:${PIPX_BIN_DIR}:${PATH}"
ENV PATH="${N_PREFIX}/bin:${PDM_PYTHONS}:${HOME}/.local/bin:${PATH}"

# Dependency explanations:
# - git: required by some python package; contributors should use git on their host
Expand All @@ -42,16 +45,18 @@ RUN dnf -y install dnf-plugins-core \
gcc \
just \
which \
pipx \
nodejs \
nodejs npm \
python3.12 pipx \
docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin \
&& pipx install \
pdm pipenv \
pre-commit \
&& npm install -g \
&& npm install -g \
n \
corepack \
&& corepack enable
&& corepack enable

RUN bash -c 'chmod -Rv 0777 /opt'

# Avoid overwriting `.venv`'s from the host
ENV PDM_VENV_IN_PROJECT="False"
Expand Down
27 changes: 2 additions & 25 deletions docker/dev_env/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ fi

cd "$OPENVERSE_PROJECT" || exit 1

suppress_output() {
"$@" 2>/dev/null 1>/dev/null
}

suppress_output corepack install
corepack install

if [ -z "$(n ls 2>/dev/null)" ]; then
printf "Installing the specific Node JS version required by Openverse frontend; this is only necessary the first time the toolkit runs\n"
Expand Down Expand Up @@ -53,23 +49,4 @@ if [ -n "$PDM_CACHE_DIR" ]; then
pdm config install.cache on
fi

_profiles=(
"$OPENVERSE_PROJECT"/.ovprofile
"$OPENVERSE_PROJECT"/docker/dev_env/bash_profile.sh
)

for profile in "${_profiles[@]}"; do
if [ -f "$profile" ]; then
if grep -q '^alias ' "$profile"; then
printf "Aliases in %s will not work. Use functions instead." "$profile" >>/dev/stderr
exit 1
fi

# SC1090 cannot be disabled directly
# Workaround from https://github.com/koalaman/shellcheck/issues/2038#issuecomment-680513830
# shellcheck source=/dev/null
source "$profile"
fi
done

exec "$@"
bash -c "$@"
17 changes: 13 additions & 4 deletions docker/dev_env/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

set -e

suppress_output() {
"$@" 2>/dev/null 1>/dev/null
}

run_args=(
-i
--rm
Expand Down Expand Up @@ -35,6 +31,19 @@ if [ -t 0 ]; then
run_args+=(-t)
fi

case "$OSTYPE" in
linux*)
run_args+=(--user "$UID:$(getent group docker | cut -d: -f3)")
;;
darwin*)
# noop, just catching them to avoid the fall-through error case
;;
*)
printf "Openverse development is only supported on Linux and macOS hosts. Please use WSL to run the Openverse development environment under Linux on Windows computers." >/dev/stderr
exit 1
;;
esac

host_pnpm_store="$(pnpm store path 2>/dev/null || echo)"

# Share the pnpm cache with the container, if it's available locally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

# Personal aliases and utilities should go in an .ovprofile file at the monorepo root

j() {
just "$@"
}
declare -A shared_aliases
export shared_aliases

shared_aliases=(
[j]="just"
)
21 changes: 14 additions & 7 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,22 @@ init-ovprofile:
#! /usr/bin/env bash

# Personal modifications to the ov dev environment go here
# Use bash functions to define aliases of your common workflow
# Shared aliases are available in docker/dev_env/bash_profile
# Use additional entries in the associative bash array to define aliases
# Shared aliases (and more examples) are in docker/dev_env/shared_aliases.sh

# This is just an example bash function for demonstration. Feel free to delete it.
declare -A personal_aliases
export personal_aliases

personal_aliases=(
[welcome]="just welcome-to-openverse"
)
EOPROFILE

# Recipe used as example alias in default .ovprofile (see init-ovprofile)
welcome-to-openverse:
#! /usr/bin/env bash
# ASCII art courtesy of http://patorjk.com/software/taag/#p=display&f=Big&t=Openverse
welcome_to_openverse() {
cat <<OPENVERSE
cat <<OPENVERSE
___ ____ ___ ____ __ __ ___ ____ _____ ___
/ \ | \ / _]| \ | | | / _]| \ / ___/ / _]
| || o ) [_ | _ || | | / [_ | D )( \_ / [_
Expand All @@ -88,8 +97,6 @@ init-ovprofile:
| || | | || | | \ / | || . \ \ || |
\___/ |__| |_____||__|__| \_/ |_____||__|\_| \___||_____|
OPENVERSE
}
EOPROFILE

# Setup pre-commit as a Git hook
precommit:
Expand Down
21 changes: 20 additions & 1 deletion ov
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ _cmd="$1"

dev_env="$OPENVERSE_PROJECT"/docker/dev_env

# shellcheck source=./docker/dev_env/shared_aliases.sh
source "$dev_env/shared_aliases.sh"

if [ -f "$OPENVERSE_PROJECT/.ovprofile" ]; then
# shellcheck source=/dev/null
source "$OPENVERSE_PROJECT/.ovprofile"
fi

if [[ $_cmd == "help" || -z $_cmd ]]; then
cat <<-'EOF'
Openverse development toolkit
Expand Down Expand Up @@ -89,7 +97,18 @@ hook)
;;

*)
"$dev_env"/run.sh "$@"
declare -a rest
if [ -n "${personal_aliases[$_cmd]}" ]; then
rest=("${personal_aliases[$_cmd]}" "${@:2}")
elif [ -n "${shared_aliases[$_cmd]}" ]; then
rest=("${shared_aliases[$_cmd]}" "${@:2}")
else
rest=("$@")
fi

echo "${rest[@]}"

"$dev_env"/run.sh "${rest[@]}"
;;

esac

0 comments on commit 326a243

Please sign in to comment.