Skip to content

Commit

Permalink
run and verify db
Browse files Browse the repository at this point in the history
  • Loading branch information
vrsorheim committed Jul 7, 2024
1 parent 82f47e4 commit 860935f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
28 changes: 27 additions & 1 deletion .github/workflows/build_and_push_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ jobs:
- name: Build and push Server Docker image
run: |
pwd && docker buildx build --push --tag crimomsw.azurecr.io/server:${{ github.sha }} ../IMOMaritimeSingleWindow/Server
- name: Build and push Verifyer Docker image
run: |
pwd && docker buildx build --push --tag crimomsw.azurecr.io/db-verifier:latest ../IMOMaritimeSingleWindow/Server/SqlScripts
# - name: Run SQL Script and Check Errors
# run: |
# docker run --rm -e PGPASSWORD=szechuan crimomsw.azurecr.io/server:${{ github.sha }} psql -h imo-dev-psqlflexibleserver-1.postgres.database.azure.com -U postgres -d db-imo-msw-dev-1 -f /workspaces/backend/SqlScripts/Create_and_populate_DB.sql || exit 1
# docker run --rm -e PGPASSWORD=szechuan crimomsw.azurecr.io/server:${{ github.sha }} psql -h imo-dev-psqlflexibleserver-1.postgres.database.azure.com -U postgres -d db-imo-msw-dev-1 -f /workspaces/backend/SqlScripts/Create_and_populate_DB.sql || exit 1

verify:
name: Verify Database
runs-on: ubuntu-latest
needs: docker
steps:
- name: Checkout
uses: actions/checkout@v4

- name: 'Az CLI login using OIDC'
uses: azure/login@v2
with:
client-id: ${{ secrets.ARM_CLIENT_ID }}
tenant-id: ${{ secrets.ARM_TENANT_ID }}
subscription-id: ${{ secrets.ARM_SUBSCRIPTION_ID }}

- name: Run Terraform to Verify Database
run: |
terraform apply -auto-approve -var db_password=szechuan
- name: Retrieve Verification Logs
run: |
az container logs --resource-group rg-imo-msw-terraform-dev-preview --name db-verifier --container-name db-verifier
11 changes: 11 additions & 0 deletions IMOMaritimeSingleWindow/Server/SqlScripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Dockerfile for database verification
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-bionic

WORKDIR /workspaces/verify

# Install PostgreSQL client
RUN apt-get update && apt-get install -y postgresql-client

# Set the entrypoint command to run the verification query and output the result
CMD ["sh", "-c", "psql -h $PGHOST -U $PGUSER -d $PGDATABASE -c 'SELECT * FROM country;'"]

28 changes: 28 additions & 0 deletions terraform/db.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,31 @@ resource "azurerm_postgresql_flexible_server_firewall_rule" "imo_dev_app" {
start_ip_address = "0.0.0.0"
end_ip_address = "0.0.0.0"
}


resource "azurerm_container_group" "db_verifier" {
name = "db-verifier"
location = var.location
resource_group_name = data.azurerm_resource_group.imo_dev_app.name
os_type = "Linux"

container {
name = "db-verifier"
image = "crimomsw.azurecr.io/db-verifier:latest"
cpu = "0.5"
memory = "1.5"

environment_variables = {
PGHOST = "imo-dev-psqlflexibleserver-1.postgres.database.azure.com"
PGUSER = "postgres"
PGPASSWORD = "szechuan"
PGDATABASE = "db-imo-msw-dev-1"
}

commands = [
"sh",
"-c",
"psql -h $PGHOST -U $PGUSER -d $PGDATABASE -c 'SELECT * FROM country;'"
]
}
}

0 comments on commit 860935f

Please sign in to comment.