-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit implements the report using Tern The reports use the ``concurrent.futures``, but instead of building all the implementation for it, we use flask-executer that makes the implementation on top of Flask. All the report requests go to the ``tern-tasks`` (Futures) and are handled such as a Celery implementation. All tasks start with the status 'UNKNOWN', which means that the task has no defined status until the ``tern-tasks`` start processing it. Once the task is in picked up by the ``tern-tasks`` it is moved to 'RUNNING'. If the processing finishes, the status is moved to 'FINISH' independently of the task content/result. Here the status is for the task itself. The FAIL status is given when the task cannot finish its routine. The Tern, for now, is called using ``subprocess``, and the output is handled by the stdout and stderr. The initial API specification was changed a bit for more clearness. How to run as Docker container was added to the README.md. Signed-off-by: Kairo de Araujo <[email protected]>
- Loading branch information
Kairo de Araujo
committed
Mar 9, 2022
1 parent
4086cba
commit 6233661
Showing
16 changed files
with
456 additions
and
167 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
tests/ | ||
docs/ | ||
cached/ | ||
.github | ||
.gitignore | ||
Dockerfile | ||
Makefile | ||
Pipfile | ||
Pipfile.lock | ||
README.md | ||
requirements-dev.txt | ||
setup.py | ||
tox.ini | ||
.coverage | ||
.dockerignore | ||
.git | ||
.mypy_cache | ||
.pytest_cache | ||
.tox | ||
__pycache__ | ||
tern_rest_api.egg-info |
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,3 +1,6 @@ | ||
# tern-rest-api specifics | ||
cached | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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,29 @@ | ||
# Copyright (c) 2022 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
|
||
FROM python:3.9-slim-buster as base | ||
|
||
RUN echo "deb http://deb.debian.org/debian bullseye main" > /etc/apt/sources.list.d/bullseye.list \ | ||
&& echo "Package: *\nPin: release n=bullseye\nPin-Priority: 50" > /etc/apt/preferences.d/bullseye \ | ||
&& apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
attr \ | ||
findutils \ | ||
fuse-overlayfs/bullseye \ | ||
fuse3/bullseye \ | ||
git \ | ||
jq \ | ||
skopeo \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN mkdir /opt/tern-rest-api | ||
|
||
ADD . /opt/tern-rest-api | ||
WORKDIR /opt/tern-rest-api | ||
RUN pip install --no-cache -r ./requirements.txt | ||
|
||
ENV TERN_API_CACHE_DIR=/var/opt/tern-rest-api/cached | ||
ENV TERN_DEFAULT_REGISTRY="registry.hub.docker.com" | ||
|
||
ENV FLASK_APP=/opt/tern-rest-api/app.py | ||
CMD ["bash", "docker_start.sh"] |
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,6 @@ | ||
build-dev: | ||
docker build -t tern-rest-api:dev . | ||
|
||
|
||
serve-dev: build-dev | ||
docker run --rm --name tern-rest-api -e ENVIRONMENT=DEVELOPMENT --privileged -v /var/run/docker.sock:/var/run/docker.sock -v $(PWD):/opt/tern-rest-api -p 5001:80 tern-rest-api:dev |
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
Large diffs are not rendered by default.
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
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,7 @@ | ||
#!/bin/bash | ||
|
||
if [[ ${ENVIRONMENT^^} == "DEVELOPMENT" ]]; then | ||
flask run --reload --debugger -h 0.0.0.0 -p 80 | ||
else | ||
gunicorn --workers=1 -b 0.0.0.0:80 app:tern_api | ||
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
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,7 +1,15 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2022 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
import os | ||
|
||
from flask import Flask | ||
from flask_executor import Executor | ||
|
||
tern_app = Flask(__name__) | ||
tern_app.config["TERN_API_CACHE_DIR"] = os.getenv("TERN_API_CACHE_DIR") | ||
tern_app.config["TERN_DEFAULT_REGISTRY"] = os.getenv("TERN_DEFAULT_REGISTRY") | ||
|
||
tern_api = Flask(__name__) | ||
tern_tasks = Executor(tern_app) |
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
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,8 @@ | ||
from enum import Enum | ||
|
||
|
||
class task_status(Enum): | ||
UNKNOWN = "UNKNOWN" | ||
RUNNING = "RUNNING" | ||
FINISH = "FINISH" | ||
FAIL = "FAIL" |
Oops, something went wrong.