Skip to content

Commit 97747b1

Browse files
EmmaTintingerric-evansgithub-actions
authored
Merge main updates to monopod_wilks (#319)
Update monopod_wilks branch to include updates to main --------- Co-authored-by: Ric Evans <19216225+ric-evans@users.noreply.github.com> Co-authored-by: ric-evans <emejqz@gmail.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent 599d570 commit 97747b1

9 files changed

Lines changed: 540 additions & 412 deletions

File tree

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
image-publish:
17-
uses: WIPACrepo/wipac-dev-workflows/.github/workflows/image-publish.yml@v1.13
17+
uses: WIPACrepo/wipac-dev-workflows/.github/workflows/image-publish.yml@v1.20
1818
permissions: # for GITHUB_TOKEN
1919
packages: write
2020
with:

.github/workflows/tests.yml

Lines changed: 258 additions & 327 deletions
Large diffs are not rendered by default.

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ ARG ICETRAY_VERSION=v1.15.3-ubuntu22.04
77
FROM icecube/icetray:icetray-devel-v1.15.3_pr4012-ubuntu22.04 AS prod
88

99
# gcd files
10-
RUN mkdir -p /opt/i3-data/baseline_gcds && \
11-
wget -nv -N -t 5 -P /opt/i3-data/baseline_gcds -r -l 1 -A *.i3* -nd http://prod-exe.icecube.wisc.edu/baseline_gcds/ && \
10+
# -- toggle GCD download at build time (1=download, 0=skip)
11+
ARG INCLUDE_GCD=1
12+
RUN set -eux; \
13+
mkdir -p /opt/i3-data/baseline_gcds; \
14+
if [ "${INCLUDE_GCD}" = "1" ]; then \
15+
wget -nv -N -t 5 -P /opt/i3-data/baseline_gcds -r -l 1 -A '*.i3*' -nd http://prod-exe.icecube.wisc.edu/baseline_gcds/; \
16+
else \
17+
echo "Skipping baseline_gcds download (INCLUDE_GCD=${INCLUDE_GCD})"; \
18+
fi; \
1219
chmod -R u+rwX,go+rX,go-w /opt/i3-data/baseline_gcds
1320

1421
#

pyproject.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ mypy = [
5151
'oms-mqclient[rabbitmq]',
5252
] # do not edit — autogenerated by wipac-dev-py-setup-action
5353

54+
[tool.setuptools]
55+
packages = [
56+
'skymap_scanner',
57+
'skymap_scanner.client',
58+
'skymap_scanner.recos',
59+
'skymap_scanner.recos.common',
60+
'skymap_scanner.server',
61+
'skymap_scanner.utils',
62+
] # do not edit — autogenerated by wipac-dev-py-setup-action
63+
5464
[tool.setuptools.package-data]
5565
"*" = ["py.typed"] # do not edit — autogenerated by wipac-dev-py-setup-action
5666

57-
[tool.setuptools.packages.find] # do not edit — autogenerated by wipac-dev-py-setup-action
58-
namespaces = false
59-
exclude = ["test", "tests", "doc", "docs", "resource", "resources", "example", "examples"]
60-
6167
[tool.setuptools_scm] # do not edit — autogenerated by wipac-dev-py-setup-action
62-
fallback_version = "UNTAGGED" # only used when SCM metadata is completely unavailable (e.g., no '.git/'). NOTE: in shallow clones without git tags, setuptools-scm will still infer a commit-based version (like '0.1.dev1+g79c9b4b'); this value will NOT be used in that case.
68+
fallback_version = "CANNOT_BUILD_WITHOUT_GIT_DIR" # used when SCM metadata is missing (no '.git/') — if '.git/' exists but does not contain tags, a commit-based version (like '0.1.dev1+g79c9b4b') will be used instead.

resources/build_apptainer_image.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
echo "now: $(date -u +"%Y-%m-%dT%H:%M:%S.%3N")"
4+
5+
########################################################################
6+
# Require environment variables
7+
########################################################################
8+
if [[ -z "${_SCANNER_IMAGE_DOCKER:-}" ]]; then
9+
echo "::error:: _SCANNER_IMAGE_DOCKER must be set"
10+
exit 1
11+
fi
12+
if [[ -z "${APPTAINER_CACHEDIR:-}" ]]; then
13+
echo "::error:: APPTAINER_CACHEDIR must be set"
14+
exit 1
15+
fi
16+
17+
APPTAINER_SANDBOX_DIR="skymap_scanner.sandbox"
18+
19+
########################################################################
20+
# Build sandbox image
21+
########################################################################
22+
echo "building apptainer sandbox at: ${APPTAINER_SANDBOX_DIR}"
23+
# ensure a clean target (apptainer refuses to overwrite without --force)
24+
rm -rf "${APPTAINER_SANDBOX_DIR}" || true
25+
apptainer build --sandbox --force "${APPTAINER_SANDBOX_DIR}" docker-daemon://"$_SCANNER_IMAGE_DOCKER"
26+
du -sh "${APPTAINER_SANDBOX_DIR}" || ls -lh "${APPTAINER_SANDBOX_DIR}"
27+
28+
########################################################################
29+
# Drop apptainer caches
30+
########################################################################
31+
echo "clearing apptainer caches..."
32+
du -sh "$APPTAINER_CACHEDIR" || true
33+
rm -rf "$APPTAINER_CACHEDIR" || true
34+
35+
########################################################################
36+
# Free docker stuff now that sandbox is built
37+
########################################################################
38+
echo "clearing docker things..."
39+
BEFORE="$(df -B1 --output=avail / | tail -1)"
40+
41+
# -- docker layers
42+
docker ps -a --filter "ancestor=$_SCANNER_IMAGE_DOCKER" -q | xargs -r docker rm -f
43+
docker rmi -f "$_SCANNER_IMAGE_DOCKER" || true
44+
45+
# -- prune buildkit + volume
46+
docker ps -aq --filter "label=name=buildx_buildkit" | xargs -r docker rm -f || true
47+
docker ps -aq --filter "ancestor=moby/buildkit:buildx-stable-1" | xargs -r docker rm -f || true
48+
docker buildx ls | awk 'NR>1{gsub(/\*$/,"",$1); if($1!="default" && $1!="") print $1}' | xargs -r -n1 docker buildx rm -f || true
49+
docker builder prune -af || true
50+
docker system prune -af --volumes || true
51+
docker volume ls -q --filter 'name=buildx_buildkit_.*_state' | xargs -r docker volume rm -f || true
52+
53+
# -- report
54+
AFTER="$(df -B1 --output=avail / | tail -1)"
55+
DELTA="$((AFTER - BEFORE))"
56+
GIB="$(awk -v b="$DELTA" 'BEGIN{printf "%.2f", b/1024/1024/1024}')"
57+
MIB="$(awk -v b="$DELTA" 'BEGIN{printf "%.0f", b/1024/1024}')"
58+
echo "Freed: ${GIB} GiB (${MIB} MiB)"
Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
#!/bin/bash
22
set -euo pipefail
3-
set -ex
43

54
########################################################################
65
#
76
# Launch a Skymap Scanner worker
7+
# Uses '_CI_SCANNER_CONTAINER_PLATFORM' to control the mode:
88
#
9-
# Run worker on ewms pilot
9+
# - Docker mode:
10+
# runs the pilot image (docker) that runs Docker scanner clients
11+
# - Apptainer mode:
12+
# runs the pilot image (docker) that runs Apptainer scanner clients
1013
#
1114
########################################################################
1215

16+
########################################################################
17+
# Common (platform-agnostic) setup
18+
########################################################################
19+
1320
# establish pilot's root path
1421
tmp_rootdir="$(pwd)/pilot-$(uuidgen)"
15-
mkdir $tmp_rootdir
16-
cd $tmp_rootdir
22+
mkdir "$tmp_rootdir"
23+
cd "$tmp_rootdir"
1724
export EWMS_PILOT_DATA_DIR_PARENT_PATH_ON_HOST="$tmp_rootdir"
1825

1926
# mark startup.json's dir to be bind-mounted into the task container (by the pilot)
2027
# -> check that the dir only has one file, otherwise we may end up binding extra dirs
2128
python -c 'import os; assert os.listdir(os.path.dirname(os.environ["CI_SKYSCAN_STARTUP_JSON"])) == ["startup.json"]'
2229
export EWMS_PILOT_EXTERNAL_DIRECTORIES="$(dirname "$CI_SKYSCAN_STARTUP_JSON")"
2330

24-
# task image, args, env
25-
if [ -n "${_RUN_THIS_SIF_IMAGE:-}" ]; then
26-
# place a duplicate of the file b/c the pilot transforms this into another format, so there are issues w/ parallelizing
27-
export EWMS_PILOT_TASK_IMAGE="$tmp_rootdir/$(basename "$_RUN_THIS_SIF_IMAGE")"
28-
cp "$_RUN_THIS_SIF_IMAGE" "$EWMS_PILOT_TASK_IMAGE"
29-
export _EWMS_PILOT_CONTAINER_PLATFORM="apptainer"
30-
else
31-
export EWMS_PILOT_TASK_IMAGE="$CI_DOCKER_IMAGE_TAG"
32-
export _EWMS_PILOT_CONTAINER_PLATFORM="docker" # NOTE: technically not needed b/c this is the default value
33-
export _EWMS_PILOT_DOCKER_SHM_SIZE="6gb" # this only needed in ci--the infra would set this in prod
34-
fi
31+
# args
3532
export EWMS_PILOT_TASK_ARGS="python -m skymap_scanner.client --infile {{INFILE}} --outfile {{OUTFILE}} --client-startup-json $CI_SKYSCAN_STARTUP_JSON"
36-
json_var=$(env | grep -E '^(SKYSCAN_|_SKYSCAN_)' | awk -F= '{printf "\"%s\":\"%s\",", $1, $2}' | sed 's/,$//') # must remove last comma
33+
34+
# marshal SKYSCAN/_SKYSCAN_ env into JSON
35+
json_var=$(env | grep -E '^(SKYSCAN_|_SKYSCAN_)' | awk -F= '{printf "\"%s\":\"%s\",", $1, $2}' | sed 's/,$//')
3736
json_var="{$json_var}"
3837
export EWMS_PILOT_TASK_ENV_JSON="$json_var"
3938

40-
# file types -- controls intermittent serialization
39+
# file types
4140
export EWMS_PILOT_INFILE_EXT="JSON"
4241
export EWMS_PILOT_OUTFILE_EXT="JSON"
4342

44-
# Load JSON values
43+
# queues/broker config
4544
export EWMS_PILOT_QUEUE_INCOMING=$(jq -r '.toclient.name' "$_EWMS_JSON_ON_HOST")
4645
export EWMS_PILOT_QUEUE_INCOMING_AUTH_TOKEN=$(jq -r '.toclient.auth_token' "$_EWMS_JSON_ON_HOST")
4746
export EWMS_PILOT_QUEUE_INCOMING_BROKER_TYPE=$(jq -r '.toclient.broker_type' "$_EWMS_JSON_ON_HOST")
@@ -53,11 +52,62 @@ export EWMS_PILOT_QUEUE_OUTGOING_BROKER_TYPE=$(jq -r '.fromclient.broker_type' "
5352
export EWMS_PILOT_QUEUE_OUTGOING_BROKER_ADDRESS=$(jq -r '.fromclient.broker_address' "$_EWMS_JSON_ON_HOST")
5453

5554

56-
# run!
57-
ENV="$(dirname $tmp_rootdir)/pyenv-$(basename $tmp_rootdir)"
58-
pip install virtualenv
59-
virtualenv --python python3 "$ENV"
60-
. "$ENV"/bin/activate
61-
pip install --upgrade pip
62-
pip install ewms-pilot[rabbitmq]
63-
python -m ewms_pilot
55+
########################################################################
56+
# Run!
57+
########################################################################
58+
59+
# ─────────────── Case: Docker ───────────────
60+
if [[ "${_CI_SCANNER_CONTAINER_PLATFORM}" == "docker" ]]; then
61+
62+
# docker-specific pilot env vars
63+
export EWMS_PILOT_TASK_IMAGE="$_SCANNER_IMAGE_DOCKER"
64+
export _EWMS_PILOT_DOCKER_SHM_SIZE="6gb" # CI-specific; prod infra should set this
65+
66+
# Required env for the helper
67+
export DOOD_OUTER_IMAGE="$_PILOT_IMAGE_FOR_DOCKER_SCANNER_CLIENT"
68+
# Network for the outer container
69+
if [[ -z "${DOOD_NETWORK:-}" ]]; then
70+
echo "::error::DOOD_NETWORK must be set — this should've been set in '.github/workflows/tests.yml'. Did it not get forwarded to this script?"
71+
exit 1
72+
fi
73+
# Bind dirs: the pilot needs these paths visible at the same locations
74+
# - tmp_rootdir (RW)
75+
# - startup.json's parent (RO)
76+
export DOOD_BIND_RW_DIRS="$tmp_rootdir"
77+
export DOOD_BIND_RO_DIRS="$(dirname "$CI_SKYSCAN_STARTUP_JSON")"
78+
# Forward envs by prefix and explicit list
79+
export DOOD_FORWARD_ENV_PREFIXES="EWMS_ _EWMS_ SKYSCAN_ _SKYSCAN_"
80+
export DOOD_FORWARD_ENV_VARS="CI_SKYSCAN_STARTUP_JSON"
81+
82+
# run (curl script first)
83+
tmp_for_dood_sh=$(mktemp -d)
84+
curl -fsSL "$CI_SCRIPT_URL_DOOD_RUN" -o "$tmp_for_dood_sh/run-dood.sh"
85+
chmod +x "$tmp_for_dood_sh/run-dood.sh"
86+
"$tmp_for_dood_sh/run-dood.sh"
87+
88+
# ─────────────── Case: Apptainer ───────────────
89+
elif [[ "${_CI_SCANNER_CONTAINER_PLATFORM}" == "apptainer" ]]; then
90+
91+
# apptainer-specific pilot env vars
92+
export EWMS_PILOT_TASK_IMAGE="$_SCANNER_IMAGE_APPTAINER"
93+
export _EWMS_PILOT_APPTAINER_IMAGE_DIRECTORY_MUST_BE_PRESENT=True
94+
95+
# run
96+
docker run --rm \
97+
--privileged \
98+
--network=host \
99+
\
100+
-v "$tmp_rootdir:$tmp_rootdir" \
101+
-v "$(dirname "$CI_SKYSCAN_STARTUP_JSON"):$(dirname "$CI_SKYSCAN_STARTUP_JSON")":ro \
102+
-v "$_SCANNER_IMAGE_APPTAINER:$_SCANNER_IMAGE_APPTAINER":ro \
103+
\
104+
--env CI_SKYSCAN_STARTUP_JSON="$CI_SKYSCAN_STARTUP_JSON" \
105+
$(env | grep -E '^(EWMS_|_EWMS_)' | cut -d'=' -f1 | sed 's/^/--env /') \
106+
\
107+
"$_PILOT_IMAGE_FOR_APPTAINER_SCANNER_CLIENT"
108+
109+
# ─────────────── Case: Unknown??? ───────────────
110+
else
111+
echo "::error::cannot launch worker — unknown '_CI_SCANNER_CONTAINER_PLATFORM=$_CI_SCANNER_CONTAINER_PLATFORM'"
112+
exit 2
113+
fi

0 commit comments

Comments
 (0)