From d99d92f646453ad5ea98075c18d95c76ff2579d5 Mon Sep 17 00:00:00 2001 From: Jan Bauer <7868978+jbauerrfid@users.noreply.github.com> Date: Sat, 8 Jan 2022 11:39:30 +0100 Subject: [PATCH 1/3] add example for mssql Add Example project with Java and Microsoft SQL Server --- jekyll/_cci2/postgres-config.md | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/jekyll/_cci2/postgres-config.md b/jekyll/_cci2/postgres-config.md index f8081e628d..52a811f302 100644 --- a/jekyll/_cci2/postgres-config.md +++ b/jekyll/_cci2/postgres-config.md @@ -317,6 +317,69 @@ VALUES ( ); ``` +## Example project with Java and Microsoft SQL Server + +{: #example-mssql-project } + +The following example runs a maven build in the primary container and spins up a Microsoft SQL Server in a secondary container. +It waits for the database to start up with the `wait-for` ORB and then runs `sqlcmd` to create a test database. +Finally it runs the maven build and tests against the database `circle_test` on `localhost:1433` +The test user is `sa` to keep it simple (the database is temporary just to run the tests, so security is not really an issue). + +{% raw %} + +```yaml +version: 2.1 + +orbs: + wait-for: cobli/wait-for@0.0.2 + +var: + job: + - &jdkJobWithMssql + docker: + - image: cimg/openjdk:11.0 + - image: mcr.microsoft.com/mssql/server:2019-latest + environment: + ACCEPT_EULA: y + SA_PASSWORD: YourStrongDbPassword + +jobs: + build: + <<: *jdkJobWithMssql + steps: + # See documentation at: https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15#ubuntu + - checkout + - run: + name: Add Microsoft repo keys + command: curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - + - run: + name: Add Microsoft Ubuntu repository + command: curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list + - run: + name: Install packages + command: sudo apt-get update -qq && sudo ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev + # See documentation at: https://circleci.com/developer/orbs/orb/cobli/wait-for#commands-port + - wait-for/port: + description: wait for MS SQL Server + timeout: 600 + seconds-between-retries: 10 + port: 1433 + - run: + name: Create test database + command: /opt/mssql-tools/bin/sqlcmd -U sa -P YourStrongDbPassword -Q "CREATE DATABASE circle_test" + - run: + name: Compile package and run tests + command: mvn package + +workflows: + version: 2 + main: + jobs: + - build: +``` + +{% endraw %} ## See also {: #see-also } From 9b7af94738d67c9bbb4f4c10f87234377d93585e Mon Sep 17 00:00:00 2001 From: Jan Bauer <7868978+jbauerrfid@users.noreply.github.com> Date: Sat, 8 Jan 2022 11:40:51 +0100 Subject: [PATCH 2/3] Update postgres-config.md --- jekyll/_cci2/postgres-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll/_cci2/postgres-config.md b/jekyll/_cci2/postgres-config.md index 52a811f302..695f0e4c05 100644 --- a/jekyll/_cci2/postgres-config.md +++ b/jekyll/_cci2/postgres-config.md @@ -376,7 +376,7 @@ workflows: version: 2 main: jobs: - - build: + - build ``` {% endraw %} From 39500b474dfdd200b9931fa2027aa27d57339660 Mon Sep 17 00:00:00 2001 From: Jan Bauer <7868978+jbauerrfid@users.noreply.github.com> Date: Tue, 18 Jan 2022 09:04:13 +0100 Subject: [PATCH 3/3] Replace wait-for orb with shell command Replace wait-for orb with shell command to avoid third party code in example. --- jekyll/_cci2/postgres-config.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/jekyll/_cci2/postgres-config.md b/jekyll/_cci2/postgres-config.md index 695f0e4c05..735569eeae 100644 --- a/jekyll/_cci2/postgres-config.md +++ b/jekyll/_cci2/postgres-config.md @@ -322,7 +322,7 @@ VALUES ( {: #example-mssql-project } The following example runs a maven build in the primary container and spins up a Microsoft SQL Server in a secondary container. -It waits for the database to start up with the `wait-for` ORB and then runs `sqlcmd` to create a test database. +It waits for the database to start up with the `nc` shell command and then runs `sqlcmd` to create a test database. Finally it runs the maven build and tests against the database `circle_test` on `localhost:1433` The test user is `sa` to keep it simple (the database is temporary just to run the tests, so security is not really an issue). @@ -331,9 +331,6 @@ The test user is `sa` to keep it simple (the database is temporary just to run t ```yaml version: 2.1 -orbs: - wait-for: cobli/wait-for@0.0.2 - var: job: - &jdkJobWithMssql @@ -359,12 +356,16 @@ jobs: - run: name: Install packages command: sudo apt-get update -qq && sudo ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev - # See documentation at: https://circleci.com/developer/orbs/orb/cobli/wait-for#commands-port - - wait-for/port: - description: wait for MS SQL Server - timeout: 600 - seconds-between-retries: 10 - port: 1433 + - run: + name: Wait for MS SQL Server + command: | + for i in `seq 1 10`; + do + nc -z 127.0.0.1 1433 && echo Success && exit 0 + echo -n . + sleep 1 + done + echo Failed waiting for MS SQL Server && exit 1 - run: name: Create test database command: /opt/mssql-tools/bin/sqlcmd -U sa -P YourStrongDbPassword -Q "CREATE DATABASE circle_test"