Skip to content

Commit 525937b

Browse files
authored
Merge pull request #133 from openagri-eu/main
Updating agstack main repo with latest stable changes from OpenAgri fork
2 parents 353cb48 + 0c85900 commit 525937b

17 files changed

Lines changed: 1315 additions & 74 deletions

File tree

.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#build
2+
TAG=latest
3+
DOCKER_REGISTRY=openagri-eu
4+
SOURCE_REPO=https://github.com/openagri-eu/openagri-farmcalendar
5+
#
16
POSTGRES_HOST=localhost
27
POSTGRES_DB=farm_calendar
38
POSTGRES_USER=some_user

.github/workflows/docker-image.yml

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker Image CI
1+
name: Docker Multi-Platform Builds
22

33
on:
44
push:
@@ -9,22 +9,21 @@ on:
99
description: 'Branch to run the workflow on'
1010
required: false
1111
release:
12-
types:
13-
- created
14-
12+
types: [ created ]
1513

1614
jobs:
17-
build-and-push:
15+
16+
# -------------------------
17+
# AMD64 Build
18+
# -------------------------
19+
build-amd64:
1820
runs-on: ubuntu-latest
1921
permissions:
2022
contents: read
2123
packages: write
22-
2324
steps:
2425
- name: Checkout code
2526
uses: actions/checkout@v4
26-
with:
27-
fetch-depth: 0 # Saves time by not fetching other branches
2827

2928
- name: Set up Docker Buildx
3029
uses: docker/setup-buildx-action@v3
@@ -36,18 +35,111 @@ jobs:
3635
username: ${{ github.repository_owner }}
3736
password: ${{ secrets.GITHUB_TOKEN }}
3837

39-
- name: Set lowercase repository name
38+
- name: Normalize repo and sanitize ref
4039
run: |
4140
echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
41+
SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
42+
echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
4243
43-
- name: Build and push Docker image
44-
id: docker_build
44+
- name: Build and push AMD64 image
4545
uses: docker/build-push-action@v6
4646
with:
4747
context: .
48+
file: Dockerfile
49+
build-args: SOURCE_REPO=https://github.com/${{ github.repository }}
50+
platforms: linux/amd64
4851
push: true
4952
tags: |
50-
ghcr.io/${{ env.REPO_LOWER }}:${{ github.ref_name }}
51-
${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest', env.REPO_LOWER) || '' }}
53+
ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64
54+
${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-amd64', env.REPO_LOWER) || '' }}
5255
cache-from: type=gha
5356
cache-to: type=gha,mode=max
57+
58+
# -------------------------
59+
# ARM64 Build
60+
# -------------------------
61+
build-arm64:
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
67+
- name: Set up Docker daemon (containerd features)
68+
uses: docker/setup-docker-action@v4
69+
with:
70+
daemon-config: |
71+
{
72+
"debug": true,
73+
"features": { "containerd-snapshotter": true }
74+
}
75+
76+
- name: Set up QEMU
77+
uses: docker/setup-qemu-action@v3
78+
79+
- name: Set up Docker Buildx
80+
uses: docker/setup-buildx-action@v3
81+
82+
- name: Login to GitHub Container Registry
83+
uses: docker/login-action@v3
84+
with:
85+
registry: ghcr.io
86+
username: ${{ github.repository_owner }}
87+
password: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Normalize repo and sanitize ref
90+
run: |
91+
echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
92+
SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
93+
echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
94+
95+
- name: Build and push ARM64 image
96+
uses: docker/build-push-action@v6
97+
with:
98+
context: .
99+
file: Dockerfile
100+
build-args: BUILDKIT_PROGRESS=plain,SOURCE_REPO=https://github.com/${{ github.repository }}
101+
platforms: linux/arm64
102+
push: true
103+
tags: |
104+
ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64
105+
${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-arm64', env.REPO_LOWER) || '' }}
106+
cache-from: type=gha,scope=arm64
107+
cache-to: type=gha,scope=arm64,mode=max
108+
109+
# -------------------------
110+
# Create multi-arch manifest
111+
# -------------------------
112+
manifest:
113+
needs: [ build-amd64, build-arm64 ]
114+
runs-on: ubuntu-latest
115+
steps:
116+
- name: Set up Docker Buildx (for imagetools)
117+
uses: docker/setup-buildx-action@v3
118+
119+
- name: Login to GitHub Container Registry
120+
uses: docker/login-action@v3
121+
with:
122+
registry: ghcr.io
123+
username: ${{ github.repository_owner }}
124+
password: ${{ secrets.GITHUB_TOKEN }}
125+
126+
- name: Normalize repo and sanitize ref
127+
run: |
128+
echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
129+
SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
130+
echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
131+
132+
- name: Create multi-arch manifest for ref tag
133+
run: |
134+
docker buildx imagetools create \
135+
--tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }} \
136+
ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64 \
137+
ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64
138+
139+
- name: Also tag :latest on main
140+
if: ${{ github.ref_name == 'main' }}
141+
run: |
142+
docker buildx imagetools create \
143+
--tag ghcr.io/${{ env.REPO_LOWER }}:latest \
144+
ghcr.io/${{ env.REPO_LOWER }}:latest-amd64 \
145+
ghcr.io/${{ env.REPO_LOWER }}:latest-arm64

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
ARG SOURCE_REPO=https://github.com/openagri-eu/openagri-farmcalendar
12
FROM python:3.12
3+
LABEL org.opencontainers.image.source=${SOURCE_REPO}
24

35
# Set environment variables
46
ENV PYTHONDONTWRITEBYTECODE 1
@@ -33,4 +35,4 @@ COPY . /var/www
3335

3436
# Add the entrypoint script and set the execute permissions
3537
COPY entrypoint.sh /usr/local/bin/
36-
RUN chmod +x /usr/local/bin/entrypoint.sh
38+
RUN chmod +x /usr/local/bin/entrypoint.sh

apis/filters.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
CompostOperation,
2525
AddRawMaterialOperation,
2626
CompostTurningOperation,
27+
AnimalActivity,
28+
AnimalLactatingActivity,
2729
)
2830

