diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3f1786c --- /dev/null +++ b/CHANGELOG.md @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..079ec7a --- /dev/null +++ b/CONTRIBUTING.md @@ -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 diff --git a/Dockerfile b/Dockerfile index d72effb..d16c155 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 diff --git a/Jenkinsfile b/Jenkinsfile index 99cb08f..60e307a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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' + } + } } } @@ -38,4 +53,4 @@ pipeline { cleanupAndNotify(currentBuild.currentResult) } } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 8e842a2..ade8842 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. diff --git a/VERSION b/VERSION index afaf360..9084fa2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.1.0 diff --git a/bin/publish b/bin/publish index de8f98d..f7652a5 100755 --- a/bin/publish +++ b/bin/publish @@ -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 diff --git a/pom.xml b/pom.xml index 5e6e6ef..d200a93 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,11 @@ mysql mysql-connector-java + + com.microsoft.sqlserver + mssql-jdbc + 7.4.1.jre11 + org.springframework.boot spring-boot-starter-data-jpa diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..82c93f9 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:latest + +RUN apk add --no-cache curl bash diff --git a/test/docker-compose.yml b/test/docker-compose.yml index cebee08..1a341e0 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -7,7 +7,8 @@ services: DB_URL: DB_USERNAME: # common - DB_PASSWORD: securerootpass + DB_PASSWORD: yourStrong()Password + postgres: image: postgres:9.6 healthcheck: @@ -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: @@ -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 diff --git a/test/mssql-health-check b/test/mssql-health-check new file mode 100755 index 0000000..65a03e5 --- /dev/null +++ b/test/mssql-health-check @@ -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 diff --git a/test/test b/test/test index 2e76583..fb6f103 100755 --- a/test/test +++ b/test/test @@ -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" @@ -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" diff --git a/test/test.sql b/test/test.sql index 3166570..201db4e 100644 --- a/test/test.sql +++ b/test/test.sql @@ -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';