Skip to content

Commit f3258f5

Browse files
committed
Merge branch 'dev'
2 parents afbf9ce + 6d397cb commit f3258f5

950 files changed

Lines changed: 608 additions & 119 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/convert_images.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
else
3232
IMAGEMAGICK_CMD="convert"
3333
fi
34-
3534
while IFS= read -r -d '' png_file; do
3635
relative_path="${png_file#images/}"
3736
relative_base="${relative_path%.png}"
@@ -40,7 +39,15 @@ jobs:
4039
mkdir -p "$(dirname "${webp_file}")"
4140
4241
if [ "${{ github.event_name }}" = "workflow_dispatch" ] || [ ! -f "${webp_file}" ]; then
43-
"${IMAGEMAGICK_CMD}" "${png_file}" "${webp_file}"
42+
"${IMAGEMAGICK_CMD}" "${png_file}" \
43+
-strip \
44+
-quality 90 \
45+
-define webp:lossless=false \
46+
-define webp:method=6 \
47+
-define webp:auto-filter=true \
48+
-define webp:alpha-quality=100 \
49+
-define webp:use-sharp-yuv=true \
50+
"${webp_file}"
4451
echo "${webp_file}" >> /tmp/converted_webp_files.txt
4552
fi
4653
done < <(find images -type f -name '*.png' -print0)
@@ -63,6 +70,6 @@ jobs:
6370
6471
git config --local user.name 'AmiiboAPI (Automated)'
6572
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
66-
if git commit -m "[Automated] Add missing WebP images"; then
73+
if git commit -m "[Automated] Convert PNG to WebP images"; then
6774
git push
6875
fi

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ WORKDIR /usr/src/app
1111

1212
COPY --from=0 /amiiboapi .
1313
RUN [ "find", "." ]
14+
RUN apt-get update \
15+
&& apt-get install -y --no-install-recommends certbot cron curl ca-certificates \
16+
&& rm -rf /var/lib/apt/lists/*
1417
RUN pip install --no-cache-dir -r requirements.txt
18+
RUN chmod +x /usr/src/app/deploy/certbot/bootstrap.sh /usr/src/app/deploy/certbot/renew.sh /usr/src/app/deploy/start.sh
1519

16-
CMD [ "python", "./app.py" ]
20+
CMD [ "/usr/src/app/deploy/start.sh" ]

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ More APIs examples can be found here: [https://www.amiiboapi.org/docs/](https://
4444
Click on the `Deploy to Heroku` button and you are good to go!
4545
*Heroku is a paid service and requires an account to use*
4646

47+
### SSL / Certbot auto-renewal
48+
Certbot is included for container/self-hosted deployments with automatic renewal.
49+
50+
- Default certificate domain: `amiiboapi.org`
51+
- Default webroot for ACME challenges: `/var/www/certbot`
52+
- Renewal schedule: twice daily at `03:00` and `15:00` server time via cron
53+
54+
#### Environment variables
55+
- `ENABLE_CERTBOT_AUTO_SSL` (default: `1`) enable/disable Certbot bootstrap and renewal setup on container startup
56+
- `CERTBOT_DOMAIN` (default: `amiiboapi.org`) domain to issue/renew certificates for
57+
- `CERTBOT_EMAIL` (default: `ssl-admin@amiiboapi.org`) email used for Let's Encrypt registration
58+
- `CERTBOT_WEBROOT` (default: `/var/www/certbot`) ACME challenge webroot
59+
- `CERTBOT_STAGING` (default: `0`) set to `1` to use Let's Encrypt staging
60+
- `CERTBOT_FORCE_BOOTSTRAP` (default: `0`) set to `1` to force re-running initial certificate issuance
61+
- `CERTBOT_RELOAD_COMMAND` optional command run after successful renewals (for reverse proxies/web servers)
62+
63+
#### Hosting-location behavior
64+
- **AWS EC2 / container hosts**: startup scripts detect AWS environments and request certificates with Certbot automatically.
65+
- **Heroku**: startup scripts detect Heroku and skip Certbot because SSL is managed by Heroku ACM.
66+
67+
At startup, the bootstrap script checks for an existing certificate at `/etc/letsencrypt/live/<domain>/fullchain.pem`.
68+
If it is missing, initial Certbot setup runs automatically; otherwise it skips issuance and keeps renewal-only behavior.
69+
70+
#### Manual commands
71+
- Initial setup: `sh deploy/certbot/bootstrap.sh`
72+
- Renewal run: `sh deploy/certbot/renew.sh`
73+
74+
> Renewal scheduling writes to `/etc/cron.d/certbot-renew` and uses root because Certbot certificate files are stored under `/etc/letsencrypt`; renewal output is sent to syslog with the `certbot-renew` tag.
75+
4776
### Credit
4877
- [Brickleberry19 - Amiibo IDs](https://github.com/Brickleberry19)
4978
- [JSON script source](https://script.google.com/d/143u0RLuppsmYJ0B3wzo6i0jZYSfIFV2NLJMHPM-Sqczpr9bLwdffc-Wx/edit?usp=sharing)

app.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
@copyright: Copyright 2017, AmiiboAPI
66
@license: MIT License
77
"""
8+
import os
9+
import re
810
import colors
911

1012
from rfc3339 import rfc3339
1113

12-
from flask import Flask, jsonify, make_response, render_template, request
14+
from flask import Flask, abort, jsonify, make_response, render_template, request, send_from_directory
1315
from flask_compress import Compress
1416
from flask_cors import CORS
17+
from werkzeug.exceptions import NotFound
1518

1619
from commons.amiibo_json_encounter import AmiiboJSONEncoder
1720
from amiibo.manager import AmiiboManager
@@ -58,6 +61,18 @@ def documentation():
5861
def faqPage():
5962
return render_template('faq.html')
6063

64+
65+
@app.route('/.well-known/acme-challenge/<path:filename>')
66+
def certbot_challenge(filename):
67+
if not re.fullmatch(r"[A-Za-z0-9_-]+", filename):
68+
abort(404)
69+
webroot = os.getenv("CERTBOT_WEBROOT", "/var/www/certbot")
70+
challenge_dir = os.path.join(webroot, ".well-known", "acme-challenge")
71+
try:
72+
return send_from_directory(challenge_dir, filename)
73+
except (FileNotFoundError, NotFound):
74+
abort(404)
75+
6176
# Handle 400 as json or else Flask will use html as default.
6277
@app.errorhandler(400)
6378
def bad_request(e):

0 commit comments

Comments
 (0)