diff --git a/.dependabot/config.yml b/.dependabot/config.yml new file mode 100644 index 0000000..06460ff --- /dev/null +++ b/.dependabot/config.yml @@ -0,0 +1,20 @@ +version: 1 +update_configs: + - package_manager: "docker" + directory: "/" + update_schedule: "daily" + commit_message: + prefix: "fix" + include_scope: true + - package_manager: "github_actions" + directory: "/" + update_schedule: "daily" + commit_message: + prefix: "ci" + include_scope: true + - package_manager: "java:gradle" + directory: "/tests" + update_schedule: "daily" + commit_message: + prefix: "chore" + include_scope: true \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..52f5301 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text=auto +*.sh eol=lf +**/run eol=lf +*/services.d/* eol=lf \ No newline at end of file diff --git a/.github/semantic.yml b/.github/semantic.yml new file mode 100644 index 0000000..c0d538f --- /dev/null +++ b/.github/semantic.yml @@ -0,0 +1,11 @@ +titleOnly: true +types: + - feat + - fix + - docs + - refactor + - test + - build + - ci + - chore + - revert \ No newline at end of file diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..f980fff --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,35 @@ +# https://developer.github.com/v3/repos/#edit +repository: + name: docker-$$IMAGE_NAME$$ + description: "" + homepage: https://homecentr.github.io/ + private: false + has_issues: true + has_wiki: false + has_downloads: false + has_projects: false + archived: false + + default_branch: master + allow_squash_merge: true + allow_merge_commit: false + allow_rebase_merge: false + +# https://developer.github.com/v3/repos/branches/#update-branch-protection +branches: + - name: master + protection: + required_status_checks: + strict: true + contexts: [ ".github/workflows/ci.yml" ] + required_pull_request_reviews: null + enforce_admins: false + restrictions: + +labels: + - name: bug + color: d73a4a + - name: feature + color: a2eeef + - name: question + color: d876e3 \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..25d8109 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI PR/Branch +on: + push: + branches-ignore: + - master + pull_request: + +env: + IMAGE_NAME: "homecentr/$$IMAGE_NAME$$" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + + - name: Set up java for tests execution + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Set tag var + id: vars + run: echo ::set-output name=docker_tag::$(echo ${GITHUB_REF} | cut -d'/' -f3)-${GITHUB_SHA} + + - name: Verify Dockerfile with Hadolint + uses: brpaz/hadolint-action@master + + - name: Build Docker image + run: docker build . -t ${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }} + + - name: Test Docker image + run: cd tests && sudo gradle test --info -Dimage_tag=${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }} + + - name: Scan with Phonito Security + uses: phonito/phonito-scanner-action@master + with: + image: ${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }} + phonito-token: '${{ secrets.PHONITO_TOKEN }}' \ No newline at end of file diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml new file mode 100644 index 0000000..f85445f --- /dev/null +++ b/.github/workflows/ci_cd.yml @@ -0,0 +1,74 @@ +name: CI/CD on master +on: + push: + branches: + - master + +env: + IMAGE_NAME: "homecentr/$$IMAGE_NAME$$" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + + - name: Set up java for tests execution + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: "Determine release version" + uses: codfish/semantic-release-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Verify Dockerfile with Hadolint + uses: brpaz/hadolint-action@master + + - name: "Build Docker image" + if: env.RELEASE_VERSION != '' + run: | + docker build . -t "$IMAGE_NAME:$RELEASE_VERSION" \ + --label "org.label-schema.schema-version=1.0" \ + --label "org.label-schema.vcs-ref=${GITHUB_SHA}" \ + --label "org.label-schema.vcs-url=https://github.com/${GITHUB_REPOSITORY}" \ + --label "org.label-schema.url=https://github.com/${GITHUB_REPOSITORY}" \ + --label "org.label-schema.vendor=HomeCentr" \ + --label "version=$RELEASE_VERSION" \ + --label "org.label-schema.build-date=$(date '+%F %T')" + + - name: Test Docker image + if: env.RELEASE_VERSION != '' + run: cd tests && sudo gradle test -Dimage_tag=${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} + + - name: Scan with Phonito Security + if: env.RELEASE_VERSION != '' + uses: phonito/phonito-scanner-action@master + with: + image: ${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }} + phonito-token: '${{ secrets.PHONITO_TOKEN }}' + + - name: "Tag image as latest" + if: env.RELEASE_VERSION != '' + run: "docker tag $IMAGE_NAME:$RELEASE_VERSION $IMAGE_NAME:latest" + + - name: "Log into Docker Hub" + if: env.RELEASE_VERSION != '' + run: "echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin" + + - name: "Push versioned image" + if: env.RELEASE_VERSION != '' + run: "docker push $IMAGE_NAME:$RELEASE_VERSION" + + - name: "Push latest image" + if: env.RELEASE_VERSION != '' + run: "docker push $IMAGE_NAME:latest" + + - name: "Update Docker Hub description" + if: env.RELEASE_VERSION != '' + uses: peter-evans/dockerhub-description@v2.1.0 + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_REPOSITORY: ${{ env.IMAGE_NAME }} diff --git a/.github/workflows/regular_scan.yml b/.github/workflows/regular_scan.yml new file mode 100644 index 0000000..b4ca6d5 --- /dev/null +++ b/.github/workflows/regular_scan.yml @@ -0,0 +1,20 @@ +name: Regular Docker image vulnerability scan +on: + schedule: + - cron: '0 6 * * *' + +env: + IMAGE_NAME: "homecentr/$$IMAGE_NAME$$" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Pull Docker image + run: docker pull ${{ env.IMAGE_NAME }}:latest + + - name: Scan image for vulnerabilities + uses: phonito/phonito-scanner-action@master + with: + image: ${{ env.IMAGE_NAME }}:latest + phonito-token: '${{ secrets.PHONITO_TOKEN }}' \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79cc10f --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +*.class +*.jar +*.war +*.ear +.gradle +build +.gradletasknamecache + +**/.idea/workspace.xml +**/.idea/tasks.xml + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache \ No newline at end of file diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..6e69e5d --- /dev/null +++ b/.releaserc @@ -0,0 +1,8 @@ +{ + branch: 'master', + plugins: [ + '@semantic-release/commit-analyzer', + '@semantic-release/release-notes-generator', + '@semantic-release/github', + ], +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c3c78df --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +FROM alpine \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..570212b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 homecentr + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..80482d2 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +[![Project status](https://badgen.net/badge/project%20status/stable%20%26%20actively%20maintaned?color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/graphs/commit-activity) [![](https://badgen.net/github/label-issues/homecentr/docker-$$IMAGE_NAME$$/bug?label=open%20bugs&color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/labels/bug) [![](https://badgen.net/github/release/homecentr/docker-$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$) +[![](https://badgen.net/docker/pulls/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$) +[![](https://badgen.net/docker/size/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$) + +![CI/CD on master](https://github.com/homecentr/docker-$$IMAGE_NAME$$/workflows/CI/CD%20on%20master/badge.svg) +![Regular Docker image vulnerability scan](https://github.com/homecentr/docker-$$IMAGE_NAME$$/workflows/Regular%20Docker%20image%20vulnerability%20scan/badge.svg) + + +# HomeCentr - $$IMAGE_NAME$$ + + +## Usage + +```yml +version: "3.7" +services: + $$IMAGE_NAME$$: + build: . + image: homecentr/$$IMAGE_NAME$$ +``` + +## Environment variables + +| Name | Default value | Description | +|------|---------------|-------------| +| PUID | 7077 | UID of the user $$IMAGE_NAME$$ should be running as. | +| PGID | 7077 | GID of the user $$IMAGE_NAME$$ should be running as. | + +## Exposed ports + +| Port | Protocol | Description | +|------|------|-------------| +| 80 | TCP | Some useful details | + +## Volumes + +| Container path | Description | +|------------|---------------| +| /config | Some useful details | + +## Security +The container is regularly scanned for vulnerabilities and updated. Further info can be found in the [Security tab](https://github.com/homecentr/docker-$$IMAGE_NAME$$/security). + +### Container user +The container supports privilege drop. Even though the container starts as root, it will use the permissions only to perform the initial set up. The $$IMAGE_NAME$$ process runs as UID/GID provided in the PUID and PGID environment variables. + +:warning: Do not change the container user directly using the `user` Docker compose property or using the `--user` argument. This would break the privilege drop logic. \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..432ecf9 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,15 @@ +# Security policy + +## Disclosure policy + +In case you find a security issues with this docker image, please reach out to me at security@homecentr.io and provide 5 business days to release a fixed version. + +## Security update policy + +Known security issues will be published in GitHub repository's Security / Security advisories. + +## Automated processes + +The Docker image is scanned for vulnerabilities every 24 hours using [Phonito.io](https://phonito.io/?b=a). You can see the scan status under the actions tab / Regular Docker image vulnerability scan. + +The dependencies are automatically scanned using [Dependabot](https://dependabot.com/). Dependencies are regularly updated. You can check for pending dependency updates by listing open Pull requests with the "dependencies" label. \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..980a102 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3.7" +services: + $$IMAGE_NAME$$: + build: . + image: homecentr/$$IMAGE_NAME$$ + restart: unless-stopped \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..753e3e2 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "homecentr-$$IMAGE_NAME$$", + "version": "1.0.0", + "description": "", + "repository": { + "type": "git", + "url": "git+https://github.com/homecentr/docker-$$IMAGE_NAME$$.git" + }, + "author": "", + "license": "MIT", + "bugs": { + "url": "https://github.com/homecentr/docker-$$IMAGE_NAME$$/issues" + }, + "homepage": "https://github.com/homecentr/docker-$$IMAGE_NAME$$#readme" +} diff --git a/tests/.classpath b/tests/.classpath new file mode 100644 index 0000000..3fbb680 --- /dev/null +++ b/tests/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/.idea/.gitignore b/tests/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/tests/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/tests/.idea/.name b/tests/.idea/.name new file mode 100644 index 0000000..71d0457 --- /dev/null +++ b/tests/.idea/.name @@ -0,0 +1 @@ +docker-$$IMAGE_NAME$$-tests \ No newline at end of file diff --git a/tests/.idea/compiler.xml b/tests/.idea/compiler.xml new file mode 100644 index 0000000..098cf64 --- /dev/null +++ b/tests/.idea/compiler.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/tests/.idea/gradle.xml b/tests/.idea/gradle.xml new file mode 100644 index 0000000..dea8515 --- /dev/null +++ b/tests/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/tests/.idea/jarRepositories.xml b/tests/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/tests/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tests/.idea/misc.xml b/tests/.idea/misc.xml new file mode 100644 index 0000000..29af3ee --- /dev/null +++ b/tests/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/tests/.idea/vcs.xml b/tests/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/tests/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/.project b/tests/.project new file mode 100644 index 0000000..215fa44 --- /dev/null +++ b/tests/.project @@ -0,0 +1,23 @@ + + + docker-$$IMAGE_NAME$$-tests + Project tests created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/tests/.settings/org.eclipse.buildship.core.prefs b/tests/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..e889521 --- /dev/null +++ b/tests/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir= +eclipse.preferences.version=1 diff --git a/tests/build.gradle b/tests/build.gradle new file mode 100644 index 0000000..6e9f6cc --- /dev/null +++ b/tests/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'java' +} + +group 'org.homecentr' +version '1.0-SNAPSHOT' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + testImplementation group: 'junit', name: 'junit', version: '4.13' + testImplementation "org.testcontainers:testcontainers:1.14.2" + testImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' + testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30' +} + +test { + systemProperty 'image_tag', System.getProperty('image_tag') + afterTest { desc, result -> + logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}" + } +} \ No newline at end of file diff --git a/tests/gradle/wrapper/gradle-wrapper.jar b/tests/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..87b738c Binary files /dev/null and b/tests/gradle/wrapper/gradle-wrapper.jar differ diff --git a/tests/gradle/wrapper/gradle-wrapper.properties b/tests/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..44e7c4d --- /dev/null +++ b/tests/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/tests/gradlew b/tests/gradlew new file mode 100644 index 0000000..af6708f --- /dev/null +++ b/tests/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/tests/gradlew.bat b/tests/gradlew.bat new file mode 100644 index 0000000..6d57edc --- /dev/null +++ b/tests/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/tests/settings.gradle b/tests/settings.gradle new file mode 100644 index 0000000..efa59b6 --- /dev/null +++ b/tests/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'docker-$$IMAGE_NAME$$-tests' + diff --git a/tests/src/test/java/ContainerTestBase.java b/tests/src/test/java/ContainerTestBase.java new file mode 100644 index 0000000..a06567b --- /dev/null +++ b/tests/src/test/java/ContainerTestBase.java @@ -0,0 +1,36 @@ +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; + +public abstract class ContainerTestBase { + private static final Logger logger = LoggerFactory.getLogger(ContainerTestBase.class); + + private static GenericContainer _container; + + @BeforeClass + public static void setUp() { + String dockerImageTag = System.getProperty("image_tag", "homecentr/$$IMAGE_NAME$$"); + + logger.info("Tested Docker image tag: {}", dockerImageTag); + + _container = new GenericContainer<>(dockerImageTag) + .waitingFor(Wait.forHealthcheck()); + + _container.start(); + _container.followOutput(new Slf4jLogConsumer(logger)); + } + + @AfterClass + public static void cleanUp() { + _container.stop(); + _container.close(); + } + + protected GenericContainer getContainer() { + return _container; + } +} \ No newline at end of file