Skip to content

Commit 902a13c

Browse files
authored
Upgrade Python 3.12 (#2)
1 parent 8d4a064 commit 902a13c

File tree

5 files changed

+178
-99
lines changed

5 files changed

+178
-99
lines changed

.github/workflows/ndc-python-lambda-connector.yaml

Lines changed: 147 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- test-ci/**
77
push:
88
branches:
9-
- 'main'
9+
- "main"
1010
- test-ci/**
1111
tags:
1212
- v**
@@ -21,9 +21,9 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- uses: actions/checkout@v4
24-
- uses: actions/setup-python@v4
24+
- uses: actions/setup-python@v5
2525
with:
26-
python-version: '3.9'
26+
python-version: "3.12"
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
@@ -45,10 +45,10 @@ jobs:
4545
steps:
4646
- uses: actions/checkout@v4
4747
with:
48-
fetch-depth: 0 # This is important for git describe to work correctly
49-
- uses: actions/setup-python@v4
48+
fetch-depth: 0 # This is important for git describe to work correctly
49+
- uses: actions/setup-python@v5
5050
with:
51-
python-version: '3.9'
51+
python-version: "3.12"
5252
- name: Build connector
5353
run: |
5454
cd connector-definition
@@ -60,7 +60,7 @@ jobs:
6060
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
6161
- name: Get commit hash
6262
id: get_commit_hash
63-
run: |
63+
run: |
6464
COMMIT_HASH=$(git rev-parse HEAD)
6565
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
6666
- name: Debug information
@@ -82,30 +82,83 @@ jobs:
8282
if: startsWith(github.ref, 'refs/tags/v')
8383
steps:
8484
- uses: actions/checkout@v4
85+
86+
- name: Set up containerd
87+
uses: crazy-max/ghaction-setup-containerd@v3
88+
89+
- name: Fix containerd socket permissions
90+
run: |
91+
sudo chgrp docker /run/containerd/containerd.sock
92+
8593
- name: Set up QEMU
86-
uses: docker/setup-qemu-action@v2
94+
uses: docker/setup-qemu-action@v3
95+
8796
- name: Set up Docker Buildx
8897
uses: docker/setup-buildx-action@v3
98+
8999
- name: Login to GitHub Container Registry
90100
uses: docker/login-action@v3
91101
with:
92-
registry: ${{ env.DOCKER_REGISTRY }}
93-
username: ${{ github.actor }}
94-
password: ${{ secrets.GITHUB_TOKEN }}
102+
registry: ${{ env.DOCKER_REGISTRY }}
103+
username: ${{ github.actor }}
104+
password: ${{ secrets.GITHUB_TOKEN }}
105+
95106
- name: Extract metadata (tags, labels) for Docker
96107
id: docker-metadata
97108
uses: docker/metadata-action@v5
98109
with:
99-
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}
100-
- name: Build and push Docker image
101-
uses: docker/build-push-action@v5
110+
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}
111+
112+
- name: Build Docker image
113+
uses: docker/build-push-action@v6
114+
with:
115+
context: .
116+
push: false
117+
platforms: linux/amd64,linux/arm64
118+
tags: ${{ steps.docker-metadata.outputs.tags }}
119+
labels: ${{ steps.docker-metadata.outputs.labels }}
120+
# Export the image to a tar so it can be imported into containerd so gokakashi can scan it
121+
outputs: type=oci,dest=/tmp/image.tar
122+
123+
- name: Import docker image into containerd store
124+
run: |
125+
ctr images import --base-name ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }} --digests --all-platforms /tmp/image.tar
126+
127+
- name: Get first docker tag for gokakashi
128+
id: first-docker-tag
129+
run: |
130+
FIRST_TAG=$(echo "${{ steps.docker-metadata.outputs.tags }}" | head -n 1)
131+
echo "First docker tag: $FIRST_TAG"
132+
echo "tag=$FIRST_TAG" >> $GITHUB_OUTPUT
133+
134+
- name: Scan docker image with gokakashi
135+
uses: shinobistack/[email protected]
136+
with:
137+
image: ${{ steps.first-docker-tag.outputs.tag }}
138+
labels: agentKey=${{ github.run_id }}
139+
policy: ci-platform
140+
server: https://gokakashi-server.hasura-app.io
141+
token: ${{ secrets.GOKAKASHI_API_TOKEN }}
142+
cf_client_id: ${{ secrets.CF_ACCESS_CLIENT_ID }}
143+
cf_client_secret: ${{ secrets.CF_ACCESS_CLIENT_SECRET }}
144+
interval: 10
145+
retries: 8
146+
147+
- name: Upload Trivy report as artifact
148+
uses: actions/upload-artifact@v4
149+
with:
150+
name: trivy-report
151+
path: /tmp/trivy-report-*.json
152+
153+
- name: Push Docker image
154+
uses: docker/build-push-action@v6
102155
with:
103-
context: .
104-
push: true
105-
platforms: linux/amd64,linux/arm64
106-
tags: ${{ steps.docker-metadata.outputs.tags }}
107-
labels: ${{ steps.docker-metadata.outputs.labels }}
108-
156+
context: .
157+
push: true
158+
platforms: linux/amd64,linux/arm64
159+
tags: ${{ steps.docker-metadata.outputs.tags }}
160+
labels: ${{ steps.docker-metadata.outputs.labels }}
161+
109162
release-connector:
110163
name: Release connector
111164
runs-on: ubuntu-latest
@@ -126,11 +179,13 @@ jobs:
126179
run: |
127180
echo "tagged_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
128181
shell: bash
182+
129183
- uses: mindsers/changelog-reader-action@v2
130184
id: changelog-reader
131185
with:
132186
version: ${{ steps.get-version.outputs.tagged_version }}
133187
path: ./CHANGELOG.md
188+
134189
- uses: softprops/action-gh-release@v1
135190
with:
136191
draft: false
@@ -142,75 +197,76 @@ jobs:
142197

143198
- name: Update ndc-hub
144199
env:
145-
REGISTRY_NAME: hasura
146-
CONNECTOR_NAME: ndc-python-lambda
147-
COMMIT_HASH: ${{ needs.build-connector.outputs.commit_hash }}
148-
SHA256: ${{ needs.build-connector.outputs.sha256 }}
149-
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
200+
REGISTRY_NAME: hasura
201+
CONNECTOR_NAME: ndc-python-lambda
202+
COMMIT_HASH: ${{ needs.build-connector.outputs.commit_hash }}
203+
SHA256: ${{ needs.build-connector.outputs.sha256 }}
204+
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
150205
run: |
151-
# Clone ndc-hub repository
152-
git clone https://github.com/hasura/ndc-hub.git
153-
cd ndc-hub
154-
155-
# Create a new branch
156-
NEW_BRANCH="update-${{ env.CONNECTOR_NAME }}-connector-v${{ steps.get-version.outputs.tagged_version }}"
157-
git checkout -b $NEW_BRANCH
158-
159-
cd registry/${{ env.REGISTRY_NAME }}/python
160-
161-
# Create releases directory if it doesn't exist
162-
mkdir -p releases/v${{ steps.get-version.outputs.tagged_version }}
163-
164-
# Create connector-packaging.json
165-
cat << EOF > releases/v${{ steps.get-version.outputs.tagged_version }}/connector-packaging.json
166-
{
167-
"version": "v${{ steps.get-version.outputs.tagged_version }}",
168-
"uri": "https://github.com/${{ github.repository }}/releases/download/v${{ steps.get-version.outputs.tagged_version }}/connector-definition.tgz",
169-
"checksum": {
170-
"type": "sha256",
171-
"value": "$SHA256"
172-
},
173-
"source": {
174-
"hash": "$COMMIT_HASH"
175-
}
176-
}
177-
EOF
178-
179-
# Update metadata.json to remove 'packages' field if it exists and update 'latest_version'
180-
jq --arg version_tag "v${{ steps.get-version.outputs.tagged_version }}" \
181-
--arg commit_hash "$COMMIT_HASH" \
182-
'if has("packages") then del(.packages) else . end |
183-
.overview.latest_version = $version_tag |
184-
if has("source_code") then
185-
.source_code.version += [{
186-
"tag": $version_tag,
187-
"hash": $commit_hash,
188-
"is_verified": false
189-
}]
190-
else
191-
. + {"source_code": {"version": [{
192-
"tag": $version_tag,
193-
"hash": $commit_hash,
194-
"is_verified": false
195-
}]}}
196-
end' \
197-
metadata.json > tmp.json && mv tmp.json metadata.json
198-
199-
cp ../../../../README.md ./README.md
200-
201-
# Commit changes
202-
git config user.name "GitHub Action"
203-
git config user.email "[email protected]"
204-
git add metadata.json README.md releases
205-
git commit -m "Update ${{ env.CONNECTOR_NAME }} connector metadata to version ${{ steps.get-version.outputs.tagged_version }}"
206-
207-
# Push changes
208-
git push https://${{ secrets.PAT_TOKEN }}@github.com/hasura/ndc-hub.git HEAD:$NEW_BRANCH
209-
210-
# Create PR using GitHub CLI
211-
cd ../..
212-
gh pr create --repo hasura/ndc-hub \
213-
--base main \
214-
--head $NEW_BRANCH \
215-
--title "Update ${{ env.CONNECTOR_NAME }} connector to v${{ steps.get-version.outputs.tagged_version }}" \
216-
--body "This PR updates the ${{ env.CONNECTOR_NAME }} connector metadata to version ${{ steps.get-version.outputs.tagged_version }}."
206+
# Clone ndc-hub repository
207+
git clone https://github.com/hasura/ndc-hub.git
208+
cd ndc-hub
209+
210+
# Create a new branch
211+
NEW_BRANCH="update-${{ env.CONNECTOR_NAME }}-connector-v${{ steps.get-version.outputs.tagged_version }}"
212+
git checkout -b $NEW_BRANCH
213+
214+
cd registry/${{ env.REGISTRY_NAME }}/python
215+
216+
# Create releases directory if it doesn't exist
217+
mkdir -p releases/v${{ steps.get-version.outputs.tagged_version }}
218+
219+
# Create connector-packaging.json
220+
cat << EOF > releases/v${{ steps.get-version.outputs.tagged_version }}/connector-packaging.json
221+
{
222+
"version": "v${{ steps.get-version.outputs.tagged_version }}",
223+
"uri": "https://github.com/${{ github.repository }}/releases/download/v${{ steps.get-version.outputs.tagged_version }}/connector-definition.tgz",
224+
"checksum": {
225+
"type": "sha256",
226+
"value": "$SHA256"
227+
},
228+
"source": {
229+
"hash": "$COMMIT_HASH"
230+
},
231+
"test": {
232+
"test_config_path": "../../tests/test-config.json"
233+
}
234+
}
235+
EOF
236+
237+
# Update metadata.json to remove 'packages' field if it exists and update 'latest_version'
238+
jq --arg version_tag "v${{ steps.get-version.outputs.tagged_version }}" \
239+
--arg commit_hash "$COMMIT_HASH" \
240+
'if has("packages") then del(.packages) else . end |
241+
.overview.latest_version = $version_tag |
242+
if has("source_code") then
243+
.source_code.version += [{
244+
"tag": $version_tag,
245+
"hash": $commit_hash,
246+
"is_verified": false
247+
}]
248+
else
249+
. + {"source_code": {"version": [{
250+
"tag": $version_tag,
251+
"hash": $commit_hash,
252+
"is_verified": false
253+
}]}}
254+
end' \
255+
metadata.json > tmp.json && mv tmp.json metadata.json
256+
257+
# Commit changes
258+
git config user.name "GitHub Action"
259+
git config user.email "[email protected]"
260+
git add metadata.json README.md releases
261+
git commit -m "Update ${{ env.CONNECTOR_NAME }} connector metadata to version ${{ steps.get-version.outputs.tagged_version }}"
262+
263+
# Push changes
264+
git push https://${{ secrets.PAT_TOKEN }}@github.com/hasura/ndc-hub.git HEAD:$NEW_BRANCH
265+
266+
# Create PR using GitHub CLI
267+
cd ../..
268+
gh pr create --repo hasura/ndc-hub \
269+
--base main \
270+
--head $NEW_BRANCH \
271+
--title "Update ${{ env.CONNECTOR_NAME }} connector to v${{ steps.get-version.outputs.tagged_version }}" \
272+
--body "This PR updates the ${{ env.CONNECTOR_NAME }} connector metadata to version ${{ steps.get-version.outputs.tagged_version }}."

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This changelog documents the changes between release versions.
44
## [Unreleased]
55
Changes to be included in the next upcoming release
66

7+
## [0.2.0] - 2025-04-02
8+
* Upgrade Python 3.12
9+
* Use `python:3.12-slim` image tag with non-root user.
10+
711
## [0.1.6] - 2025-01-22
812
* Fix workflows
913

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
FROM python:3.10
1+
FROM python:3.12-slim
22

33
# Install curl for healthcheck
4-
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
4+
RUN apt-get update && \
5+
apt-get install -y curl git && \
6+
rm -rf /var/lib/apt/lists/*
57

68
COPY /docker /scripts
79
COPY /functions /functions

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Hasura Python Lambda Connector
2+
23
<a href="https://www.python.org/"><img src="https://github.com/hasura/ndc-python-lambda/blob/main/docs/logo.svg" align="right" width="200"></a>
34

45
[![Docs](https://img.shields.io/badge/docs-v3.x-brightgreen.svg?style=flat)](https://hasura.io/connectors/python)
@@ -21,6 +22,7 @@ This connector is built using the [Python Data Connector SDK](https://github.com
2122
1. The [DDN CLI](https://hasura.io/docs/3.0/cli/installation) and [Docker](https://docs.docker.com/engine/install/) installed
2223
2. A [supergraph](https://hasura.io/docs/3.0/getting-started/init-supergraph)
2324
3. A [subgraph](https://hasura.io/docs/3.0/getting-started/init-subgraph)
25+
4. Python 3.12
2426

2527
The steps below explain how to Initialize and configure a connector for local development. You can learn how to deploy a connector — after it's been configured — [here](https://hasura.io/docs/3.0/getting-started/deployment/deploy-a-connector).
2628

@@ -56,7 +58,7 @@ ddn connector introspect python
5658

5759
### Step 4: Add your resources
5860

59-
You can add the models, commands, and relationships to your API by tracking them which generates the HML files.
61+
You can add the models, commands, and relationships to your API by tracking them which generates the HML files.
6062

6163
```bash
6264
ddn connector-link add-resources python
@@ -79,15 +81,21 @@ include:
7981
8082
To run your connector outside of Docker first go into the connector directory:
8183
82-
`cd app/connector/python`
84+
```bash
85+
cd app/connector/python
86+
```
8387

8488
Install the requirements:
8589

86-
`pip3 install -r requirements.txt`
90+
```bash
91+
pip3 install -r requirements.txt`
92+
```
8793

8894
Then run the connector locally:
8995

90-
```ddn connector setenv --connector connector.yaml -- python3 functions.py serve```
96+
```bash
97+
ddn connector setenv --connector connector.yaml -- python3 functions.py serve
98+
```
9199

92100
## Documentation
93101

@@ -99,4 +107,4 @@ Check out our [contributing guide](https://github.com/hasura/ndc-python-lambda/b
99107

100108
## License
101109

102-
The Turso connector is available under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
110+
The Turso connector is available under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).

0 commit comments

Comments
 (0)