Skip to content

Commit 03882b4

Browse files
committed
Use env file
1 parent 7691347 commit 03882b4

File tree

10 files changed

+44
-17
lines changed

10 files changed

+44
-17
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
"rollForward": false
1111
}
1212
}
13-
}
13+
}

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MSSQL_SA_PASSWORD=example_123

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ jobs:
1717
run: docker compose stats --no-stream
1818
- name: Stop the stack
1919
run: docker compose down -v
20-

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@v4
2828
- uses: azure/[email protected]
29-
with:
29+
with:
3030
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
3131
path: './DbProject/DbProject.sqlproj'
3232
action: 'publish'

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Docs: https://pre-commit.com/
2+
#
3+
# Quickstart:
4+
# $ pip3 install pre-commit
5+
# $ pre-commit install
6+
# < edit json, yaml, (ba)sh, add trailing whitespace etc >
7+
# $ git add .
8+
# $ git commit
9+
#
10+
# If the pre-commit hook is broken, it can be removed by deleting the file
11+
# at .git/hooks/pre-commit
12+
13+
repos:
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v4.4.0
16+
hooks:
17+
- id: end-of-file-fixer
18+
- id: trailing-whitespace
19+
- id: check-merge-conflict

DbProject/DbProject.sqlproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider</DSP>
77
<ModelCollation>1033, CI</ModelCollation>
88
</PropertyGroup>
9-
</Project>
9+
</Project>

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
1010
## Prerequisites
1111
- Azure Subscription
12-
- Azure SQL Database
13-
- Azure Service Principal
1412

1513

1614
## Setup
@@ -31,4 +29,3 @@ See [deploy.yml](.github/workflows/deploy.yml)
3129
- https://learn.microsoft.com/en-gb/sql/tools/sqlpackage/sqlpackage?view=sql-server-ver16
3230
- https://learn.microsoft.com/en-us/sql/relational-databases/data-tier-applications/data-tier-applications?view=sql-server-ver16
3331
- https://www.nuget.org/packages/microsoft.build.sql/
34-

compose.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ services:
55
tty: true
66
container_name: sqlpackage
77
working_dir: /app
8+
env_file:
9+
- .env
810
environment:
9-
ConnectionStrings__Default: Server=db;Initial Catalog=demo;UID=sa;Password=${MSSQL_SA_PASSWORD};TrustServerCertificate=true;Connection Timeout=3;
10-
MSSQL_SA_PASSWORD: Strong=Passw0rd
11+
SourceFile: "bin/Debug/DbProject.dacpac"
12+
TargetConnectionString: "Server=tcp:db,1433;Initial Catalog=demo;UID=sa;Password=${MSSQL_SA_PASSWORD};TrustServerCertificate=true;Connection Timeout=3;"
1113
volumes:
1214
- $PWD/DbProject:/app:rw
15+
- $PWD/scripts:/scripts
1316
entrypoint:
1417
- /bin/bash
1518
- -c
1619
- |
17-
set -exo pipefail
18-
dotnet build
19-
sqlpackage /Action:Publish /SourceFile:"bin/Debug/DbProject.dacpac" \
20-
/TargetConnectionString:"Server=tcp:db,1433;Initial Catalog=demo;User ID=sa;Password=Strong=Passw0rd;TrustServerCertificate=True;Connection Timeout=30;"
20+
/scripts/deploy.sh
2121
# enables to keep the container running
2222
tail -f /dev/null
2323
depends_on:
@@ -29,16 +29,17 @@ services:
2929
db:
3030
image: mcr.microsoft.com/mssql/server:2022-CU12-ubuntu-22.04
3131
container_name: db
32+
hostname: db
33+
env_file:
34+
- .env
3235
environment:
3336
ACCEPT_EULA: "Y"
34-
MSSQL_SA_PASSWORD: Strong=Passw0rd
3537
ports:
3638
- "1433:1433"
37-
hostname: db
3839
healthcheck:
3940
test:
4041
- CMD-SHELL
41-
- /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "Strong=Passw0rd" -Q "SELECT getdate()" -b
42+
- /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$MSSQL_SA_PASSWORD" -Q "SELECT getdate()" -b
4243
timeout: 3s
4344
interval: 10s
4445
retries: 10

docker/sqlpackage/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sqlpackage /Version
1+
sqlpackage /?

scripts/deploy.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
dotnet build
5+
6+
sqlpackage /Action:Publish \
7+
/SourceFile:"${SourceFile}" \
8+
/TargetConnectionString:"${TargetConnectionString}"
9+
10+
# sqlpackage /Action:DeployReport /tcs:"${TargetConnectionString}" /sf:"${SourceFile}" /op:/app/foo

0 commit comments

Comments
 (0)