Skip to content

Commit 8a6c113

Browse files
SRTP-769-implement-api-send-gpd-message
1 parent d6dc6a3 commit 8a6c113

File tree

8 files changed

+153
-18
lines changed

8 files changed

+153
-18
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build & Push Docker image to GHCR
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
jobs:
8+
build-and-push:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
packages: write
12+
contents: read
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Log in to GitHub Container Registry
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Build and push Docker image
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: .
29+
file: gpd-test/Dockerfile
30+
push: true
31+
tags: ghcr.io/${{ github.repository_owner }}/gpd-test:latest

gpd-test/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.13-slim
2+
3+
WORKDIR /app
4+
5+
# Copy only gpd-test
6+
COPY gpd-test/ /app/
7+
8+
# Install dependecies
9+
COPY ../requirements.txt /app/
10+
RUN pip install --no-cache-dir -r requirements.txt
11+
12+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

gpd-test/deploy/deploy-dev.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: gpd-producer-sa
5+
namespace: srtp
6+
annotations:
7+
azure.workload.identity/client-id: <CLIENT_ID_WORKLOAD_IDENTITY>
8+
---
9+
apiVersion: apps/v1
10+
kind: Deployment
11+
metadata:
12+
name: gpd-producer-dev
13+
namespace: srtp
14+
spec:
15+
replicas: 1
16+
selector:
17+
matchLabels:
18+
app: gpd-producer-dev
19+
template:
20+
metadata:
21+
labels:
22+
app: gpd-producer-dev
23+
spec:
24+
serviceAccountName: gpd-producer-sa
25+
containers:
26+
- name: gpd-producer
27+
image: ghcr.io/__OWNER__/gpd-test:latest
28+
ports:
29+
- containerPort: 8000
30+
env:
31+
- name: KEYVAULT_NAME
32+
value: cstar-d-itn-srtp-kv
33+
- name: EVENTHUB_SECRET_NAME
34+
value: gdp-eventhub-connection-string
35+
- name: EVENTHUB_NAMESPACE
36+
value: pagopa-d-itn-gps-rtp-integration-evh
37+
- name: EVENTHUB_TOPIC
38+
value: rtp-events

gpd-test/deploy/deploy-uat.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: gpd-producer-sa
5+
namespace: srtp
6+
annotations:
7+
azure.workload.identity/client-id: <CLIENT_ID_WORKLOAD_IDENTITY>
8+
---
9+
apiVersion: apps/v1
10+
kind: Deployment
11+
metadata:
12+
name: gpd-producer-uat
13+
namespace: srtp
14+
spec:
15+
replicas: 1
16+
selector:
17+
matchLabels:
18+
app: gpd-producer-uat
19+
template:
20+
metadata:
21+
labels:
22+
app: gpd-producer-uat
23+
spec:
24+
serviceAccountName: gpd-producer-sa
25+
containers:
26+
- name: gpd-producer
27+
image: ghcr.io/__OWNER__/gpd-test:latest
28+
ports:
29+
- containerPort: 8000
30+
env:
31+
- name: KEYVAULT_NAME
32+
value: cstar-u-itn-srtp-kv
33+
- name: EVENTHUB_SECRET_NAME
34+
value: gdp-eventhub-connection-string
35+
- name: EVENTHUB_NAMESPACE
36+
value: pagopa-u-itn-gps-rtp-integration-evh
37+
- name: EVENTHUB_TOPIC
38+
value: rtp-events

gpd-test/deploy/deploy.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
OWNER=$(git config --get remote.origin.url | sed -E 's|.*github.com[:/](.*)/.*|\1|' | cut -d/ -f1)
4+
5+
if [[ $# -ne 1 ]]; then
6+
echo "Usage: $0 <deployment-file.yaml>"
7+
exit 1
8+
fi
9+
10+
FILE="$1"
11+
12+
echo "Deploying $FILE with GHCR owner: $OWNER"
13+
sed "s|__OWNER__|$OWNER|g" "$FILE" | kubectl apply -n srtp -f -

gpd-test/keyvault.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# from azure.identity import AzureCliCredential
2-
# from azure.keyvault.secrets import SecretClient
3-
# import os
4-
#
5-
# def get_eventhub_connection_string():
6-
# keyvault_name = os.environ["KEYVAULT_NAME"]
7-
# secret_name = os.environ["EVENTHUB_SECRET_NAME"]
8-
#
9-
# keyvault_url = f"https://{keyvault_name}.vault.azure.net"
10-
# credential = AzureCliCredential()
11-
# client = SecretClient(vault_url=keyvault_url, credential=credential)
12-
#
13-
# secret = client.get_secret(secret_name)
14-
# print(f"[KeyVault] Retrieved secret '{secret_name}' from '{keyvault_name}'")
15-
# return secret.value
1+
from azure.identity import AzureCliCredential
2+
from azure.keyvault.secrets import SecretClient
3+
import os
4+
5+
def get_eventhub_connection_string():
6+
keyvault_name = os.environ["KEYVAULT_NAME"]
7+
secret_name = os.environ["EVENTHUB_SECRET_NAME"]
8+
9+
keyvault_url = f"https://{keyvault_name}.vault.azure.net"
10+
credential = AzureCliCredential()
11+
client = SecretClient(vault_url=keyvault_url, credential=credential)
12+
13+
secret = client.get_secret(secret_name)
14+
print(f"[KeyVault] Retrieved secret '{secret_name}' from '{keyvault_name}'")
15+
return secret.value
1616

1717
from azure.identity import DefaultAzureCredential
1818
from azure.keyvault.secrets import SecretClient

gpd-test/producer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from aiokafka import AIOKafkaProducer
2-
import os, ssl
2+
import os
3+
import ssl
4+
import certifi
35
from keyvault import get_eventhub_connection_string
46

57
async def setup_producer():
68
connection_string = get_eventhub_connection_string()
79
namespace = os.environ["EVENTHUB_NAMESPACE"]
810

9-
ssl_context = ssl.create_default_context()
11+
ssl_context = ssl.create_default_context(cafile=certifi.where())
1012
ssl_context.check_hostname = True
1113
ssl_context.verify_mode = ssl.CERT_REQUIRED
1214

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ pytest~=8.4.1
1414
fastapi~=0.116.1
1515
aiokafka~=0.12.0
1616
keyvault~=0.2.1
17-
azure-core~=1.35.0
17+
azure-core~=1.35.0
18+
certifi~=2025.7.14

0 commit comments

Comments
 (0)