2931

@@ -151,3 +153,13 @@ class CompostTurningOperationFilter(BaseCalendarActivityFilter):
151153
class Meta(BaseCalendarActivityFilter.Meta):
152154
model = CompostTurningOperation
153155
fields = ['title', 'activity_type', 'parcel']
156+
157+
class AnimalActivityFilter(BaseCalendarActivityFilter):
158+
class Meta(BaseCalendarActivityFilter.Meta):
159+
model = AnimalActivity
160+
fields = ['title', 'activity_type', 'parcel', 'animal']
161+
162+
class AnimalLactatingActivityFilter(BaseCalendarActivityFilter):
163+
class Meta(BaseCalendarActivityFilter.Meta):
164+
model = AnimalLactatingActivity
165+
fields = ['title', 'activity_type', 'parcel', 'animal']

apis/serializers/base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ def to_internal_value(self, data):
3838
"""
3939
Converts a URN string into a model instance.
4040
"""
41+
if data is None:
42+
return data
4143
if not self.class_name == '{class_name}':
42-
if not isinstance(data, dict) or not data.get('@type', '').lower() == self.class_name.lower() or not data.get('@id', '').startswith(f"{self.urn_prefix}:"):
44+
if not isinstance(data, dict) or '@type' not in data or '@id' not in data:
4345
raise serializers.ValidationError((
4446
f"Invalid URN ref dict format. Expected a dictionary with "
45-
f"@type' as '{self.class_name}' and '@id' with prefix '{self.urn_prefix}:'."
47+
f"@type' (e.g., '{self.class_name}') and '@id' (e.g, with prefix '{self.urn_prefix}:')."
4648
f" Received'{data}' instead."
4749
))
4850
urn_data = data["@id"]
@@ -96,14 +98,16 @@ def to_internal_value(self, data):
9698
"""
9799
Converts a URN string into a model instance.
98100
"""
101+
if data is None:
102+
return data
99103
if isinstance(data, str):
100104
urn_data = data
101105
else:
102106
if not self.class_name == '{class_name}':
103-
if not isinstance(data, dict) or not data.get('@type', '').lower() == self.class_name.lower() or not data.get('@id', '').startswith(f"{self.urn_prefix}:"):
107+
if not isinstance(data, dict) or '@type' not in data or '@id' not in data:
104108
raise serializers.ValidationError((
105109
f"Invalid URN ref dict format. Expected a dictionary with "
106-
f"@type' as '{self.class_name}' and '@id' with prefix '{self.urn_prefix}:'."
110+
f"@type' (e.g., '{self.class_name}') and '@id' (e.g, with prefix '{self.urn_prefix}:')."
107111
f" Received'{data}' instead."
108112
))
109113
urn_data = data["@id"]
@@ -170,4 +174,4 @@ def to_representation(self, instance):
170174
return super().to_representation(instance)
171175
representation = self._prepare_represetation(instance)
172176
json_ld_representation = ClassSchema().dump(representation)
173-
return json_ld_representation
177+
return json_ld_representation

0 commit comments

Comments
 (0)