Skip to content

Commit

Permalink
Merge pull request #1582 from craddm/release-v4.1.0
Browse files Browse the repository at this point in the history
Fix deployment issues with MSSQL and PyPi mirrors
  • Loading branch information
craddm authored Aug 29, 2023
2 parents e38a17f + 6909c8c commit a0a027f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ write_files:
- path: "/etc/cron.d/pull-from-internet"
permissions: "0644"
content: |
# External update (rsync from CRAN) every 6 hours
# External update from PyPi every 6 hours
0 */6 * * * mirrordaemon ~mirrordaemon/pull_from_internet.sh
- path: "/etc/cron.d/pull-then-push"
Expand Down Expand Up @@ -313,7 +313,7 @@ runcmd:

# Install bandersnatch with pip
- echo ">=== Installing bandersnatch... ===<"
- pip3 install bandersnatch==4.2.0
- pip3 install bandersnatch==4.2.0 packaging==21.3
- echo "Using bandersnatch from '$(which bandersnatch)'"

# Initialise allowlist if appropriate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if ($operationFailed -Or (-Not $loginExists)) {
# Create a DB user for each login group
Write-Output "Ensuring that an SQL user exists for '$domainGroup' on: '$serverName'..."
$sqlCommand = "IF NOT EXISTS(SELECT * FROM sys.database_principals WHERE name = '$domainGroup') CREATE USER [$domainGroup] FOR LOGIN [$domainGroup];"
Invoke-SqlCmd -ServerInstance $serverInstance -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
Invoke-SqlCmd -ServerInstance $serverName -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query "$sqlCommand" -TrustServerCertificate -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
if ($? -And -Not $sqlErrorMessage) {
Write-Output " [o] Ensured that '$domainGroup' user exists on: '$serverName'"
Start-Sleep -s 10 # allow time for the database action to complete
Expand All @@ -124,7 +124,7 @@ if ($operationFailed -Or (-Not $loginExists)) {
foreach ($groupSchemaTuple in @(($DataAdminGroup, "data"), ($ResearchUsersGroup, "dbopublic"))) {
$domainGroup, $schemaName = $groupSchemaTuple
$sqlCommand = "IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'$schemaName') EXEC('CREATE SCHEMA $schemaName AUTHORIZATION [$domainGroup]');"
Invoke-SqlCmd -ServerInstance $serverInstance -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
Invoke-SqlCmd -ServerInstance $serverName -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -TrustServerCertificate -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
if ($? -And -Not $sqlErrorMessage) {
Write-Output " [o] Successfully ensured that '$schemaName' schema exists on: '$serverName'"
Start-Sleep -s 10 # allow time for the database action to complete
Expand Down Expand Up @@ -154,7 +154,7 @@ if ($operationFailed -Or (-Not $loginExists)) {
Write-Output " [x] Role $role not recognised!"
continue
}
Invoke-SqlCmd -ServerInstance $serverInstance -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
Invoke-SqlCmd -ServerInstance $serverName -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -TrustServerCertificate -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
if ($? -And -Not $sqlErrorMessage) {
Write-Output " [o] Successfully gave '$domainGroup' $role permissions on: '$serverName'"
Start-Sleep -s 10 # allow time for the database action to complete
Expand All @@ -171,7 +171,7 @@ if ($operationFailed -Or (-Not $loginExists)) {
# ------------------------------------
Write-Output "Running T-SQL lockdown script on: '$serverName'..."
$sqlCommand = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($ServerLockdownCommandB64))
Invoke-SqlCmd -ServerInstance $serverName -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
Invoke-SqlCmd -ServerInstance $serverName -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -TrustServerCertificate -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
if ($? -And -Not $sqlErrorMessage) {
Write-Output " [o] Successfully ran T-SQL lockdown script on: '$serverName'"
} else {
Expand All @@ -187,7 +187,7 @@ if ($operationFailed -Or (-Not $loginExists)) {
$windowsAdmin = "${serverName}\${VmAdminUsername}"
Write-Output "Removing database access from $windowsAdmin on: '$serverName'..."
$sqlCommand = "DROP USER IF EXISTS [$windowsAdmin]; IF EXISTS(SELECT * FROM master.dbo.syslogins WHERE loginname = '$windowsAdmin') DROP LOGIN [$windowsAdmin]"
Invoke-SqlCmd -ServerInstance $serverInstance -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
Invoke-SqlCmd -ServerInstance $serverName -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -TrustServerCertificate -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
if ($? -And -Not $sqlErrorMessage) {
Write-Output " [o] Successfully removed database access for $windowsAdmin on: '$serverName'"
Start-Sleep -s 10 # allow time for the database action to complete
Expand All @@ -203,7 +203,7 @@ if ($operationFailed -Or (-Not $loginExists)) {
# ---------------------------------------------------------------------------------
Write-Output "Revoking sysadmin role from $DbAdminUsername on: '$serverName'..."
$sqlCommand = "ALTER SERVER ROLE sysadmin DROP MEMBER $DbAdminUsername;"
Invoke-SqlCmd -ServerInstance $serverInstance -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
Invoke-SqlCmd -ServerInstance $serverName -Credential $sqlAdminCredentials -QueryTimeout $connectionTimeoutInSeconds -Query $sqlCommand -TrustServerCertificate -ErrorAction SilentlyContinue -ErrorVariable sqlErrorMessage -OutputSqlErrors $true
if ($? -And -Not $sqlErrorMessage) {
Write-Output " [o] Successfully revoked sysadmin role on: '$serverName'"
Start-Sleep -s 10 # allow time for the database action to complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ foreach ($databaseCfg in $config.sre.databases.instances) {
}
} else {
Add-LogMessage -Level Warning "Database VM '$($databaseCfg.vmName)' already exists. Use the '-Redeploy' option if you want to remove the existing database and its data and deploy a new one."
continue
}
}

Expand Down

0 comments on commit a0a027f

Please sign in to comment.