-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1522df8
commit 5116113
Showing
10 changed files
with
178 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
__pycache__/ | ||
.git/ | ||
.idea/ | ||
cache/ | ||
venv/ | ||
.gitignore | ||
docker-build.sh | ||
docker-run.sh | ||
# Ignore everything | ||
* | ||
|
||
# Allow files and directories | ||
!/main.py | ||
!/web.py | ||
!/requirements.txt | ||
!/Dockerfile | ||
!/docker | ||
|
||
# Ignore unnecessary files inside allowed directories | ||
# This should go after the allowed directories | ||
**/*~ | ||
**/*.log | ||
**/.DS_Store | ||
**/Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Docker Image Build and Push to registry | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
push: | ||
tags: [v*] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup Python 3.11 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Install Python deps | ||
run: | | ||
pip install -r requirements.txt | ||
pip install pytest ruff | ||
- name: Lint with Ruff | ||
run: ruff . | ||
- name: Run tests | ||
run: pytest tests | ||
|
||
build: | ||
needs: tests | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: denisbondar/strava-heatmap-cache | ||
tags: | | ||
type=raw,value=latest | ||
type=pep440,pattern={{version}} | ||
labels: | | ||
maintainer=Denis Bondar <[email protected]> | ||
org.opencontainers.image.title=Strava Heatmap Cache | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
FROM python:3.8-alpine as base | ||
FROM python:3.11-slim-bullseye as base | ||
|
||
COPY requirements.txt / | ||
|
||
RUN apk update \ | ||
&& apk add --no-cache --virtual \ | ||
.build-deps \ | ||
gcc \ | ||
musl-dev \ | ||
curl \ | ||
linux-headers | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
################################################################################ | ||
|
||
FROM python:3.8-alpine | ||
|
||
FROM python:3.11-slim-bullseye | ||
|
||
RUN mkdir -p /app/cache | ||
|
||
WORKDIR /app | ||
COPY --from=base /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages | ||
COPY ./*.py /app/ | ||
|
||
COPY ./docker/rootfs / | ||
COPY --from=base /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages | ||
COPY web.py main.py ./ | ||
|
||
RUN chmod +x /usr/bin/docker-entrypoint.sh | ||
|
||
VOLUME /app/cache | ||
|
||
VOLUME /var/run/strava.sock | ||
|
||
EXPOSE 8080 | ||
|
||
ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] | ||
|
||
CMD ["python3", "web.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
|
||
_is_sourced() { | ||
# https://unix.stackexchange.com/a/215279 | ||
[ "${#FUNCNAME[@]}" -ge 2 ] && | ||
[ "${FUNCNAME[0]}" = '_is_sourced' ] && | ||
[ "${FUNCNAME[1]}" = 'source' ] | ||
} | ||
|
||
_main() { | ||
if [ "$1" = 'build' ]; then | ||
exec python /app/main.py | ||
fi | ||
|
||
exec "$@" | ||
} | ||
|
||
if ! _is_sourced; then | ||
_main "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[project] | ||
name = "Strave Headmap Chache" | ||
requires-python = ">=3.11" | ||
|
||
[tool.ruff] | ||
target-version = "py311" | ||
line-length = 119 | ||
select = [ | ||
"E", # pycodestyle | ||
"F", # pyflakes | ||
"UP", # pyupgrade | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from main import Tile, GeoPoint | ||
|
||
|
||
def test_create_from_geo_coordinates(): | ||
assert Tile.create_from_geo_coordinates(GeoPoint(46.90946, 30.19284), 9) == Tile(298, 180, 9) | ||
|
||
|
||
def test_geo_to_tile(): | ||
assert Tile.geo_to_tile(GeoPoint(46.90946, 30.19284), 9) == (298, 180) | ||
assert Tile.geo_to_tile(GeoPoint(46.10655, 31.39070), 9) == (300, 181) | ||
|
||
|
||
def test_generate_from_area(): | ||
gen = Tile.generate_from_area(GeoPoint(46.90946, 30.19284), | ||
GeoPoint(46.10655, 31.39070), | ||
range(9, 10)) | ||
assert [t for t in gen] == [Tile(298, 180, 9), Tile(299, 180, 9), | ||
Tile(300, 180, 9), Tile(298, 181, 9), | ||
Tile(299, 181, 9), Tile(300, 181, 9)] |