Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ README.md
Tools/mssql-proxy/build
Tools/mssql-proxy/dist
Tools/mssql-proxy/.gitignore
Tools/mssql-proxy/*.spec

Frontend/.angular
Frontend/.vscode
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.sh text eol=lf
10 changes: 7 additions & 3 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
tags:
- "v*"
workflow_dispatch:

permissions:
contents: write
Expand All @@ -18,10 +19,12 @@ env:
jobs:
publish:
uses: ./.github/workflows/publish.yml
if: github.ref_type == 'tag'

release:
needs: [publish, build-linux, build-windows, build-docker]
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [publish, build-linux, build-windows, build-docker]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -81,7 +84,8 @@ jobs:
with:
python-version: 3.11.4
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
- run: pyinstaller --onefile mssql-proxy.py
- run: ./Tools/mssql-proxy/odbc-driver-installer.sh
- run: pyinstaller mssql-proxy.linux.spec
working-directory: Tools/mssql-proxy
- run: tar -czf mssql-proxy-${{ github.ref_name }}-linux.tar.gz Tools/mssql-proxy/dist
- uses: actions/upload-artifact@v4
Expand All @@ -97,7 +101,7 @@ jobs:
with:
python-version: 3.11.4
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
- run: pyinstaller --onefile mssql-proxy.py
- run: pyinstaller mssql-proxy.win.spec
working-directory: Tools/mssql-proxy
- run: tar -a -c -f mssql-proxy-${{ github.ref_name }}-windows.zip Tools/mssql-proxy/dist
- uses: actions/upload-artifact@v4
Expand Down
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ FROM node:20-alpine AS node-builder

WORKDIR /app

COPY Frontend .

COPY Frontend/package.json Frontend/package-lock.json ./
RUN npm install

COPY Frontend .
RUN npm run build

FROM python:3.11-alpine AS python-builder

WORKDIR /app

RUN apk add --no-cache --update alpine-sdk
RUN apk add --no-cache gcc python3-dev musl-dev libffi-dev libc-dev unixodbc unixodbc-dev
RUN apk add --no-cache gcc python3-dev musl-dev libffi-dev libc-dev

COPY Tools/mssql-proxy .
COPY Tools/mssql-proxy/odbc-driver-installer.sh Tools/mssql-proxy/requirements.txt ./

RUN ./odbc-driver-installer.sh
RUN pip install --no-cache-dir -r requirements.txt pyinstaller
RUN pyinstaller --onefile mssql-proxy.py --name mssql-proxy

COPY Tools/mssql-proxy .

RUN pyinstaller mssql-proxy.linux.spec

FROM alpine:latest

Expand Down
1 change: 0 additions & 1 deletion Tools/mssql-proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Compiled output
/dist
/build
*.spec

# IDEs and editors
.idea/
Expand Down
40 changes: 40 additions & 0 deletions Tools/mssql-proxy/mssql-proxy.linux.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
['mssql-proxy.py'],
pathex=[],
binaries=[],
datas=[
('/opt/microsoft/msodbcsql18', 'drivers/msodbcsql18')
],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='mssql-proxy',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
13 changes: 10 additions & 3 deletions Tools/mssql-proxy/mssql-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydantic import BaseModel
import uvicorn
from colorama import Fore, Style, init
import sys

# Initialize colorama
init(autoreset=True)
Expand Down Expand Up @@ -76,11 +77,17 @@ def log_query(index, query):
@app.post("/connect")
async def connect(request: ConnectRequest):
global connection_index_counter
connection_string = f"Driver={{SQL Server}};Server={request.server};UID={request.username};PWD={request.password};"
try:
# Attempt to connect to the database
connection = pyodbc.connect(connection_string, timeout=5)

try:
connection = pyodbc.connect(f"Driver={{SQL Server}};Server={request.server};UID={request.username};PWD={request.password};", timeout=5)
except:
try:
base_path = sys._MEIPASS
connection = pyodbc.connect(f"Driver={base_path}/drivers/msodbcsql18/lib64/libmsodbcsql-18.4.so.1.1;Server={request.server};UID={request.username};PWD={request.password};", timeout=5)
except:
raise

# Generate a unique ID and index for the connection
connection_id = str(uuid.uuid4())
index = connection_index_counter
Expand Down
38 changes: 38 additions & 0 deletions Tools/mssql-proxy/mssql-proxy.win.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
['mssql-proxy.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='mssql-proxy',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
59 changes: 59 additions & 0 deletions Tools/mssql-proxy/odbc-driver-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Detect architecture
case $(uname -m) in
x86_64) architecture="amd64" ;;
arm64) architecture="arm64" ;;
*) architecture="unsupported" ;;
esac
if [[ "unsupported" == "$architecture" ]]; then
echo "Architecture $(uname -m) is not currently supported."
exit 1
fi

# Detect OS
if [ -f /etc/alpine-release ]; then
os="alpine"
elif [ -f /etc/lsb-release ]; then
os="ubuntu"
else
echo "Unsupported operating system."
exit 1
fi

# Install dependencies based on OS
if [ "$os" == "alpine" ]; then
echo "Installing packages for Alpine Linux..."
if ! apk add --no-cache unixodbc unixodbc-dev curl gnupg; then
echo "Installation of packages failed on Alpine." >&2
exit 1
fi
elif [ "$os" == "ubuntu" ]; then
echo "Installing packages for Ubuntu..."
if ! apt-get update || ! apt-get install -y unixodbc unixodbc-dev curl gnupg; then
echo "Installation of packages failed on Ubuntu." >&2
exit 1
fi
else
echo "Unknown error occurred during OS detection."
exit 1
fi
echo "Installed dependencies successfully."

# Install msodbcsql18
echo "Installing msodbcsql18..."
if [ "$os" == "alpine" ]; then
# Download package for Alpine
curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/msodbcsql18_18.4.1.1-1_$architecture.apk
curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/msodbcsql18_18.4.1.1-1_$architecture.sig
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --import -
gpg --verify msodbcsql18_18.4.1.1-1_$architecture.sig msodbcsql18_18.4.1.1-1_$architecture.apk
apk add --allow-untrusted msodbcsql18_18.4.1.1-1_$architecture.apk
elif [ "$os" == "ubuntu" ]; then
# Add Microsoft repository
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
else
echo "Failed to handle msodbcsql18 installation for $os."
exit 1
fi