Repository navigation
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·172 lines (156 loc) · 5.25 KB
/
Copy pathdeploy
File metadata and controls
executable file
·172 lines (156 loc) · 5.25 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# This script populates the specified target directory with the deployed
# software and the output directory (named "s3_objects"). The default target
# directory is the parent the repository root.
#
# This script does not have any dependencies beyond posix and curl. It downloads
# micromamba, uses micromamba to create a standalone Python deployment
# containing the "uv" tool, and then uses "uv pip install" to install the
# dependency versions pinned in uv.lock followed by the software itself.
#
# This is the production installer. Development uses "uv sync --extra dev"
# instead (see README.md). To test a production-style deployment without
# touching the repository's parent, pass a scratch directory with -p.
#
# Suppose the filesystem looked like this:
# aws-object-search
# └── git
# ├── deploy
# └── ...
#
# After running "./git/deploy SUFFIX", the filesystem would look like this.
# aws-object-search
# ├── aws-object-search-SUFFIX
# ├── micromamba
# ├── git
# └── s3_objects
#
# The default SUFFIX is "dev", which makes an editable install with the dev
# extras. Any other SUFFIX makes a frozen install.
#
# Production invocation from source directory:
# VERSION=1.0.0 # select desired version
# REPO_DIR=...
# TARGET_DIR=... # the default is $REPO_DIR/..
# cd $REPO_DIR
# git checkout v$VERSION
# ./deploy -p $VERSION
#
# Resulting production tree:
# $TARGET_DIR
# ├── aws-object-search-$VERSION
# │ └── bin
# │ ├── aos-scan (used by cron to update s3_objects)
# │ ├── search-aws
# │ └── search.py
# ├── micromamba
# └── s3_objects (the index of S3)
set -euo pipefail
# set -x
PYTHON_VERSION=3.13
# Resolve the absolute path to the directory containing the script
REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Set default values
PREFIX="$( dirname "$REPO_DIR" )"
SUFFIX="dev"
main() {
parse_args "$@"
THIS_SCRIPT="${BASH_SOURCE[0]}"
if [[ -z "${__SANITIZED_ENV:+x}" ]]; then
# If not already in a sanitized environment, run the script in a sanitized environment
echo "Sanitizing environment"
exec "$REPO_DIR"/scripts/sanitize-command "$THIS_SCRIPT" "$@"
else
# If already in a sanitized environment, just run the script
echo "Running in a sanitized environment:"
echo "REPO_DIR: $REPO_DIR"
echo "PREFIX: $PREFIX"
echo "SUFFIX: $SUFFIX"
cd "$PREFIX"
export HOME="$PWD"
deploy
fi
}
parse_args() {
# Variable to track if SUFFIX has been set
local SUFFIX_SET=false
# Parse command line options
while [[ $# -gt 0 ]]; do
case $1 in
-p|--prefix)
PREFIX="$2"
shift 2
;;
-h|--help)
show_usage
exit 0
;;
-*)
echo "Unknown option $1" >&2
show_usage >&2
exit 1
;;
*)
# This is the positional parameter for SUFFIX
if [[ "$SUFFIX_SET" == true ]]; then
echo "Error: Too many arguments. Only one positional parameter (SUFFIX) is allowed." >&2
show_usage >&2
exit 1
fi
SUFFIX="$1"
SUFFIX_SET=true
shift
;;
esac
done
}
show_usage() {
echo "Usage: $0 [-p|--prefix PREFIX] [-h|--help] [SUFFIX]"
echo ""
echo "Options:"
echo " -p, --prefix PREFIX Set prefix value (default: '..')"
echo " -h, --help Show this help message"
echo ""
echo "Arguments:"
echo " SUFFIX Set suffix value (default: 'dev')"
echo ""
echo "Examples:"
echo " $0 # Use defaults"
echo " $0 -p /home/user # Set prefix only"
echo " $0 prod # Set suffix only"
echo " $0 --prefix /opt staging # Set both prefix and suffix"
}
deploy() {
echo "Running deploy() in $PWD with SUFFIX=$SUFFIX"
echo
echo "env:"
env
echo
TARGET_ENV="$PWD/aws-object-search-$SUFFIX"
echo TARGET_ENV=$TARGET_ENV
# Phase 1: Get micromamba.
bash "$REPO_DIR"/scripts/fetch-micromamba.sh
# Phase 2: Create deployment environment.
./micromamba create -y -p "$TARGET_ENV" python=$PYTHON_VERSION uv
# Phase 3: Populate deployment environment with application.
export PATH="$TARGET_ENV"/bin:$PATH
if [[ $SUFFIX == "dev" ]]; then
EDITABLE="-e"
EXTRAS="--extra dev"
else
EDITABLE=""
EXTRAS=""
fi
# Install the dependency versions pinned in uv.lock (the versions that
# were tested), then the package itself without re-resolving.
LOCKED_REQUIREMENTS="$TARGET_ENV/locked-requirements.txt"
uv export --project "$REPO_DIR" --frozen --no-emit-project $EXTRAS \
--output-file "$LOCKED_REQUIREMENTS"
echo uv pip install --system -r "$LOCKED_REQUIREMENTS"
uv pip install --system -r "$LOCKED_REQUIREMENTS"
echo uv pip install --system --no-deps $EDITABLE "$REPO_DIR"
uv pip install --system --no-deps $EDITABLE "$REPO_DIR"
# Phase 4: create output directory.
mkdir -p s3_objects
}
main "$@"