Search code examples
djangodockergdalgeodjangocircleci

Django, GDAL and CircleCI 2


I have a Django app configured with GeoDjango that is failing on CircleCI 2.0 builds with the following error:

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library. Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

However, when I remove 'django.contrib.gis' from DJANGO_APPS in settings.py the build runs successfully.

Are there additional steps for configuring GDAL in CircleCI outside of the postgres and GDAL docker images? I (perhaps incorrectly) assumed that GDAL would be found after the docker image was installed. Below is my config.yml:

version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.6.3

      - image: circleci/postgres:10.1-postgis
        environment:
        - POSTGRES_USER=ubuntu
        - POSTGRES_DB=myapp_test

      - image: geodata/gdal

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "requirements.txt" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt
      - save_cache:
          paths:
            - ./venv
          key: v1-dependencies-{{ checksum "requirements.txt" }}

      - run:
          name: run tests
          command: |
            . venv/bin/activate
            python manage.py test
          environment:
            DATABASE_URL: "postgres://ubuntu@localhost:5432/myapp_test"

      - store_artifacts:
          path: test-reports
          destination: test-reports

Solution

  • I fixed it by adding the following:

    apt-get update && apt-get install -y \
    gdal-bin python-gdal python3-gdal
    

    right where you run pip install:

      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt
            apt-get update && apt-get install -y \
            gdal-bin python-gdal python3-gdal