skip to Main Content

I’m trying to build a CI/CD pipeline for my flask app in Azure using Github Actions.

I have been able to build the workflows, however, when running the tests (using pytest),
I’m getting the error

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 18 for SQL Server' : file not found (0) (SQLDriverConnect)")

It seems that is due to the missing odbc driver on the Ubuntu VM/container used by GitHub actions to run the code.

So I tried to install the drivers in the building environement using:

- name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          
          curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

          curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list

          apt-get update
          ACCEPT_EULA=Y apt-get install -y msodbcsql18
          ACCEPT_EULA=Y apt-get install -y mssql-tools18
          echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
          source ~/.bashrc
          # optional: for unixODBC development headers
          sudo apt-get install -y unixodbc-dev

In the same way is suggested here.

However, when running the action I receive the following error:

 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: apt-key output should not be parsed (stdout is not a terminal)
E: This command can only be used by root.

100   983  100   983    0     0   8776      0 --:--:-- --:--:-- --:--:--  8776
(23) Failed writing body
Error: Process completed with exit code 1.

That seems to be caused by the curl commands.

So my question is. What’s the best way to test my app using GitHub actions?
Do I need to install the odbc driver? If yes, how can I do it?

Thank you in advance.

2

Answers


  1. You should only need to apt-get the package to install the driver:

        steps:
          - uses: actions/checkout@v3
    
          - name: Install Microsoft ODBC
            run: sudo ACCEPT_EULA=Y apt-get install msodbcsql18 -y
    

    that successfully installs for me. Worth pointing out though that when you connect you’ll need to use the mapped port to the container:

            env:
              PORT: ${{ job.services.mssql.ports[1433] }}
    

    this assumes SQL Server was setup like:

          mssql:
            image: mcr.microsoft.com/mssql/server:2022-latest
            ports: [1433]
            env:
              MSSQL_PID: Developer
              SA_PASSWORD: iugeshrigsuerbiwer
              ACCEPT_EULA: Y
    
    Login or Signup to reply.
  2. You need to run the commands with elevated privileges.
    Simply, add shell with sudo like so:

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        ...
        sudo apt-get install -y unixodbc-dev
      shell: sudo bash {0}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search