From 630b687516f1dfe4aa40ca8b98b1af9f26ad6604 Mon Sep 17 00:00:00 2001 From: Simon Kagwi Date: Wed, 22 Jan 2025 19:23:14 +0300 Subject: [PATCH 01/11] Fix errors in the populate_sample_odk_data management command. --- .../management/commands/populate_sample_odk_data.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/odk_publish/management/commands/populate_sample_odk_data.py b/apps/odk_publish/management/commands/populate_sample_odk_data.py index 58bbf56..071bcf8 100644 --- a/apps/odk_publish/management/commands/populate_sample_odk_data.py +++ b/apps/odk_publish/management/commands/populate_sample_odk_data.py @@ -33,12 +33,12 @@ def handle(self, *args, **options): logger.info("Creating Projects...") project = odk_publish.Project.objects.create( name="Caktus Test", - project_id=1, + central_id=1, central_server=central_server, ) odk_publish.Project.objects.create( name="Other Project", - project_id=5, + central_id=5, central_server=myodkcloud, ) logger.info("Creating TemplateVariable...") @@ -61,6 +61,7 @@ def handle(self, *args, **options): app_user = odk_publish.AppUser.objects.create( name=center_id, project=project, + central_id=1, ) odk_publish.AppUserTemplateVariable.objects.create( app_user=app_user, template_variable=center_id_var, value=center_id From 95fc88508e19fff7ecf8bd166a4aca214a5be2cf Mon Sep 17 00:00:00 2001 From: Simon Kagwi Date: Wed, 22 Jan 2025 19:24:39 +0300 Subject: [PATCH 02/11] Fix docker build errors due to non-existent folders. --- Dockerfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7f51a3b..1439818 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,8 @@ RUN npm install --silent COPY config/assets config/assets COPY config/static config/static # Every template dir using Tailwind must be added below -COPY apps/eportal/templates apps/eportal/templates -COPY apps/inventory/templates apps/inventory/templates -COPY apps/inventory_materials/templates apps/inventory_materials/templates -COPY apps/portal_patterns/templates apps/portal_patterns/templates +COPY config/templates config/templates +COPY apps/patterns/templates apps/patterns/templates RUN npm run build FROM python:3.11-slim-bookworm as base From cc22a3196fcfcc9058dc85ecab49f40a455e06be Mon Sep 17 00:00:00 2001 From: Simon Kagwi Date: Wed, 22 Jan 2025 19:26:09 +0300 Subject: [PATCH 03/11] Fix "Package 'pyodk' requires a different Python: 3.11.11 not in '>=3.12'" --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1439818..bec6f37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ COPY config/templates config/templates COPY apps/patterns/templates apps/patterns/templates RUN npm run build -FROM python:3.11-slim-bookworm as base +FROM python:3.12-slim-bookworm as base # Install packages needed to run your application (not build deps): # mime-support -- for mime types when serving static files From 2c1bcbf67b57a5805fd4fc8f8b023ab5f7b09105 Mon Sep 17 00:00:00 2001 From: Simon Kagwi Date: Wed, 22 Jan 2025 19:57:23 +0300 Subject: [PATCH 04/11] Add a workflow for publishing an image to GHCR. --- .github/workflows/docker-publish.yml | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..f845f44 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,53 @@ +name: Docker + +on: + push: + branches: [master, deploy] # FIXME: Remove deploy, only temporary for testing + # Publish semver tags as releases. + tags: ["v*.*.*"] + # FIXME: Remove workflow_dispatch. Only temporary for testing with manual deploys via the GitHub Actions Web UI + workflow_dispatch: + +env: + REGISTRY: ghcr.io + REGISTRY_WITH_PATH: ghcr.io/${{ github.repository_owner }} + +jobs: + build-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_WITH_PATH }}/odk-publish + # Generate Docker tags based on the following events/attributes + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}}.{{hotfix}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 6e86a24f6efd252cf467f98da3c38616388d8d25 Mon Sep 17 00:00:00 2001 From: Simon Kagwi Date: Wed, 22 Jan 2025 20:26:36 +0300 Subject: [PATCH 05/11] Remove copying of config/static in the Dockerfile. --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bec6f37..a846eeb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ ENV PATH /code/node_modules/.bin:$PATH COPY package.json package-lock.json tailwind.config.js postcss.config.js /code/ RUN npm install --silent COPY config/assets config/assets -COPY config/static config/static # Every template dir using Tailwind must be added below COPY config/templates config/templates COPY apps/patterns/templates apps/patterns/templates From df58a30aa5057a1a1358c640c68ef38452bc0caf Mon Sep 17 00:00:00 2001 From: Simon Kagwi Date: Wed, 22 Jan 2025 22:50:36 +0300 Subject: [PATCH 06/11] Fix "Missing staticfiles manifest entry for 'favicon.ico'" when DEBUG = False. --- config/templates/base.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/templates/base.html b/config/templates/base.html index 4b8c110..974efc1 100644 --- a/config/templates/base.html +++ b/config/templates/base.html @@ -14,9 +14,9 @@ {# favicon #} - + {% comment "FIXME: Uncomment when the favicon file is added. Currently causing an error when DEBUG=False" %} + + {% endcomment %} {% block title %} ODK Publish From 091f03a10e4da3ea6768fc362ccce76bf4710fe2 Mon Sep 17 00:00:00 2001 From: Simon Kagwi <skagwi@caktusgroup.com> Date: Mon, 27 Jan 2025 22:23:16 +0300 Subject: [PATCH 07/11] Add a default cache path for pyodk. --- apps/odk_publish/etl/odk/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/odk_publish/etl/odk/client.py b/apps/odk_publish/etl/odk/client.py index 69b6242..9513f8d 100644 --- a/apps/odk_publish/etl/odk/client.py +++ b/apps/odk_publish/etl/odk/client.py @@ -49,7 +49,7 @@ def __init__(self, base_url: str, project_id: int | None = None): api_version="v1", username=server_config.username, password=server_config.password.get_secret_value(), - cache_path=None, + cache_path="/tmp/.pyodk_cache.toml", ) super().__init__(config_path=str(config_path), session=session, project_id=project_id) # Update the stub config with the environment-provided authentication From c53ddad63790047cd206231acb1c672088910931 Mon Sep 17 00:00:00 2001 From: Simon Kagwi <skagwi@caktusgroup.com> Date: Tue, 28 Jan 2025 01:03:04 +0300 Subject: [PATCH 08/11] Make the ADMINS setting configurable. --- config/settings/deploy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/settings/deploy.py b/config/settings/deploy.py index c8608a8..3dde2be 100644 --- a/config/settings/deploy.py +++ b/config/settings/deploy.py @@ -9,7 +9,8 @@ ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "localhost").split(":") ### ADMINS and MANAGERS -ADMINS = (("Caktus Team", "team@caktusgroup.com"),) +ADMIN_EMAIL = os.getenv("ADMIN_EMAIL") +ADMINS = (("Admin", ADMIN_EMAIL),) # STATIC # ------------------------------------------------------------------------------ From 2c70d0c6b46e5d8f331c175836299eaf04c7291b Mon Sep 17 00:00:00 2001 From: Simon Kagwi <skagwi@caktusgroup.com> Date: Tue, 28 Jan 2025 19:57:45 +0300 Subject: [PATCH 09/11] Fix error creating QR codes. --- apps/odk_publish/etl/load.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/odk_publish/etl/load.py b/apps/odk_publish/etl/load.py index fa4d096..6f1d8cc 100644 --- a/apps/odk_publish/etl/load.py +++ b/apps/odk_publish/etl/load.py @@ -45,7 +45,7 @@ def generate_and_save_app_user_collect_qrcodes(project: Project): image = create_app_user_qrcode( app_user=central_app_users[app_user.name], base_url=client.session.base_url, - central_id=project.central_id, + project_id=project.central_id, project_name_prefix=project.name, ) app_user.qr_code.save( From 0162dc65175b842dc3caf12c1f5c489686a66b88 Mon Sep 17 00:00:00 2001 From: Simon Kagwi <skagwi@caktusgroup.com> Date: Tue, 28 Jan 2025 20:26:56 +0300 Subject: [PATCH 10/11] Create the cache file if it does not exist. --- apps/odk_publish/etl/odk/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/odk_publish/etl/odk/client.py b/apps/odk_publish/etl/odk/client.py index 9513f8d..4d95c09 100644 --- a/apps/odk_publish/etl/odk/client.py +++ b/apps/odk_publish/etl/odk/client.py @@ -41,6 +41,10 @@ def __init__(self, base_url: str, project_id: int | None = None): config_path = Path("/tmp/.pyodk_config.toml") if not config_path.exists(): config_path.write_text(CONFIG_TOML) + # Create stub cache file if it doesn't exist, so that pyodk doesn't complain + cache_path = Path("/tmp/.pyodk_cache.toml") + if not cache_path.exists(): + cache_path.write_text('token = ""') # Create a session with the given authentication details and supply the # session to the super class, so it doesn't try and create one itself server_config = self.get_config(base_url=base_url) @@ -49,7 +53,7 @@ def __init__(self, base_url: str, project_id: int | None = None): api_version="v1", username=server_config.username, password=server_config.password.get_secret_value(), - cache_path="/tmp/.pyodk_cache.toml", + cache_path=str(cache_path), ) super().__init__(config_path=str(config_path), session=session, project_id=project_id) # Update the stub config with the environment-provided authentication From 778f3f0d85539a9ca26fd9af3ca8603d4d39af79 Mon Sep 17 00:00:00 2001 From: Simon Kagwi <skagwi@caktusgroup.com> Date: Wed, 29 Jan 2025 20:56:29 +0300 Subject: [PATCH 11/11] Remove GA workflow changes meant for testing. --- .github/workflows/docker-publish.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index f845f44..85aa624 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -2,11 +2,9 @@ name: Docker on: push: - branches: [master, deploy] # FIXME: Remove deploy, only temporary for testing + branches: [master] # Publish semver tags as releases. tags: ["v*.*.*"] - # FIXME: Remove workflow_dispatch. Only temporary for testing with manual deploys via the GitHub Actions Web UI - workflow_dispatch: env: REGISTRY: ghcr.io