-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_3podR.sh
More file actions
102 lines (91 loc) · 3.58 KB
/
run_3podR.sh
File metadata and controls
102 lines (91 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# --- 1. CHECK FOR DOCKER INSTALLATION ---
if ! [ -x "$(command -v docker)" ]; then
echo "🚀 Docker not found. Detecting OS for installation..."
OS_TYPE="$(uname -s)"
if [[ "$OS_TYPE" == "Darwin" ]]; then
echo "🍎 Mac detected. Checking for Homebrew..."
if ! [ -x "$(command -v brew)" ]; then
echo "🍺 Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" <<EOF
EOF
if [[ -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -f /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
fi
echo "📦 Installing Docker Desktop via Homebrew..."
brew install --cask docker
open /Applications/Docker.app
elif [[ "$OS_TYPE" == *"NT"* || "$OS_TYPE" == *"MINGW"* || "$OS_TYPE" == *"MSYS" ]]; then
echo "🪟 Windows detected. Using winget..."
if command -v winget.exe >/dev/null 2>&1; then
echo "📦 Installing Docker Desktop via winget..."
winget.exe install --id Docker.DockerDesktop --silent --accept-source-agreements --accept-package-agreements
echo "🚀 Starting Docker Desktop..."
"/c/Program Files/Docker/Docker Desktop.exe" &
else
echo "❌ winget not found. Please install Docker manually: https://www.docker.com"
exit 1
fi
else
echo "❌ Unsupported OS."
exit 1
fi
fi
# --- 2. WAIT FOR DOCKER ENGINE ---
echo "🐋 Waiting for Docker engine to start..."
MAX_RETRIES=60
COUNT=0
until docker info >/dev/null 2>&1; do
echo " ...still waiting (attempt $COUNT/60)..."
sleep 10
((COUNT++))
if [ $COUNT -ge $MAX_RETRIES ]; then
echo "⏱️ Timeout: Docker engine didn't start. If this is a fresh install, a RESTART may be required."
exit 1
fi
done
echo "✅ Docker engine is ready!"
# --- 3. PREPARE LOCAL ENVIRONMENT ---
mkdir -p results
echo "📂 Host working directory: $(pwd)"
echo "📂 Host results folder contents before running container:"
ls -l results
# --- 4. PULL AND RUN ---
echo "📥 Pulling latest container..."
docker pull cdrl/3podr_container:latest
echo "📊 Running 3PodR Report..."
# --- 4a. Mount host files into container ---
docker run --rm \
-v "$(pwd)/results":/project/results \
-v "$(pwd)/extdata":/project/extdata \
-v "$(pwd)/configuration.yml":/project/configuration.yml \
-w /project \
-e R_LIBS_USER=/opt/renv/library \
-e R_PROFILE_USER=/dev/null \
cdrl/3podr_container:latest \
R -e '
cat("📂 Inside container: current working directory:\n")
print(getwd())
cat("📄 Inside container: files in current directory before render:\n")
print(list.files())
dir.create("results", showWarnings = FALSE)
cat("📄 Inside container: files in results/ after creation:\n")
print(list.files("results"))
bookdown::render_book(input = ".", output_dir = "results")
cat("📄 Inside container: files in results/ after render_book:\n")
print(list.files("results"))
saveRDS(global_state, file = "results/global_state.rds")
'
# --- 5. VERIFY ---
echo "📂 Host results folder contents after running container:"
ls -l results
if [ -n "$(ls -A results)" ]; then
echo "✅ Done! Analysis successful. Files are in the 'results' folder."
else
echo "❌ Error: Analysis finished but no files were found in 'results'."
echo "Make sure your R Markdown outputs are correctly configured."
exit 1
fi