-
Notifications
You must be signed in to change notification settings - Fork 31
Request for Merge #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kerklangsi
wants to merge
14
commits into
MitchTalmadge:staging
Choose a base branch
from
kerklangsi:staging
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+333
−19
Open
Request for Merge #255
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
477a8ee
Add AMP licence reactivation support
kerklangsi 3f85cfe
Add Docker CLI support and dynamic volume mapping
kerklangsi 5d3077a
Refactor AMP user/group creation logic
kerklangsi 38d98dd
Rename variable for group GID in routines.sh
kerklangsi 0f292b8
modified: entrypoint/routines.sh
kerklangsi 8721e88
Merge branch 'staging' of https://github.com/kerklangsi/AMP-dockerize…
kerklangsi 7580ef2
Update entrypoint/routines.sh
kerklangsi e97ba17
Update entrypoint/routines.sh
kerklangsi fcbf966
Update entrypoint/routines.sh
kerklangsi 12d431e
Update entrypoint/routines.sh
kerklangsi ee6a64d
modified: entrypoint/routines.sh
kerklangsi 6136bb5
modified: entrypoint/routines.sh
kerklangsi 14f991d
modified: entrypoint/routines.sh
kerklangsi e70d07d
Merge branch 'staging' into staging
kerklangsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| # Docker wrapper to adjust volume mounts for AMP container | ||
| REAL_DOCKER="/usr/bin/docker" | ||
| CONTAINER_PREFIX="/home/amp" | ||
|
|
||
| # Normalize a path by removing trailing slashes | ||
| normalize_path() { | ||
| local value="$1" | ||
| if [ -z "$value" ]; then | ||
| echo "" | ||
| return | ||
| fi | ||
| while [ "${#value}" -gt 1 ] && [ "${value%/}" != "$value" ]; do | ||
| value="${value%/}" | ||
| done | ||
| echo "$value" | ||
| } | ||
|
|
||
| # Decode escaped characters in mount paths | ||
| decode_mount_path() { | ||
| local path="$1" | ||
| path="${path//\\040/ }" | ||
| path="${path//\\011/$'\t'}" | ||
| path="${path//\\012/$'\n'}" | ||
| path="${path//\\134/\\}" | ||
| echo "$path" | ||
| } | ||
|
|
||
| # Detect host mount prefix for the container prefix | ||
| detect_host_prefix() { | ||
| local mount_line | ||
| mount_line=$(awk -v mp="$CONTAINER_PREFIX" '$5==mp {print $4; exit}' /proc/self/mountinfo 2>/dev/null || true) | ||
| if [ -z "$mount_line" ] || [ "$mount_line" = "/" ]; then | ||
| echo "" | ||
| return | ||
| fi | ||
| decode_mount_path "$mount_line" | ||
| } | ||
|
|
||
| # Determine HOST_PREFIX | ||
| HOST_PREFIX="${AMP_HOST_HOME:-}" | ||
| if [ -z "$HOST_PREFIX" ]; then | ||
| HOST_PREFIX="$(detect_host_prefix)" | ||
| fi | ||
| HOST_PREFIX="$(normalize_path "$HOST_PREFIX")" | ||
| CONTAINER_PREFIX="$(normalize_path "$CONTAINER_PREFIX")" | ||
|
|
||
| # If no host prefix detected or same as container, run docker as-is | ||
| if [ -z "$HOST_PREFIX" ] || [ "$HOST_PREFIX" = "$CONTAINER_PREFIX" ]; then | ||
| exec "$REAL_DOCKER" "$@" | ||
| fi | ||
|
|
||
| # Helper to split quoted values | ||
| split_with_quote() { | ||
| local value="$1" | ||
| local quote="" | ||
| if [ "${value#\"}" != "$value" ] && [ "${value%\"}" != "$value" ]; then | ||
| quote='"' | ||
| value="${value#\"}" | ||
| value="${value%\"}" | ||
| elif [ "${value#\'}" != "$value" ] && [ "${value%\'}" != "$value" ]; then | ||
| quote="'" | ||
| value="${value#\'}" | ||
| value="${value%\'}" | ||
| fi | ||
| printf '%s|%s' "$quote" "$value" | ||
| } | ||
|
|
||
| # Rewrite volume argument | ||
| rewrite_volume_arg() { | ||
| local original="$1" | ||
| local src_with_quotes="${original%%:*}" | ||
| local remainder="${original#"$src_with_quotes"}" | ||
| local parsed | ||
| parsed="$(split_with_quote "$src_with_quotes")" | ||
| local quote="" | ||
| local src="" | ||
| IFS='|' read -r quote src <<<"$parsed" | ||
| if [ -n "$src" ] && { [ "$src" = "$CONTAINER_PREFIX" ] || [ "${src#$CONTAINER_PREFIX/}" != "$src" ]; }; then | ||
| local suffix="${src#$CONTAINER_PREFIX}" | ||
| local new_src="${HOST_PREFIX}${suffix}" | ||
| echo "${quote}${new_src}${quote}${remainder}" | ||
| return | ||
| fi | ||
| echo "$original" | ||
| } | ||
|
|
||
| # Rewrite mount argument | ||
| rewrite_mount_arg() { | ||
| local original="$1" | ||
| IFS=',' read -ra parts <<<"$original" | ||
| local updated=() | ||
| for part in "${parts[@]}"; do | ||
| local key="${part%%=*}" | ||
| local value="${part#*=}" | ||
| if [ "$key" = "source" ] || [ "$key" = "src" ]; then | ||
| local parsed | ||
| parsed="$(split_with_quote "$value")" | ||
| local quote="" | ||
| local path="" | ||
| IFS='|' read -r quote path <<<"$parsed" | ||
| if [ -n "$path" ] && { [ "$path" = "$CONTAINER_PREFIX" ] || [ "${path#$CONTAINER_PREFIX/}" != "$path" ]; }; then | ||
| local suffix="${path#$CONTAINER_PREFIX}" | ||
| local new_path="${HOST_PREFIX}${suffix}" | ||
| part="${key}=${quote}${new_path}${quote}" | ||
| fi | ||
| fi | ||
| updated+=("$part") | ||
| done | ||
| local IFS=',' | ||
| echo "${updated[*]}" | ||
| } | ||
|
|
||
| # Adjust all arguments | ||
| adjust_args() { | ||
| local -a result=() | ||
| while [ "$#" -gt 0 ]; do | ||
| local arg="$1" | ||
| case "$arg" in | ||
| -v) | ||
| if [ "$#" -gt 1 ]; then | ||
| result+=("-v" "$(rewrite_volume_arg "$2")") | ||
| shift | ||
| else | ||
| result+=("$arg") | ||
| fi | ||
| ;; | ||
| -v*) | ||
| result+=("-v$(rewrite_volume_arg "${arg#-v}")") | ||
| ;; | ||
| --volume) | ||
| if [ "$#" -gt 1 ]; then | ||
| result+=("--volume" "$(rewrite_volume_arg "$2")") | ||
| shift | ||
| else | ||
| result+=("$arg") | ||
| fi | ||
| ;; | ||
| --volume=*) | ||
| result+=("--volume=$(rewrite_volume_arg "${arg#--volume=}")") | ||
| ;; | ||
| --mount) | ||
| if [ "$#" -gt 1 ]; then | ||
| result+=("--mount" "$(rewrite_mount_arg "$2")") | ||
| shift | ||
| else | ||
| result+=("$arg") | ||
| fi | ||
| ;; | ||
| --mount=*) | ||
| result+=("--mount=$(rewrite_mount_arg "${arg#--mount=}")") | ||
| ;; | ||
| *) | ||
| result+=("$arg") | ||
| ;; | ||
| esac | ||
| shift | ||
| done | ||
| printf '%s\0' "${result[@]}" | ||
| } | ||
|
|
||
| # Transform and execute | ||
| mapfile -d '' transformed < <(adjust_args "$@") | ||
| exec "$REAL_DOCKER" "${transformed[@]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.