-
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.
Merge pull request #2 from inab/feature/download-endpoint
Feature/download endpoint
- Loading branch information
Showing
9 changed files
with
188 additions
and
89 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,66 +1,49 @@ | ||
name: CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.10.6 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: | | ||
pytest -v app/tests | ||
build: | ||
runs-on: ubuntu-latest | ||
needs: test | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ghcr.io/inab/observatory-api:latest | ||
name: Build and Publish Docker on Tag | ||
|
||
on: | ||
# Trigger the workflow when a new tag is pushed | ||
push: | ||
tags: | ||
- 'v*' # Match tags like v1.0.0, v2.1.0, etc. | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Build the Docker image with the Git tag | ||
- name: Build and tag Docker image | ||
run: | | ||
TAG_NAME=${GITHUB_REF#refs/tags/} # Extract the tag name (e.g., v1.0.0) | ||
docker build -t ghcr.io/inab/observatory-api:${TAG_NAME} . | ||
docker tag ghcr.io/inab/observatory-api:${TAG_NAME} ghcr.io/inab/observatory-api:latest | ||
# Push the Docker image to the registry | ||
- name: Push Docker image | ||
run: | | ||
TAG_NAME=${GITHUB_REF#refs/tags/} # Extract the tag name (e.g., v1.0.0) | ||
docker push ghcr.io/inab/observatory-api:${TAG_NAME} | ||
docker push ghcr.io/inab/observatory-api:latest |
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,31 @@ | ||
name: CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.10.6 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: | | ||
pytest -v app/tests |
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,2 @@ | ||
2.0.0 | ||
2.1.0 |
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,32 @@ | ||
from fastapi import HTTPException, APIRouter | ||
from pydantic import BaseModel | ||
import requests | ||
|
||
router = APIRouter() | ||
|
||
class URLRequest(BaseModel): | ||
url: str | ||
|
||
@router.post("/download-content/", tags=["downloads"]) | ||
async def download_content(request: URLRequest): | ||
""" | ||
Download content from a specified URL. | ||
This endpoint accepts a URL in the request body and returns the HTML content | ||
of the specified URL. If the URL is invalid or the content cannot be downloaded, | ||
it returns a 400 status code with an error message. | ||
Args: | ||
request (URLRequest): A JSON object containing the URL to be downloaded. | ||
Returns: | ||
dict: A dictionary containing the original URL and the downloaded content. | ||
""" | ||
try: | ||
print(request.url) | ||
response = requests.get(request.url) | ||
response.raise_for_status() | ||
except requests.exceptions.RequestException as e: | ||
raise HTTPException(status_code=400, detail=f"Error downloading content: {e}") | ||
|
||
return {"url": request.url, "content": response.text} |
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 @@ | ||
# Ready-to-use database | ||
|
||
To facilitate the testing of the Observatory API, a docker-compose to deploy and populate a full and ready-to-use database is available (`mongo-compose/docker-compose.yml`). | ||
|
||
The components necessary for this deployment are `mongodb`, `mongo-total` and `mongo-seed`. The configuration of the latter two can be found in the `mongo-compose` directory. | ||
|
||
To deploy the database: | ||
|
||
``` | ||
sudo docker login registry.gitlab.bsc.es | ||
sudo docker-compose up --remove-orphans --force-recreate --renew-anon-volumes | ||
``` |
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,43 @@ | ||
#!/bin/bash | ||
|
||
# Fail script if any command fails | ||
set -e | ||
|
||
# Ensure that we're on the main branch and up to date | ||
git checkout main | ||
git pull origin main | ||
|
||
# Read the latest version from the VERSION file | ||
NEW_VERSION=$(cat VERSION) | ||
|
||
echo "Validating version format..." | ||
|
||
# Check if the version follows Semantic Versioning (MAJOR.MINOR.PATCH) | ||
if [[ ! "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "ERROR: The version '$NEW_VERSION' in the VERSION file does not follow Semantic Versioning (e.g., 1.0.0)." | ||
exit 1 | ||
fi | ||
|
||
# Check if the version needs a "v" prefix, and add it if not present | ||
if [[ "$NEW_VERSION" != v* ]]; then | ||
NEW_VERSION="v$NEW_VERSION" | ||
echo "Prepending 'v' to version. New version is $NEW_VERSION" | ||
fi | ||
|
||
# Check if the version already has a Git tag | ||
echo "Checking if version $NEW_VERSION already has a tag..." | ||
if git rev-parse "$NEW_VERSION" >/dev/null 2>&1; then | ||
echo "ERROR: Version $NEW_VERSION already has a tag!" | ||
echo "It looks like you forgot to update the VERSION file." | ||
echo "Please update the VERSION file to the new version." | ||
exit 1 | ||
fi | ||
|
||
# If no existing tag, proceed with committing and pushing the version update | ||
echo "Version $NEW_VERSION does not have a tag. Proceeding with the update." | ||
|
||
git tag "$NEW_VERSION" | ||
|
||
git push origin main "$NEW_VERSION" | ||
|
||
echo "Version updated to $NEW_VERSION and pushed to main branch." |