-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathpost-create.sh
More file actions
executable file
Β·132 lines (114 loc) Β· 4.85 KB
/
post-create.sh
File metadata and controls
executable file
Β·132 lines (114 loc) Β· 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Post-create script for MSSQL Python Driver devcontainer
set -e
echo "π Setting up MSSQL Python Driver development environment..."
# Install Python packages from requirements.txt
echo "π¦ Installing Python packages..."
pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
# Create symlink for 'python' command (build.sh expects it)
echo "π Creating python symlink..."
sudo ln -sf $(which python3) /usr/local/bin/python
# Set up useful shell aliases (for both bash and zsh)
echo "β‘ Setting up aliases..."
cat > ~/.shell_aliases << 'EOF'
# MSSQL Python Driver development aliases
alias build='cd /workspaces/mssql-python/mssql_python/pybind && ./build.sh && cd /workspaces/mssql-python'
alias test='python -m pytest -v'
EOF
# Ensure aliases are sourced in both shells
grep -qxF 'source ~/.shell_aliases' ~/.bashrc 2>/dev/null || echo 'source ~/.shell_aliases' >> ~/.bashrc
grep -qxF 'source ~/.shell_aliases' ~/.zshrc 2>/dev/null || echo 'source ~/.shell_aliases' >> ~/.zshrc
# Verify environment
echo ""
echo "π Verifying environment..."
python --version
pip --version
cmake --version
if command -v sqlcmd &> /dev/null; then
echo "β
sqlcmd available"
else
echo "β sqlcmd not found"
fi
# Build the C++ extension
echo ""
echo "π¨ Building C++ extension..."
if cd mssql_python/pybind && ./build.sh && cd ../..; then
echo "β
C++ extension built successfully"
else
echo "β C++ extension build failed!"
exit 1
fi
# Install mssql_py_core from NuGet (required for bulkcopy functionality)
echo ""
echo "π¦ Installing mssql_py_core from NuGet (required for bulkcopy)..."
PYCORE_INSTALLED=false
if bash eng/scripts/install-mssql-py-core.sh; then
echo "β
mssql_py_core installed successfully"
PYCORE_INSTALLED=true
else
echo "β οΈ mssql_py_core installation failed - bulkcopy functionality will not be available"
echo " You can retry manually: bash eng/scripts/install-mssql-py-core.sh"
fi
# Generate random password for SQL Server
echo ""
echo "Generating SQL Server password..."
SA_PASSWORD="$(openssl rand -base64 16 | tr -dc 'A-Za-z0-9' | head -c 16)Aa1!"
echo "$SA_PASSWORD" > /tmp/.sqlserver_sa_password
chmod 600 /tmp/.sqlserver_sa_password
# Start SQL Server container (use Azure SQL Edge for ARM64 compatibility)
# This is optional - if Docker-in-Docker fails, the devcontainer still works
echo ""
echo "Starting SQL Server container (optional)..."
ARCH=$(uname -m)
if [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
echo "Detected ARM64 - using Azure SQL Edge..."
docker run -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \
-p 1433:1433 --name sqlserver \
-d mcr.microsoft.com/azure-sql-edge:latest && SQL_STARTED=true || SQL_STARTED=false
else
echo "Detected x86_64 - using SQL Server 2025..."
docker run -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \
-p 1433:1433 --name sqlserver \
-d mcr.microsoft.com/mssql/server:2025-latest && SQL_STARTED=true || SQL_STARTED=false
fi
if [ "$SQL_STARTED" = "true" ]; then
echo "Waiting for SQL Server to start..."
sleep 15
else
echo "WARNING: SQL Server container failed to start (Docker issue)"
echo " You can start it manually later with:"
echo " docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=YourPassword123!' -p 1433:1433 --name sqlserver -d mcr.microsoft.com/azure-sql-edge:latest"
fi
# Set DB_CONNECTION_STRING environment variable (persist across all terminals)
DB_CONNECTION_STRING="Server=localhost,1433;Database=master;UID=sa;PWD=$SA_PASSWORD;TrustServerCertificate=Yes;Encrypt=Yes"
# Write to /etc/environment for system-wide persistence
echo "DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" | sudo tee -a /etc/environment > /dev/null
# Also add to shell rc files for immediate availability in new terminals
echo "export DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" >> ~/.bashrc
echo "export DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" >> ~/.zshrc
# Export for current session
export DB_CONNECTION_STRING
# Display completion message and next steps
echo ""
echo "=============================================="
echo "π Dev environment setup complete!"
echo "=============================================="
echo ""
echo "π¦ What's ready:"
echo " β
C++ extension built"
if [ "$PYCORE_INSTALLED" = "true" ]; then
echo " β
mssql_py_core installed (bulkcopy support)"
else
echo " β οΈ mssql_py_core not installed (bulkcopy unavailable - retry: bash eng/scripts/install-mssql-py-core.sh)"
fi
echo " β
SQL Server running (localhost:1433)"
echo " β
DB_CONNECTION_STRING set in environment"
echo ""
echo "π Quick start - just type these commands:"
echo " python main.py β Test the connection"
echo " test β Run all pytest tests"
echo " build β Rebuild C++ extension"
echo ""
echo "=============================================="
echo ""