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
You should only need to apt-get the package to install the driver:
that successfully installs for me. Worth pointing out though that when you connect you’ll need to use the mapped port to the container:
this assumes SQL Server was setup like:
You need to run the commands with elevated privileges.
Simply, add
shell
withsudo
like so: