Workflow/push to dokku#164
Open
gideonmaina wants to merge 30 commits into
Open
Conversation
Reads and bumps from VERSION file for prod deploy
Cleaner than reading VERSION file. TODO: update to accomadate major version releases
Resolves Celery 4.3.0 package dependency
View had missing ViewSet section
- Makes test database configurable via SENSORSAFRICA_TEST_DATABASE_URL env var, defaulting to SQLite - Adds pytest_collection_modifyitems hook to auto-skip @pytest.mark.postgres_only tests on SQLite - Registers the postgres_only marker in pytest.ini - Updates v2 tests to authenticate via token and use correct /v2/data/stats/air/ URLs - Marks deprecated v1 tests (test_filter_view, test_sensordata_view, test_sensor_view) as skipped - Marks PostgreSQL-dependent stats tests as @pytest.mark.postgres_only - Fixes bulk_create re-fetch for SQLite (which doesn't return PKs in Django 1.11)
…properlyConfigured
VinneyJ
reviewed
Jul 8, 2026
| DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
| DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} | ||
| run: | |
There was a problem hiding this comment.
Is this a bit too much for a build-and-push job? Would a simpler structure like this be easier to maintain?
needs: test
runs-on: ubuntu-22.04
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGE_NAME }}
- name: Build and push image
uses: docker/build-push-action@v7
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #161 — Adds a fully automated GitHub Actions CI/CD pipeline for testing, Docker image building, and Dokku deployment (staging + production) for
sensors.AFRICA-api.Workflow Architecture
graph TD PR[Pull Request → master] --> Test[🧪 Test<br/>Python 3.7 / pytest<br/>PostgreSQL service] Test --> Build[🐳 Build & Push<br/>Docker Hub<br/>semver auto-versioning] Build --> DeployStaging[🚀 Deploy Staging<br/>Dokku git:from-image] DeployStaging --> Integration[🔍 Integration Tests<br/>against staging] Push[Push → master] --> Test2[🧪 Test] Test2 --> Build2[🐳 Build & Push] Build2 --> DeployProd[🚀 Deploy Production<br/>Dokku git:from-image]test→build-and-push→deploy-staging→integration-teststest→build-and-push→deploy-productionType of change
Checklist:
Key Features
Docker Image Versioning
v0.1.0→v0.1.1)beta-pr-{N}-{sha}andpr-{N}tags; master builds getv{version}andlatestDatabase Compatibility (Test Job)
@pytest.mark.postgres_only) are auto-skipped on SQLite via apytest_collection_modifyitemshookSENSORSAFRICA_TEST_DATABASE_URLto run the full PostgreSQL suite when neededInstallation Cleanup
Dependencies that were scattered across manual
pip installsteps in the workflow are now consolidated inrequirements.txt, with upgraded versions for Python 3.7 binary wheel compatibility (gevent==1.4.0,greenlet==0.4.17).feinstaubis the only package installed separately (--no-deps) due to its brokenopbeatdependency.Code Changes
.github/workflows/deploy.ymlrequirements.txtsensorsafrica/tests/conftest.pypytest_collection_modifyitemshookImproperlyConfiguredduring collection; auto-skip PG-only tests on SQLitesensorsafrica/tests/settings.pysensorsafrica/tests/test_*.pysensorsafrica/management/commands/cache_lastactive_nodes.pyINTERVALsyntax broke on SQLitepytest.iniDJANGO_SETTINGS_MODULEandpostgres_onlymarkerTesting
Local Simulation
act(nektos) was used to simulate GitHub Actions runs locally during development, catching issues before pushing to CI.Fork CI
The full workflow was tested end-to-end on a fork:
https://github.com/gideonmaina/sensors.AFRICA-api/actions — with automatic Docker image creation, versioning, and Dokku deployment.
Staging & Production Demo
Both staging and production were deployed to the same Dokku host (sensors-dev) using different app names to demonstrate the full workflow:
sensorsafrica-stagingsensorsafrica-prod-deploy-testPrerequisites
Before this workflow will run in the upstream repo, configure these:
Repository Secrets
Settings → Secrets and variables → Actions → New repository secretDOCKERHUB_USERNAMEDOCKERHUB_TOKENDOCKERHUB_REPOSITORYorg/sensors-africaDOKKU_SSH_STAGING_PRIVATE_KEYDOKKU_SSH_PRIVATE_KEYSTAGING_DOKKU_HOSTSTAGING_APP_NAMEsensorsafrica-staging)PRODUCTION_DOKKU_HOSTPRODUCTION_APP_NAMESSH Keys on Dokku Servers
The public key corresponding to each private key must be added to the Dokku host:
Dokku Apps
Create the apps on each Dokku host (or let the workflow auto-create them with
dokku apps:create):