Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.git
.github
.devcontainer
.terraform
.terraform.lock.hcl
*.tfstate
*.tfstate.*
*.tfvars
__pycache__
*.py[cod]
.pytest_cache
.tox
.coverage
htmlcov
build
dist
*.egg-info
.env
6 changes: 6 additions & 0 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export TF_VAR_CAT_ARCHITECTURE="x86_64"
export TF_VAR_ECS_TASK_CPU=512
export TF_VAR_ECS_TASK_MEMORY=1024
export TF_VAR_ECS_DESIRED_COUNT=1
export TF_VAR_ECS_HEALTHCHECK_GRACE_PERIOD_SECONDS=1800
export TF_VAR_ECS_LOGS_RETENTION_DAYS=14
export TF_VAR_CONTAINER_PORT=8000
export TF_VAR_HEALTHCHECK_PATH="/hello"
Expand All @@ -57,7 +58,12 @@ export TF_VAR_CAT_DEPLOYMENT="prod"
export TF_VAR_ECR_REPOSITORY_NAME="app"
export TF_VAR_ECR_IMAGE_SCAN_ON_PUSH=true
export TF_VAR_ECR_KEEP_IMAGE_COUNT=20
export TF_VAR_EFS_PERFORMANCE_MODE="generalPurpose"
export TF_VAR_EFS_THROUGHPUT_MODE="bursting"

# Keep this in sync with DOCKER_IMAGE_TAG.

export TF_VAR_DOCKER_IMAGE_TAG="${DOCKER_IMAGE_TAG}"

# Must be globally unique across all AWS accounts.
export TF_VAR_S3_BUCKET_NAME="sbn-cat-lite-data"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# dwd-dev stuff
AGENTS.md
.devcontainer

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -167,6 +171,7 @@ cython_debug/
*.tfstate.backup
.terraform.lock.hcl
*.tfvars
terraform.tfstate.*


# IDE files
Expand Down
46 changes: 21 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM python:3.12-slim

# Set working directory
WORKDIR /app

