Skip to content

Commit c250a1a

Browse files
committed
Have it baby! now it scalegit status
1 parent c173cf7 commit c250a1a

File tree

17 files changed

+513
-274
lines changed

17 files changed

+513
-274
lines changed

.github/workflows/pyright.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v4
2424

25+
- name: Initialize submodules
26+
run: git submodule update --init --recursive
27+
2528
- name: "Build"
2629
run: |
2730
docker build -t bruttazz/apod-api:$TAG .

.github/workflows/smoketest.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Smoke Test
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
schedule:
7+
- cron: "0 0 * * 0"
8+
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
group: "smokeTest"
16+
cancel-in-progress: true
17+
18+
jobs:
19+
pyright:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Initialize submodules
26+
run: git submodule update --init --recursive
27+
28+
- name: Smoke Test
29+
run: make test

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
*.db
2-
__pycache__
3-
.venv
1+
var
2+
dev-docker-build
3+
build

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/deps/lua-htmlparser"]
2+
path = src/deps/lua-htmlparser
3+
url = https://github.com/msva/lua-htmlparser

.pre-commit-config.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
11
repos:
2-
- repo: https://github.com/PyCQA/isort
3-
rev: 6.0.1
4-
hooks:
5-
- id: isort
6-
args: ["--profile=black"]
7-
8-
- repo: https://github.com/psf/black
9-
rev: 24.3.0
10-
hooks:
11-
- id: black
12-
language_version: python3.13
13-
14-
- repo: https://github.com/RobertCraigie/pyright-python
15-
rev: v1.1.403
16-
hooks:
17-
- id: pyright
18-
192
- repo: https://github.com/pre-commit/pre-commit-hooks
203
rev: v5.0.0
214
hooks:

Dockerfile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
FROM python:3.13-alpine
1+
FROM openresty/openresty:1.21.4.1-0-alpine
22

3-
COPY requirements.txt .
4-
RUN pip3 install -r requirements.txt
3+
RUN apk add --no-cache perl curl
4+
RUN opm get ledgetech/lua-resty-http
55

6-
WORKDIR /opt/app
7-
COPY server.py server.py
6+
RUN apk del perl curl
87

9-
ENTRYPOINT ["python3", "-m", "uvicorn", "server:app", "--host", "0.0.0.0"]
10-
CMD ["--port", "8000", "--workers", "2"]
8+
RUN mkdir -p /var/app/www \
9+
&& chmod 777 -R /var/app/www \
10+
&& mkdir -p /var/logs/openresty \
11+
&& ln -sf /dev/stdout /var/logs/openresty/error.log \
12+
&& ln -sf /dev/stderr /var/logs/openresty/access.log
13+
14+
ENV WWW_DIR=/var/app/www
15+
16+
17+
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
18+
COPY src /opt/app/src
19+
20+
EXPOSE 8000

Dockerfile.dev

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM openresty/openresty:1.21.4.1-0-alpine
2+
3+
RUN apk add perl curl
4+
RUN opm get ledgetech/lua-resty-http
5+
6+
RUN mkdir -p /var/app/www
7+
ENV WWW_DIR=/var/app/www
8+
ENV LOCAL_ENV=true

Makefile

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1+
VERSION ?= v0.0.1
2+
13
PORT ?= 8000
2-
HOST ?= 0.0.0.0
3-
WORKERS ?= 4
44

5-
PYTHON ?= .venv/bin/python
5+
CONTAINER_CMD := docker
6+
DEV_CONTAINER_IMG := dev-docker-build
7+
PROD_CONTAINER_IMG := bruttazz/apod-api:$(VERSION)
8+
9+
610

711
help: ## Show all Makefile targets.
812
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
913

10-
.venv: requirements.txt
11-
- python3 -m venv .venv
12-
- $(PYTHON) -m pip install -r requirements.txt
14+
test: $(DEV_CONTAINER_IMG) ## Run unit tests
15+
@$(CONTAINER_CMD) run -it --rm -v ./src:/opt/app:ro -w /opt/app --entrypoint resty $(DEV_CONTAINER_IMG) tests.lua
16+
17+
shell: $(DEV_CONTAINER_IMG) ## Get resty shell
18+
@$(CONTAINER_CMD) run -it --rm -v ./src:/opt/app:ro -v ./var:/var/app/www -w /opt/app --entrypoint sh $(DEV_CONTAINER_IMG)
19+
20+
build: ## Build prod
21+
$(CONTAINER_CMD) rmi $(PROD_CONTAINER_IMG) || true
22+
$(CONTAINER_CMD) build -f Dockerfile -t $(PROD_CONTAINER_IMG) .
23+
touch build
24+
25+
run: build ## Run production docker build
26+
- $(CONTAINER_CMD) run -it --rm -p $(PORT):8000 -e SERVICE_BASE_URL=http://localhost:8000 $(PROD_CONTAINER_IMG)
27+
28+
run-b: ## Build and run
29+
$(RM) build
30+
$(MAKE) run
31+
32+
$(DEV_CONTAINER_IMG):
33+
$(CONTAINER_CMD) build -f Dockerfile.dev . -t $(DEV_CONTAINER_IMG)
34+
@touch $(DEV_CONTAINER_IMG)
1335

