Skip to content

Commit c02493b

Browse files
committed
Merge branch 'main' of https://github.com/nexB/federatedcode into main
2 parents 867fb40 + 8e226fb commit c02493b

108 files changed

Lines changed: 835 additions & 2551 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.

Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,32 @@
66
# See https://github.com/nexB/federatedcode for support or download.
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
9-
FROM python:3.10
9+
10+
FROM python:3.10-slim
11+
12+
ENV APP_NAME federatedcode
13+
ENV APP_DIR /opt/$APP_NAME
14+
1015
# Python settings: Force unbuffered stdout and stderr (i.e. they are flushed to terminal immediately)
1116
ENV PYTHONUNBUFFERED 1
1217
# Python settings: do not write pyc files
1318
ENV PYTHONDONTWRITEBYTECODE 1
19+
# Add the app dir in the Python path for entry points availability
20+
ENV PYTHONPATH $PYTHONPATH:$APP_DIR
1421

15-
RUN pip install --upgrade pip
22+
RUN apt-get update \
23+
&& apt-get install -y --no-install-recommends \
24+
wait-for-it \
25+
git \
26+
&& apt-get clean \
27+
&& rm -rf /tmp/* /var/tmp/*
1628

17-
WORKDIR /federatedcode
29+
WORKDIR $APP_DIR
1830

19-
COPY requirements.txt pyproject.toml /federatedcode/
31+
RUN mkdir -p /var/$APP_NAME/static/
2032

21-
RUN pip install -r requirements.txt
33+
# Keep the dependencies installation before the COPY of the app/ for proper caching
34+
COPY setup.cfg setup.py requirements.txt pyproject.toml $APP_DIR/
35+
RUN pip install . -c requirements.txt
2236

23-
COPY . /federatedcode
37+
COPY . $APP_DIR

README.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@ security information.
99
Quick Installation
1010
--------------------
1111

12+
Run with Docker
13+
~~~~~~~~~~~~~~~
14+
15+
16+
Clone FederatedCode::
17+
18+
git clone https://github.com/aboutcode-org/federatedcode.git
19+
cd federatedcode
20+
21+
Build and run::
22+
23+
docker compose build
24+
docker compose up
25+
26+
27+
Local development installation
28+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
1230
On a Debian system, use this::
1331

1432
sudo apt-get install python3-venv python3-dev postgresql libpq-dev build-essential
15-
git clone https://github.com/nexB/federatedcode.git
33+
git clone https://github.com/aboutcode-org/federatedcode.git
1634
cd federatedcode
1735
make dev envfile postgresdb
1836
make test
@@ -164,9 +182,3 @@ funding is made available by the Swiss State Secretariat for Education, Research
164182
:target: https://nlnet.nl/discovery/
165183
:height: 40
166184
:alt: NGI Discovery logo
167-
168-
169-
170-
171-
172-

aboutcode/federatedcode/README.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=======================
2+
aboutcode.federatedcode
3+
=======================
4+
5+
|license| |build|
6+
7+
.. |license| image:: https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge
8+
:target: https://opensource.org/licenses/Apache-2.0
9+
10+
.. |build| image:: https://img.shields.io/github/actions/workflow/status/aboutcode-org/federatedcode/main.yml?style=for-the-badge&logo=github
11+
12+
This is a library of FederatedCode client utilities to fetch and subscribe package metadata.
13+
14+
15+
License
16+
=======
17+
18+
Copyright (c) nexB Inc. and others. All rights reserved.
19+
20+
SPDX-License-Identifier: Apache-2.0
21+
22+
See https://aboutcode.org for more information about AboutCode OSS projects.
23+
24+
.. code-block:: none
25+
26+
You may not use this software except in compliance with the License.
27+
You may obtain a copy of the License at
28+
29+
http://www.apache.org/licenses/LICENSE-2.0
30+
31+
Unless required by applicable law or agreed to in writing, software
32+
distributed under the License is distributed on an "AS IS" BASIS,
33+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34+
See the License for the specific language governing permissions and
35+
limitations under the License.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# FederatedCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/federatedcode for support or download.
7+
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
8+
#
9+
10+
import os
11+
from typing import Union
12+
from urllib.parse import urljoin
13+
14+
import requests
15+
from aboutcode.hashid import get_package_base_dir
16+
from dotenv import load_dotenv
17+
from packageurl import PackageURL
18+
19+
load_dotenv()
20+
21+
FEDERATEDCODE_GITHUB_ACCOUNT_NAME = os.getenv("FEDERATEDCODE_GITHUB_ACCOUNT_NAME")
22+
23+
24+
class ScanNotAvailableError(Exception):
25+
pass
26+
27+
28+
def get_package_scan(purl: Union[PackageURL, str]):
29+
"""Return the package scan result for a PURL from the FederatedCode Git repository."""
30+
31+
if not FEDERATEDCODE_GITHUB_ACCOUNT_NAME:
32+
raise ValueError("Provide ``FEDERATEDCODE_GITHUB_ACCOUNT_NAME`` in .env file.")
33+
34+
if isinstance(purl, str):
35+
purl = PackageURL.from_string(purl)
36+
37+
if not purl.version:
38+
raise ValueError("Missing version in PURL.")
39+
40+
package_path = get_package_base_dir(purl=purl)
41+
package_path_parts = package_path.parts
42+
43+
repo_name = f"{package_path_parts[0]}/refs/heads/main"
44+
package_dir_path = "/".join(package_path_parts[1:])
45+
version = purl.version
46+
file_name = "scancodeio.json"
47+
48+
url_parts = [FEDERATEDCODE_GITHUB_ACCOUNT_NAME, repo_name, package_dir_path, version, file_name]
49+
50+
file_url = urljoin("https://raw.githubusercontent.com", "/".join(url_parts))
51+
52+
try:
53+
response = requests.get(file_url)
54+
response.raise_for_status()
55+
return response.json()
56+
except requests.exceptions.HTTPError as err:
57+
if response.status_code == 404:
58+
raise ScanNotAvailableError(f"No scan available for {purl!s}")
59+
raise err

docker-compose.yml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
11
version: '3'
22

33
services:
4-
federatedcode_db:
5-
image: postgres:16
4+
db:
5+
image: postgres:13
66
env_file:
77
- docker.env
88
volumes:
9-
- federatedcode_db_data:/var/lib/postgresql/data/
9+
- db_data:/var/lib/postgresql/data/
1010

11-
federatedcode:
11+
web:
1212
build: .
13-
command: /bin/sh -c "
14-
apt-get update && apt-get install -y gunicorn &&
15-
python manage.py collectstatic --no-input --verbosity 0 --clear &&
16-
python manage.py migrate &&
17-
gunicorn federatedcode.wsgi:application -u nobody -g nogroup --bind :8000 --timeout 600 --workers 8"
13+
command: wait-for-it --strict --timeout=60 db:5432 -- sh -c "
14+
./manage.py migrate &&
15+
./manage.py collectstatic --no-input --verbosity 0 --clear &&
16+
gunicorn federatedcode.wsgi:application --bind :8000 --timeout 600 --workers 8"
1817
env_file:
1918
- docker.env
2019
expose:
2120
- 8000
22-
ports:
23-
- "8000:8000"
2421
volumes:
25-
- static:/var/federatedcode/static/
2622
- /etc/federatedcode/:/etc/federatedcode/
23+
- static:/var/federatedcode/static/
24+
- workspace:/var/federatedcode/workspace/
2725
depends_on:
28-
- federatedcode_db
26+
- db
2927

30-
federatedcode_nginx:
28+
nginx:
3129
image: nginx
30+
ports:
31+
- 80:80
32+
- 443:443
3233
env_file:
3334
- docker.env
3435
volumes:
35-
- ./etc/nginx/conf.d/:/etc/nginx/conf.d
36+
- ./etc/nginx/conf.d/:/etc/nginx/conf.d/
37+
- static:/var/federatedcode/static/
38+
- /var/www/html:/var/www/html
3639
depends_on:
37-
- federatedcode
40+
- web
3841

3942
volumes:
40-
federatedcode_db_data:
41-
federatedcode_static:
42-
federatedcode:
43-
43+
db_data:
44+
static:
45+
workspace:

docker.env

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
FEDERATEDCODE_WORKSPACE_LOCATION=/var/federatedcode
1+
POSTGRES_DB=federatedcode
2+
POSTGRES_USER=federatedcode
3+
POSTGRES_PASSWORD=federatedcode
4+
5+
FEDERATEDCODE_DB_HOST=db
6+
FEDERATEDCODE_STATIC_ROOT=/var/federatedcode/static/
7+
8+
FEDERATEDCODE_WORKSPACE_LOCATION=/var/federatedcode/workspace/
29
FEDERATEDCODE_CLIENT_ID=""
310
FEDERATEDCODE_CLIENT_SECRET=""
4-
NGINX_PORT=8080

docs/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "federatedcode.settings")
1717
os.environ.setdefault("SECRET_KEY", "dummy secret key for autodoc rtd documentation")
1818
os.environ.setdefault("FEDERATEDCODE_CLIENT_ID", "dummy secret key for autodoc rtd documentation")
19-
os.environ.setdefault("FEDERATEDCODE_CLIENT_SECRET", "dummy secret key for autodoc rtd documentation")
19+
os.environ.setdefault(
20+
"FEDERATEDCODE_CLIENT_SECRET", "dummy secret key for autodoc rtd documentation"
21+
)
2022

2123
sys.path.insert(0, os.path.abspath("../../."))
2224

41.5 KB
Loading
16.6 KB
Loading
40.6 KB
Loading

0 commit comments

Comments
 (0)