Skip to content

Commit 47ed88e

Browse files
committed
Added build.yml
1 parent cc99875 commit 47ed88e

File tree

9 files changed

+133
-49
lines changed

9 files changed

+133
-49
lines changed

.github/workflows/build.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Automatically build container images for every push to master,
2+
# and also every version tag in the form X.X.X[.*].
3+
# Built images are pushed to both docker.io and ghcr.io
4+
5+
name: Build
6+
7+
on:
8+
push:
9+
branches: [ master ]
10+
tags:
11+
- "[0-9]+.[0-9]+.[0-9]+*"
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Get git tag
18+
id: git_info
19+
if: startsWith(github.ref, 'refs/tags/')
20+
run: echo "::set-output name=tag::${GITHUB_REF##*/}"
21+
- name: Determine image tags
22+
id: determine
23+
env:
24+
git_tag: ${{ steps.git_info.outputs.tag }}
25+
run: |
26+
repo="${GITHUB_REPOSITORY,,}" # to lower case
27+
tag="${git_tag:-latest}" # if build triggered by tag, use tag name
28+
echo "::set-output name=repo::$repo"
29+
echo "::set-output name=tag::$tag"
30+
echo "::set-output name=dock_image::$repo:$tag"
31+
- uses: docker/setup-qemu-action@v1
32+
- uses: docker/setup-buildx-action@v1
33+
id: buildx
34+
- name: Cache Docker layers
35+
uses: actions/cache@v2
36+
with:
37+
path: /tmp/.buildx-cache
38+
key: ${{ runner.os }}-buildx-${{ github.sha }}
39+
restore-keys: |
40+
${{ runner.os }}-buildx-
41+
- name: Login to DockerHub
42+
uses: docker/login-action@v1
43+
with:
44+
username: ${{ secrets.DOCKERHUB_USERNAME }}
45+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
46+
47+
- name: Login to GitHub Container Registry
48+
uses: docker/login-action@v1
49+
with:
50+
registry: ghcr.io
51+
username: ${{ github.repository_owner }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
- name: Build and push
54+
uses: docker/build-push-action@v2
55+
with:
56+
push: true
57+
tags: |
58+
${{ steps.determine.outputs.dock_image }}
59+
ghcr.io/${{ steps.determine.outputs.dock_image }}
60+
platforms: linux/amd64,linux/ppc64le,linux/arm64,linux/arm/v7
61+
cache-from: type=local,src=/tmp/.buildx-cache
62+
cache-to: type=local,dest=/tmp/.buildx-cache
63+
PushContainerReadme:
64+
runs-on: ubuntu-latest
65+
name: Push README to Docker Hub
66+
steps:
67+
- name: git checkout
68+
uses: actions/checkout@v2
69+
- name: push README to Dockerhub
70+
uses: christian-korneck/update-container-description-action@v1
71+
env:
72+
DOCKER_USER: ${{ secrets.DOCKERHUB_USERNAME }}
73+
DOCKER_PASS: ${{ secrets.DOCKERHUB_PASSWORD }}
74+
with:
75+
destination_container_repo: fnndsc/pflink
76+
provider: dockerhub
77+
short_description: 'A Python-FastAPI application to interact with CUBE and pfdcm.'
78+
readme_file: 'README.md'
79+

app/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Settings(BaseSettings):
55
pflink_mongodb: MongoDsn = 'mongodb://localhost:27017'
6-
version: str = "2.1.3"
6+
version: str = "2.1.5"
77

88

99
settings = Settings()

app/controllers/pfdcm.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,45 +85,48 @@ async def about_pfdcm(service_name: str) -> dict:
8585

8686

8787
# Get the list of `cube` available in a pfdcm instance
88-
async def cube_list(service_name: str) -> dict:
88+
async def cube_list(service_name: str) -> list[str]:
89+
d_results = []
8990
pfdcm_server = retrieve_pfdcm(service_name)
9091
if not pfdcm_server:
91-
return {"error": f"{service_name} does not exist."}
92+
return d_results
9293
pfdcm_url = pfdcm_server['service_address']
9394
pfdcm_cube_list_api = f'{pfdcm_url}/api/v1/SMDB/CUBE/list/'
9495
try:
9596
response = requests.get(pfdcm_cube_list_api)
9697
d_results = json.loads(response.text)
9798
return d_results
9899
except:
99-
return{"error": f"Unable to reach {pfdcm_url}."}
100+
return d_results
100101

101102

102103
# Get the list of `swift` servers available in a pfdcm instance
103-
async def swift_list(service_name: str) -> dict:
104+
async def swift_list(service_name: str) -> list[str]:
105+
d_results = []
104106
pfdcm_server = retrieve_pfdcm(service_name)
105107
if not pfdcm_server:
106-
return {"error": f"{service_name} does not exist."}
108+
return d_results
107109
pfdcm_url = pfdcm_server['service_address']
108110
pfdcm_swift_list_api = f'{pfdcm_url}/api/v1/SMDB/swift/list/'
109111
try:
110112
response = requests.get(pfdcm_swift_list_api)
111113
d_results = json.loads(response.text)
112114
return d_results
113115
except:
114-
return{"error": f"Unable to reach {pfdcm_url}."}
116+
return d_results
115117

116118

117119
# Get the list of `PACS service` available in a pfdcm instance
118-
async def pacs_list(service_name: str) -> dict:
120+
async def pacs_list(service_name: str) -> list[str]:
121+
d_results = []
119122
pfdcm_server = retrieve_pfdcm(service_name)
120123
if not pfdcm_server:
121-
return {"error": f"{service_name} does not exist."}
124+
return d_results
122125
pfdcm_url = pfdcm_server['service_address']
123126
pfdcm_pacs_list_api = f'{pfdcm_url}/api/v1/PACSservice/list'
124127
try:
125128
response = requests.get(pfdcm_pacs_list_api)
126129
d_results = json.loads(response.text)
127130
return d_results
128131
except:
129-
return{"error": f"Unable to reach {pfdcm_url}."}
132+
return d_results

app/main.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from fastapi import FastAPI
22
from fastapi.middleware.cors import CORSMiddleware
3-
from app.routes.basic import router as BasicRouter
4-
from app.routes.pfdcm import router as PfdcmRouter
5-
from app.routes.workflow import router as WorkflowRouter
6-
from app.routes.testing import router as WorkflowTestRouter
3+
from app.routes.basic import router as basic_router
4+
from app.routes.pfdcm import router as pfdcm_router
5+
from app.routes.workflow import router as workflow_router
6+
from app.routes.testing import router as workflow_testing_router
77
from app.config import settings
88

99
description = """
@@ -15,8 +15,15 @@
1515
## pfdcm
1616
1717
You can **add**,**retrieve** `pfdcm` service info.
18+
Additionally you can:
1819
19-
## Workflows
20+
* **Get a `hello` response from a pfdcm instance.**
21+
* **Know `about` a pfdcm instance.**
22+
* **Get the list of the names of all `cube` instances available in a pfdcm instance.**
23+
* **Get the list of the names of all `swift` instances available in a pfdcm instance.**
24+
* **Get the list of the names of all `PACS` instances available in a pfdcm instance.**
25+
26+
## Workflow
2027
2128
You can **create** new workflows and get status of the workflow.
2229
@@ -69,7 +76,7 @@
6976
allow_methods=["GET", "POST", "PUT", "OPTIONS"],
7077
allow_headers=["*"],
7178
)
72-
app.include_router(BasicRouter, tags=["Basic Info"], prefix="/api/v1")
73-
app.include_router(PfdcmRouter, tags=["Pfdcm Service Info"], prefix="/api/v1/pfdcm")
74-
app.include_router(WorkflowRouter, tags=["Workflow Services"], prefix="/api/v1/workflow")
75-
app.include_router(WorkflowTestRouter, tags=["Test Workflow Services"], prefix="/api/v1/testing")
79+
app.include_router(basic_router, tags=["Basic Info"], prefix="/api/v1")
80+
app.include_router(pfdcm_router, tags=["Pfdcm Service Info"], prefix="/api/v1/pfdcm")
81+
app.include_router(workflow_router, tags=["Workflow Services"], prefix="/api/v1/workflow")
82+
app.include_router(workflow_testing_router, tags=["Test Workflow Services"], prefix="/api/v1/testing")

app/routes/pfdcm.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from fastapi import APIRouter, Body
1+
from fastapi import APIRouter, Body, HTTPException
22
from fastapi.encoders import jsonable_encoder
33

44
from app.controllers.pfdcm import (
@@ -15,7 +15,6 @@
1515
from app.models.pfdcm import (
1616
PfdcmQuerySchema,
1717
PfdcmQueryResponseSchema,
18-
PfdcmCollectionResponseModel,
1918
)
2019

2120
router = APIRouter()
@@ -44,14 +43,12 @@ async def add_pfdcm_data(pfdcm: PfdcmQuerySchema = Body(...)) -> PfdcmQueryRespo
4443
response_description="pfdcm setup info.",
4544
summary="Retrieve all `pfdcm` services saved."
4645
)
47-
async def get_pfdcms() -> PfdcmCollectionResponseModel:
46+
async def get_pfdcms() -> list[str]:
4847
"""
4948
Fetch all `pfdcm` service addresses from the DB.
5049
"""
5150
pfdcms = await retrieve_pfdcms()
52-
if pfdcms:
53-
return PfdcmCollectionResponseModel(data=pfdcms, message="pfdcm data retrieved successfully.")
54-
return PfdcmCollectionResponseModel(data=pfdcms, message="There are no records in the DB.")
51+
return pfdcms
5552

5653

5754
@router.get(
@@ -100,35 +97,41 @@ async def get_about_pfdcm(service_name: str) -> PfdcmQueryResponseSchema:
10097
response_description="About PFDCM",
10198
summary="Get the list of cube services registered to a `pfdcm` instance"
10299
)
103-
async def cube_service_list(service_name: str) -> PfdcmCollectionResponseModel:
100+
async def cube_service_list(service_name: str) -> list[str]:
104101
"""
105102
Get the list of PACS services registered to a `pfdcm` instance by providing its service name
106103
"""
107104
response = await cube_list(service_name)
108-
return PfdcmQueryResponseSchema(data=response, message="")
105+
if not response:
106+
raise HTTPException(status_code=404, detail=f"Unable to reach endpoints of {service_name}")
107+
return response
109108

110109

111110
@router.get(
112111
"/{service_name}/swift/list",
113112
response_description="About PFDCM",
114113
summary="Get the list of swift services registered to a `pfdcm` instance"
115114
)
116-
async def swift_service_list(service_name: str) -> PfdcmCollectionResponseModel:
115+
async def swift_service_list(service_name: str) -> list[str]:
117116
"""
118117
Get the list of PACS services registered to a `pfdcm` instance by providing its service name
119118
"""
120119
response = await swift_list(service_name)
121-
return PfdcmQueryResponseSchema(data=response, message="")
120+
if not response:
121+
raise HTTPException(status_code=404, detail=f"Unable to reach endpoints of {service_name}")
122+
return response
122123

123124

124125
@router.get(
125126
"/{service_name}/PACSservice/list",
126127
response_description="About PFDCM",
127128
summary="Get the list of PACS services registered to a `pfdcm` instance"
128129
)
129-
async def pacs_service_list(service_name: str) -> PfdcmCollectionResponseModel:
130+
async def pacs_service_list(service_name: str) -> list[str]:
130131
"""
131132
Get the list of PACS services registered to a `pfdcm` instance by providing its service name
132133
"""
133134
response = await pacs_list(service_name)
134-
return PfdcmQueryResponseSchema(data=response, message="")
135+
if not response:
136+
raise HTTPException(status_code=404, detail=f"Unable to reach endpoints of {service_name}")
137+
return response

app/routes/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def test_create_workflow(
3131
* **compute**
3232
* **cube**
3333
34-
For an invalid error_type you get a error message as follows:
34+
For an invalid error_type you get an error message as follows:
3535
* "Undefined error_type : Please pass values as pfdcm/study/feed/analysis/compute/cube as valid error_type"
3636
"""
3737
response = await post_workflow(data, test=True, error_type=error_type)

pflink.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
docker build -t local/pflink .
33
docker-compose up -d --remove-orphans
4-
docker-compose exec pflink pytest .
4+

test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker-compose exec pflink pytest .

tests/test_pfdcm.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,26 @@ def test_get_pfdcm_about(test_app, monkeypatch):
7171

7272
def test_get_pfdcm_cube_list(test_app, monkeypatch):
7373
test_response_payload = {
74-
"data": {
75-
"error": "Unable to reach something else."
76-
},
77-
"message": ""
74+
"detail": "Unable to reach endpoints of something"
7875
}
7976
response = test_app.get("/api/v1/pfdcm/something/cube/list")
80-
assert response.status_code == 200
77+
assert response.status_code == 404
8178
assert response.json() == test_response_payload
8279

8380

8481
def test_get_pfdcm_swift_list(test_app, monkeypatch):
8582
test_response_payload = {
86-
"data": {
87-
"error": "Unable to reach something else."
88-
},
89-
"message": ""
83+
"detail": "Unable to reach endpoints of something"
9084
}
9185
response = test_app.get("/api/v1/pfdcm/something/swift/list")
92-
assert response.status_code == 200
86+
assert response.status_code == 404
9387
assert response.json() == test_response_payload
9488

9589

9690
def test_get_pfdcm_pacs_list(test_app, monkeypatch):
9791
test_response_payload = {
98-
"data": {
99-
"error": "Unable to reach something else."
100-
},
101-
"message": ""
92+
"detail": "Unable to reach endpoints of something"
10293
}
10394
response = test_app.get("/api/v1/pfdcm/something/PACSservice/list")
104-
assert response.status_code == 200
95+
assert response.status_code == 404
10596
assert response.json() == test_response_payload
106-

0 commit comments

Comments
 (0)