Skip to content

Commit

Permalink
Merge pull request #18 from conjurdemos/add-mssql
Browse files Browse the repository at this point in the history
Add support for MSSQL
  • Loading branch information
doodlesbykumbi authored Jan 14, 2020
2 parents 32ef62b + 02f7664 commit b778e8c
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 27 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.1.0] - 2020-01-13

### Added
- Added support for MSSQL

## [1.0.0] - 2018-05-17

The first tagged version.

[Unreleased]: https://github.com/cyberark/secretless-broker/compare/v1.1.0...HEAD
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing to the Pet Store Demo

## Prerequisites

Before getting started, you should install some developer tools.

1. [git][get-git] to manage source code
1. [Docker][get-docker] to manage dependencies and runtime environments

[get-docker]: https://docs.docker.com/engine/installation
[get-git]: https://git-scm.com/downloads

## Building
Run `./bin/build`. Requires Docker.

## Testing
To test against a specific database type, run `./test/test {db type}`, where
**db type** is `mysql`, `postgres`, or `mssql`.

## Releasing
- Update the [VERSION](VERSION)
- Update the [CHANGELOG](CHANGELOG.md)
- Submit your changes in a PR
- Once the PR has been reviewed and merged, at a git tag to the repo
- Add a github release for the new tag, and copy/paste the CHANGELOG data
for the version into the gh release notes
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# STAGE:
# The 'maven' base is used to package the application
FROM maven:3.5.3-jdk-8-alpine as maven
FROM maven:3.6.3-jdk-11-slim as maven

WORKDIR /app

Expand All @@ -21,7 +21,7 @@ RUN mvn package && cp target/petstore-*.jar app.jar
# This base is used for the final image
# It extracts the packaged application from the previous stage
# and builds the final image
FROM java:8-jre-alpine
FROM openjdk:11-jre-slim
MAINTAINER CyberArk

COPY --from=maven /app/app.jar /app.jar
Expand Down
23 changes: 19 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@ pipeline {
}

stage('Test') {
steps {
sh './test/test postgres'
sh './test/test mysql'
parallel {
stage('Test Postgres') {
steps {
sh './test/test postgres'
}
}

stage('Test MySQL') {
steps {
sh './test/test mysql'
}
}

stage('Test MSSQL') {
steps {
sh './test/test mssql'
}
}
}
}

Expand All @@ -38,4 +53,4 @@ pipeline {
cleanupAndNotify(currentBuild.currentResult)
}
}
}
}
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# pet-store
A demo application creating using the Spring Framework. This application requires access to a database.

### Building
Run `./bin/build`. Requires Docker.

### Running
When running the pet-store, the following environment variables are expected:
`DB_URL` Url or connection string
`DB_USERNAME` Username to connect as (not required for secretless)
`DB_PASSWORD` Password to connect as (not required for secretless)
`DB_PLATFORM` Platform to use in the DDL or DML scripts (such as schema-${platform}.sql or data-${platform}.sql)
- `DB_URL` Url or connection string.
- `DB_USERNAME` Username to connect as (not required for secretless).
- `DB_PASSWORD` Password to connect as (not required for secretless).
- `DB_PLATFORM` Platform to use in the DDL or DML scripts (such as schema-${platform}.sql
or data-${platform}.sql). Supported values of `DB_PLATFORM` are `mysql`, `mssql`, and `postgres`.

### Routes
The demo application mocks a pet store service which controls an inventory of pets in a persistent database. The following routes are exposed:
Expand Down Expand Up @@ -72,6 +69,10 @@ the app knows about
##### Returns
`200`

# Contributing

To learn more about contributing to this repository, please see [CONTRIBUTING.md](CONTRIBUTING.md).

# License

The Pet Store demo app is licensed under Apache License 2.0 - see [`LICENSE.md`](LICENSE.md) for more details.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
17 changes: 13 additions & 4 deletions bin/publish
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ readonly REGISTRY="${1:-cyberark}"
readonly IMAGE_NAME="demo-app"
readonly IMAGE_TAG="$(cat VERSION)"

docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}"
docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "${REGISTRY}/${IMAGE_NAME}:latest"
# fetching tags is required for git_description to work
git fetch --tags
git_description=$(git describe --tags)

docker push "${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}"
docker push "${REGISTRY}/${IMAGE_NAME}:latest"
# only publish images when the tag matches the VERSION
if [ "$git_description" = "v${IMAGE_TAG}" ]; then
echo "Revision $git_description matches version $VERSION exactly. Pushing to Dockerhub..."

docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}"
docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "${REGISTRY}/${IMAGE_NAME}:latest"

docker push "${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}"
docker push "${REGISTRY}/${IMAGE_NAME}:latest"
fi
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.1.jre11</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:latest

RUN apk add --no-cache curl bash
25 changes: 21 additions & 4 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ services:
DB_URL:
DB_USERNAME:
# common
DB_PASSWORD: securerootpass
DB_PASSWORD: yourStrong()Password

postgres:
image: postgres:9.6
healthcheck:
Expand All @@ -16,7 +17,8 @@ services:
interval: 10s
retries: 10
environment:
POSTGRES_PASSWORD: securerootpass
POSTGRES_PASSWORD: yourStrong()Password

mysql:
image: mysql/mysql-server:5.7
healthcheck:
Expand All @@ -25,10 +27,25 @@ services:
interval: 10s
retries: 10
environment:
MYSQL_ROOT_PASSWORD: securerootpass
MYSQL_ROOT_PASSWORD: yourStrong()Password
MYSQL_DATABASE: mysql
volumes:
- ./test.sql:/docker-entrypoint-initdb.d/test.sql

mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
healthcheck:
test: ["CMD-SHELL", "mssql-health-check"]
timeout: 10s
interval: 10s
retries: 10
environment:
SA_PASSWORD: yourStrong()Password
ACCEPT_EULA: Y
volumes:
- ./mssql-health-check:/usr/local/bin/mssql-health-check

test:
image: mysql/mysql-server:5.7
build:
context: .
command: sleep infinity
18 changes: 18 additions & 0 deletions test/mssql-health-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -euo pipefail

# wait for MSSQL server to start
export STATUS=1
i=0

while [[ $STATUS -ne 0 ]] && [[ $i -lt 30 ]]; do
i=$i+1
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q 'SELECT @@VERSION' >> /dev/null
STATUS=$?
done

if [ $STATUS -ne 0 ]; then
echo "Error: MSSQL SERVER took more than thirty seconds to start up."
exit 1
fi
13 changes: 11 additions & 2 deletions test/test
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@ mysql) export DB_PLATFORM=mysql
export DB_URL=mysql://mysql:3306/mysql
export DB_USERNAME=mysql
;;
mssql) export DB_PLATFORM=mssql
export DB_URL=sqlserver://mssql:1433;databaseName=tempdb
export DB_USERNAME=sa
;;
*) echo "DATABASE_TYPE $1 is not supported"
exit 1
;;
esac

cleanup () {
docker-compose logs app;
# Uncomment this line for debugging
# docker-compose logs app;
docker-compose down -v;
}
trap cleanup EXIT QUIT INT;

cleanup;
# set the COMPOSE_PROJECT_NAME for the tests you'll be running
COMPOSE_PROJECT_NAME="$(openssl rand -hex 3)"
export COMPOSE_PROJECT_NAME

docker-compose up -d ${DB_PLATFORM};

echo "Waiting for $DB_PLATFORM to start"
Expand All @@ -41,6 +49,7 @@ done
echo ""
>&2 echo "$DB_PLATFORM is up - continuing"

docker-compose build test
docker-compose up -d app test;

echo "Waiting for app"
Expand Down
4 changes: 2 additions & 2 deletions test/test.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' IDENTIFIED BY 'securerootpass';
GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%' IDENTIFIED BY 'securerootpass';
GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' IDENTIFIED BY 'yourStrong()Password';
GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%' IDENTIFIED BY 'yourStrong()Password';

0 comments on commit b778e8c

Please sign in to comment.