### Install system dependencies
RUN apt-get update && apt-get install -y \
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
astrometry.net \
source-extractor \
netcat-openbsd \
git \
wget \
Expand All @@ -13,33 +15,27 @@ RUN apt-get update && apt-get install -y \
libbz2-dev \
&& rm -rf /var/lib/apt/lists/*

RUN pip install -U pip setuptools wheel "connexion[flask,swagger-ui,uvicorn]"
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -U pip setuptools wheel

COPY requirements.local.txt /app/

COPY . /app
RUN pip install /app
COPY requirements.local.txt .
RUN pip install -r requirements.local.txt
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.local.txt

COPY pyproject.toml setup.py MANIFEST.in README.md /app/
COPY catch_analysis_tools /app/catch_analysis_tools
COPY scripts /app/scripts
COPY docker /app/docker

# Checkout code
# RUN --mount=type=bind,source=./,target=/app/src/
# COPY \
# requirements.local.txt \
# setup.py \
# pyproject.toml \
# .
# COPY catch_analysis_tools /app/catch_analysis_tools
ARG PACKAGE_VERSION=0.0.0
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CATCH_ANALYSIS_TOOLS=${PACKAGE_VERSION}

# # ARG CAT_DEPLOYMENT
# # RUN if [ "$CAT_DEPLOYMENT" = "prod" ]; then \
# # git clone git+https://github.com
# # pip install -r src/requirements.prod.txt; \
# # else \
# # fi
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-deps /app

# # Install dependencies
# #RUN pip install -r requirements.local.txt;
RUN chmod +x /app/docker/entrypoint.sh

EXPOSE 8000

CMD ["python3", "-m", "catch_analysis_tools.app.app"]
ENTRYPOINT ["/app/docker/entrypoint.sh"]
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Running locally will install the currently checked out version of the CAT.
### DWD's changes:

- Added terraform configuration. For now, we are depending on my local machine for state-files.
- Moved docker stuff to just two files in the root dir: Dockerfile and docker-compose.yml. We'll worry about different deployments later
- Moved docker stuff to just two files in the root dir: Dockerfile and docker-compose.yml. We'll worry about different deployments later.
- To run the app locally, use `docker-compose up`
- To deploy to AWS:
- Don't do this for now -- rely on DWD to do it -- this is just FYI
Expand All @@ -63,9 +63,10 @@ Running locally will install the currently checked out version of the CAT.
- Update tf state with `./_tf apply`
- I also made some changes adding a /hello route, and wiring up the flask code to get it to work
- Added a simple script to ping the endpoint created by tf, `./_ping_endpoint`
- To make sure that the /astrometry endpoint does not run before the Astrometry.net index files are downloaded, I added a bunch of logic in `catch_analysis_tools/app/astrometry_readiness`. See README therein for details. It also involves a new route `/health` that lets you know if the files are downloaded.


## Astrometry Configuration
## Astrometry Configuration

The astrometric calibration pipeline depends on **astrometry.net** index files and a corresponding configuration file. These are required for WCS solving.

Expand Down
95 changes: 95 additions & 0 deletions _ping_astrometry
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
#
# Resolve service URL from OpenTofu outputs and test POST /astrometry.
# Use --local to ping the locally running docker-compose app.

set -euo pipefail
IFS=$'\n\t'

local_mode=false

print_help() {
cat <<'EOF'
Usage: ./_ping_astrometry [--local]

Options:
--local Ping http://127.0.0.1:8000 instead of the deployed service.
-h, --help Show this help.
EOF
}

while [[ $# -gt 0 ]]; do
case "$1" in
--local)
local_mode=true
shift
;;
-h|--help)
print_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
print_help >&2
exit 1
;;
esac
done

if ! command -v curl >/dev/null 2>&1; then
echo "curl command not found. Install curl and try again." >&2
exit 1
fi

if [[ "${local_mode}" == true ]]; then
service_base_url="${LOCAL_SERVICE_BASE_URL:-http://127.0.0.1:8000}"
else
if [[ ! -f ".env" ]]; then
echo "Missing .env file. Copy .env-template and configure required values." >&2
exit 1
fi

if ! command -v tofu >/dev/null 2>&1; then
echo "OpenTofu (tofu) is not installed or not in PATH." >&2
exit 1
fi

# shellcheck disable=SC1091
source .env

service_base_url="$(tofu output -raw service_base_url)"
if [[ -z "${service_base_url}" ]]; then
echo "Failed to resolve service_base_url from tofu output." >&2
exit 1
fi
fi

endpoint="${service_base_url%/}/astrometry"
echo "Pinging: ${endpoint}"

# /wcs POST

payload='{
"image_url": "https://uxzqjwo0ye.execute-api.us-west-1.amazonaws.com/api/images/urn:nasa:pds:gbo.ast.loneos.survey:data_augmented:060104_1a_099_fits?ra=51.11064&dec=17.38378&size=12.60arcmin&format=fits",
"ra": 51.11064,
"dec": 17.38378,
"use_ra_dec": true,
"pixel_scale": 2.5,
"snr_threshold": 3.0,
"aperture_radius": 7.0,
"catalog": "PanSTARRS1",
"obs_band": "g",
"cal_band": "r",
"return_plot": false
}'

printf 'Executing:\n'
printf 'curl -i -X POST %q -H %q --max-time 900 --data %q\n' \
"${endpoint}" \
"Content-Type: application/json" \
"${payload}"

curl -i -X POST "${endpoint}" \
-H "Content-Type: application/json" \
--max-time 900 \
--data "${payload}"
34 changes: 0 additions & 34 deletions _ping_endpooint

This file was deleted.

73 changes: 73 additions & 0 deletions _ping_health
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash
#
# Resolve service URL from OpenTofu outputs and ping /health.
# Use --local to ping the locally running docker-compose app.

set -euo pipefail
IFS=$'\n\t'

local_mode=false

print_help() {
cat <<'EOF'
Usage: ./_ping_health [--local]

Options:
--local Ping http://127.0.0.1:8000 instead of the deployed service.
-h, --help Show this help.
EOF
}

while [[ $# -gt 0 ]]; do
case "$1" in
--local)
local_mode=true
shift
;;
-h|--help)
print_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
print_help >&2
exit 1
;;
esac
done

if ! command -v curl >/dev/null 2>&1; then
echo "curl command not found. Install curl and try again." >&2
exit 1
fi

if [[ "${local_mode}" == true ]]; then
service_base_url="${LOCAL_SERVICE_BASE_URL:-http://127.0.0.1:8000}"
else
if [[ ! -f ".env" ]]; then
echo "Missing .env file. Copy .env-template and configure required values." >&2
exit 1
fi

if ! command -v tofu >/dev/null 2>&1; then
echo "OpenTofu (tofu) is not installed or not in PATH." >&2
exit 1
fi

# shellcheck disable=SC1091
source .env

service_base_url="$(tofu output -raw service_base_url)"
if [[ -z "${service_base_url}" ]]; then
echo "Failed to resolve service_base_url from tofu output." >&2
exit 1
fi
fi

endpoint="${service_base_url%/}/health"
echo "Pinging: ${endpoint}"

printf 'Executing:\n'
printf 'curl -i %q\n' "${endpoint}"

curl -i "${endpoint}"
Loading
Loading