File size: 3,757 Bytes
00b4479 e9833fa fa76f5f 59ebac7 3dbe011 7d6e00c 3dbe011 b2b1ed7 59ebac7 b2b1ed7 59ebac7 b2b1ed7 59ebac7 b2b1ed7 59ebac7 9e6626c b2b1ed7 9e6626c 5a246f7 2b50a97 5a246f7 00b4479 6f2f547 00b4479 6f2f547 00b4479 c655420 2ac5c46 c655420 00b4479 2b50a97 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# SamGIS
## todo
1. export output to mask: OK local, OK aws lambda
2. resolve model paths: OK local
3. inference:
4. from mask to json (rasterio + geopandas, check for re-projection to EPSG_4326)
5. check mandatory dependencies
6. check for alternative python interpreters
## Build instructions
Build the docker image:
```bash
# clean any old active containers
docker stop $(docker ps -a -q); docker rm $(docker ps -a -q)
# build the base docker image with the docker aws repository tag
docker build . -f dockerfiles/dockerfile-lambda-gdal-runner --tag 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-gdal-runner
# OPTIONAL: to build the lambda-gdal-runner image on a x86 machine use the build arg `RIE="https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie"`:
docker build . -f dockerfiles/dockerfile-lambda-gdal-runner --build-arg RIE="https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie" --tag 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-gdal-runner --progress=plain
# build the final docker image
docker build . -f dockerfiles/dockerfile-lambda-fastsam-api --tag 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-fastsam-api
```
Run the container (keep it on background) and show logs
```bash
docker tag 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-fastsam-api:latest lambda-fastsam-api;docker run -d --name lambda-fastsam-api -p 8080:8080 lambda-fastsam-api; docker logs -f lambda-fastsam-api
```
Test it with curl:
```bash
URL=http://localhost:8080/2015-03-31/functions/function/invocations
curl -X 'POST' \
${URL} \
-H 'accept: application/json' \
-d '{}'
```
## Publish the aws lambda
1. Login on aws ECR with the correct aws profile (details on [ECR page](https://eu-west-1.console.aws.amazon.com/ecr/repositories/private/686901913580/surferdtm-prediction-api?region=eu-west-1))
```
aws --profile alessandrotrinca_hotmail_aws_console_ec2_lambda ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 686901913580.dkr.ecr.eu-west-1.amazonaws.com
```
2. Build and tag the docker images, then push them:
```
docker push 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-gdal-runner:latest
docker push 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-fastsam-api:latest
```
3. It's possible to publish a new aws lambda version from cmd or from lambda page
## Dependencies installation and local tests
The docker build process needs only the classic requirements.txt, instead for local development and sphinx-docs build
there is `Pipfile` (sphinx docs is hosted on Cloudflare Pages).
## Tests
Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
```bash
python -m pytest --cov=src --cov-report=term-missing && coverage html
```
## Update the static documentation with sphinx
Run the sphinx-apidoc: it's a tool for automatic generation of Sphinx sources that, using the autodoc
extension, document a whole package in the style of other automatic API documentation tools. See the
[documentation page](https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html) for details.
Run the command from the project root:
```bash
# missing docs folder (run from project root)
cd docs && sphinx-quickstart -p SamGIS -a "alessandro trinca tornidor" -r 1.0.0 -l python --master index
# update docs folder (from project root)
sphinx-apidoc -f -o docs src
```
Then it's possible to generate the HTML pages
```bash
cd docs && make html && ../
# to clean old files
cd docs && make clean html && cd ../
```
The static documentation it's now ready at the path `docs/_build/html/index.html`.
|