14-
run: .venv ## Run server
15-
@$(PYTHON) -m uvicorn server:app --host $(HOST) --port $(PORT) --workers $(WORKERS) $(FLAGS)
36+
clean-builds:
37+
$(CONTAINER_CMD) rmi $(DEV_CONTAINER_IMG) || true
38+
$(CONTAINER_CMD) rmi $(PROD_CONTAINER_IMG) || true
1639

17-
dev: .venv ## Run dev server
18-
@$(MAKE) run WORKERS=1 FLAGS='--reload'
40+
clean: ## Clean all build deps
41+
$(RM) build
42+
$(RM) $(DEV_CONTAINER_IMG)
43+
$(MAKE) clean-builds

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1+
# APOD cache server & API
2+
![smoketest-status](https://github.com/bruttazz/apod-api/actions/workflows/smoketest.yml/badge.svg)
3+
4+
15
**A dead simple API that scrap, cache and serve APOD (Astronomy Picture of the Day) info from [nasa](https://apod.nasa.gov/apod/) / [star.ucl](http://www.star.ucl.ac.uk/~apod/apod/)!**
26

3-
Inspired from: [@apod@reentry.codl.fr](https://reentry.codl.fr/@apod)
7+
**Inspired from** the activitypub bot, [@apod@reentry.codl.fr](https://reentry.codl.fr/@apod)
8+
9+
### API Endpoints
410

5-
Usage:
11+
- GET `/api/v1/apod.json`
12+
13+
### Usage
614
```sh
7-
curl http://127.0.0.1:8000/api/v1/apod/ | jq
15+
curl http://localhost:8000/api/v1/apod.json -s | jq
816
{
9-
"img": "<http url>",
10-
"description": "",
11-
"title": "",
12-
"date": "YYYY-MM-DD",
17+
"credits": "www.star.ucl.ac.uk",
18+
"img": "http://localhost:8000/api/v1/apod-img.jpg",
19+
"description": "Put on your red/blue glasses and float next to asteroid 101955 Bennu. Shaped like a spinning toy top with boulders littering its rough surface, the tiny Solar System world is about one Empire State Building (less than 500 metres) across. Frames used to construct this 3D anaglyph were taken by PolyCam on the OSIRIS_REx spacecraft on December 3, 2018 from a distance of about 80 kilometres. With a sample from the asteroid's rocky surface on board, OSIRIS_REx departed Bennu's vicinity in May of 2021. The robotic spacecraft successfully returned the sample to its home world in September of 2023.",
20+
"title": "3D Bennu",
21+
"source": "http://www.star.ucl.ac.uk/~apod/apod/",
22+
"date": "2025-10-19"
1323
}
1424
```
1525

26+
### Env Vars:
27+
- `APOD_PAGE_URL` (defaults to `http://www.star.ucl.ac.uk/~apod/apod/`, compatable with `https://apod.nasa.gov/apod/` (but the site is dead today))
28+
- `SERVICE_BASE_URL` (defaults to empty string, eg: `http://localhost:8000` )
29+
- `APOD_PAGE_MAX_SIZE` (defaults to 50kb) -- to save your server
30+
- `APOD_IMG_MAX_SIZE` (defaults to 10Mb) -- to save your server
1631

17-
Env Vars:
18-
- `APOD_SITE_URL` (defaults: `http://www.star.ucl.ac.uk/~apod/apod/`, compatable with `https://apod.nasa.gov/apod/` (but the site is dead today))
19-
20-
dockers:
21-
- bruttazz/apod-api
32+
### Pre-built docker images:
33+
- `bruttazz/apod-api`
2234

23-
live-apis:
24-
- apod.brutt.site/api/v1/apod
35+
### Live Endpoints
36+
- (https://apod.brutt.site/api/v1/apod.json)[https://apod.brutt.site/api/v1/apod.json]
2537

38+
### Credits
2639
All rights reserved to respective sites: [star.ucl](http://www.star.ucl.ac.uk/~apod/apod/) / [nasa](https://apod.nasa.gov/apod/)

0 commit comments

Comments
 (0)