Feature : Docker optimization and offline prediction #678
Workflow file for this run
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
| name: Backend Build and Tests | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - develop | |
| paths: | |
| - "backend/**" | |
| - ".github/workflows/backend_build.yml" | |
| pull_request: | |
| branches: | |
| - master | |
| - develop | |
| paths: | |
| - "backend/**" | |
| - ".github/workflows/backend_build.yml" | |
| jobs: | |
| Build_on_ubuntu: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgis/postgis:14-3.2 | |
| env: | |
| # must specify password for PG Docker container image, see: https://registry.hub.docker.com/_/postgres?tab=description&page=1&name=10 | |
| POSTGRES_USER: admin | |
| POSTGRES_PASSWORD: password | |
| POSTGRES_DB: ai | |
| ports: | |
| - 5432:5432 | |
| # needed because the postgres container does not provide a healthcheck | |
| options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 2 | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.8 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.8 | |
| cache: "pip" | |
| - name: Clone Ramp | |
| run: git clone https://github.com/kshitijrajsharma/ramp-code-fAIr.git ramp-code | |
| - name: Install uv | |
| run: pip install uv | |
| - name: Download Basemodel | |
| run: wget https://api-prod.fair.hotosm.org/api/v1/workspace/download/ramp/baseline.zip | |
| - name: Unzip and Move Basemodel | |
| run: unzip baseline.zip -d ramp-code/ramp | |
| - name: Install gdal | |
| run: | | |
| sudo apt-get update && sudo apt-get -y install gdal-bin libgdal-dev python3-gdal && sudo apt-get -y autoremove && sudo apt-get clean | |
| pip install GDAL==$(gdal-config --version) | |
| - name: Install ramp dependecies | |
| run: | | |
| cd ramp-code && cd colab && make install | |
| - name: Install tensorflow | |
| run: pip install tensorflow==2.9.2 | |
| - name: Install fair utilities | |
| run: pip install hot-fair-utilities | |
| - name: Install Psycopg2 | |
| run: | | |
| sudo apt-get install python3-psycopg2 | |
| - name: Install redis | |
| run: | | |
| sudo apt install lsb-release | |
| curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg | |
| echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list | |
| sudo apt-get update | |
| sudo apt-get install redis | |
| redis-cli ping | |
| - name: Install Dependencies | |
| working-directory: ./backend | |
| run: | | |
| uv pip compile --python-version=3.8 pyproject.toml -o requirements.txt --group api --group base-workers --group ramp-workers | |
| pip install --no-cache-dir -r requirements.txt | |
| pip install coverage | |
| pip install factory-boy | |
| - name: Create env | |
| working-directory: ./backend | |
| run: | | |
| export DATABASE_URL=postgis://admin:password@localhost:5432/ai | |
| export RAMP_HOME="/home/runner/work/fAIr/fAIr" | |
| export TRAINING_WORKSPACE="/home/runner/work/fAIr/fAIr/backend/training" | |
| - name: Run celery worker | |
| working-directory: ./backend | |
| run: celery -A aiproject worker --loglevel=debug -Q ramp_training,yolo_training & | |
| - name: Run flower dashboard | |
| working-directory: ./backend | |
| run: celery -A aiproject --broker=redis://localhost:6379/ flower & | |
| - name: Fix gdal array | |
| run: | | |
| pip uninstall -y gdal | |
| pip install numpy | |
| pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-option="-I/usr/include/gdal" | |
| - name: Check Opencv version | |
| run: | | |
| pip freeze | grep opencv | |
| pip install opencv-python-headless==4.7.0.68 | |
| - name: Run migrations | |
| env: | |
| TESTING_TOKEN: ${{ secrets.TESTING_TOKEN }} | |
| OSM_CLIENT_ID: ${{ secrets.OSM_CLIENT_ID }} | |
| OSM_CLIENT_SECRET: ${{ secrets.OSM_CLIENT_SECRET }} | |
| OSM_SECRET_KEY: ${{ secrets.OSM_SECRET_KEY }} | |
| working-directory: ./backend | |
| run: | | |
| python manage.py makemigrations | |
| python manage.py makemigrations core | |
| python manage.py makemigrations login | |
| python manage.py migrate | |
| python manage.py migrate login | |
| python manage.py migrate core | |
| - name: Run tests | |
| env: | |
| TESTING_TOKEN: ${{ secrets.TESTING_TOKEN }} | |
| OSM_CLIENT_ID: ${{ secrets.OSM_CLIENT_ID }} | |
| OSM_CLIENT_SECRET: ${{ secrets.OSM_CLIENT_SECRET }} | |
| OSM_SECRET_KEY: ${{ secrets.OSM_SECRET_KEY }} | |
| working-directory: ./backend | |
| run: coverage run manage.py test tests | |
| # enable coverage report with this : coverage report |