Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,34 @@ RUN jlink --compress=2 --module-path /opt/jdk/jmods \
&& apk add --no-cache git sed findutils coreutils make npm curl gawk \
&& git config --global advice.detachedHead false

ENV DOCKER=build
RUN npm install -gs raml2html raml2html-modern-theme

# copy files required to build dev environment and fetch dependencies
COPY makefile build.gradle.kts settings.gradle.kts gradlew ./
# download gradle
COPY gradlew ./
COPY gradle gradle
RUN bash -c 'echo "\n\n" | ./gradlew init --type basic --dsl kotlin --no-daemon'

# copy files required to build dev environment and fetch dependencies
COPY build.gradle.kts settings.gradle.kts ./

# cache build environment
RUN make install-dev-env
# download raml tools (these never change)
RUN ./gradlew install-raml-4-jax-rs install-raml-merge

# download project dependencies in advance
RUN ./gradlew download-dependencies

# copy raml over for merging, then perform code and documentation generation
COPY api.raml ./
COPY schema schema
RUN ./gradlew generate-jaxrs generate-raml-docs

# copy remaining files
COPY . .

# build the project
RUN ./gradlew clean test shadowJar


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Run the service
Expand Down
9 changes: 7 additions & 2 deletions api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ uses:
application/json:
type: error.ServerError

# TODO: need the file upload patch in the gradle plugin for this
/word-count:
post:
description: Counts the words in an uploaded file.
body:
multipart/form-data:
type: file
type: object
properties:
uploadMethod:
type: string
enum: [ 'url', 'file' ]
url?: string
file?: file
responses:
200:
description: |
Expand Down
32 changes: 11 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.veupathdb.lib.gradle.container.util.Logger.Level

plugins {
java
id("org.veupathdb.lib.gradle.container.container-utils") version "4.5.3"
id("org.veupathdb.lib.gradle.container.container-utils") version "4.8.3"
id("com.github.johnrengelman.shadow") version "7.1.2"
}

Expand Down Expand Up @@ -41,19 +41,9 @@ containerBuild {
dockerFile = "Dockerfile"

// Resulting image tag
imageName = "example-service"
imageName = "example-async-service"

}

generateJaxRS {
// List of custom arguments to use in the jax-rs code generation command
// execution.
arguments = listOf(/*arg1, arg2, arg3*/)

// Map of custom environment variables to set for the jax-rs code generation
// command execution.
environment = mapOf(/*Pair("env-key", "env-val"), Pair("env-key", "env-val")*/)
}
}

java {
Expand Down Expand Up @@ -95,21 +85,21 @@ dependencies {
// repository:

// Core lib
implementation("org.veupathdb.lib:jaxrs-container-core:6.10.1")
implementation("org.veupathdb.lib:jaxrs-container-core:6.14.4")

// Jersey
implementation("org.glassfish.jersey.core:jersey-server:3.0.8")
implementation("org.glassfish.jersey.core:jersey-server:3.1.1")

// Async platform core
implementation("org.veupathdb.lib:compute-platform:1.3.5")
implementation("org.veupathdb.lib:compute-platform:1.5.0")

// Job IDs
implementation("org.veupathdb.lib:hash-id:1.1.0")

// Logging
implementation("org.slf4j:slf4j-api:1.7.36")
implementation("org.apache.logging.log4j:log4j-core:2.19.0")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.19.0")
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.20.0")


// Example Dependencies
Expand All @@ -120,7 +110,7 @@ dependencies {
// Pico CLI
// Only required if your project adds custom CLI/environment options, see
// the "MyOptions" class in the demo source code.
implementation("info.picocli:picocli:4.6.3")
implementation("info.picocli:picocli:4.7.1")

// Jackson
// Only required if you are going to be directly using Jackson's JSON api.
Expand All @@ -138,9 +128,9 @@ dependencies {
// These dependencies are not required, but are recommended.

// JUnit 5
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")

// Mockito Test Mocking
testImplementation("org.mockito:mockito-core:4.7.0")
testImplementation("org.mockito:mockito-core:5.2.0")
}
5 changes: 1 addition & 4 deletions docker-compose/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ services:
RABBITMQ_DEFAULT_USER: demouser
RABBITMQ_DEFAULT_PASS: demopass

service:
build:
dockerfile: Dockerfile
context: ..
example:
ports:
- "8080:8080"
depends_on:
Expand Down
12 changes: 4 additions & 8 deletions docker-compose/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ services:
#
# Each new container in the Docker compose stack will need a service entry.
example:
# The "build" field tells docker compose how to build the Docker image that
# backs this individual service.
build:
# Context is the root for the docker image to be built, including the
# Dockerfile.
context: ..
image: example-async-service:latest

# The "environment" field defines a map of environment variables that will
# be passed to the service container on startup.
#
# Fields here that do not have a value provided here will be required on
# docker-compose startup.
environment:
# The port this service will bind to in it's own container.
# The port this service will bind to in its own container.
SERVER_PORT: 80

# A comma separated list of LDAP servers this service should hit to fetch
Expand Down Expand Up @@ -68,4 +64,4 @@ services:
# docker-compose stack.
networks:
traefik:
external: true
external: true
129 changes: 48 additions & 81 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
<<<<<<< HEAD
APP_PACKAGE := $(shell ./gradlew -q print-package | tail -1)
MAIN_DIR := src/main/java/$(shell echo $(APP_PACKAGE) | sed 's/\./\//g')
TEST_DIR := $(shell echo $(MAIN_DIR) | sed 's/main/test/')
BIN_DIR := .tools/bin
#
# Help/Usage
#

C_BLUE := "\\033[94m"
C_NONE := "\\033[0m"
C_CYAN := "\\033[36m"
C_RED := "\\033[31m"

=======
>>>>>>> template/master
#
# Development environment setup / teardown
#

<<<<<<< HEAD
.PHONY: help
help:
@echo "Targets:\n`cat makefile | grep '^[a-z\-]\+:' | sed 's/:.*//;s/^/ /'`"
.PHONY: default
default:
@echo "Please choose one of:"
@echo ""
@echo "$(C_BLUE) make install-dev-env$(C_NONE)"
@echo " Checks the development environment for initial build dependencies "
@echo " and downloads them if necessary."
@echo ""
@echo "$(C_BLUE) make raml-gen-code$(C_NONE)"
@echo " Generates Java classes representing API interfaces as "
@echo " defined in api.raml and child types."
@echo ""
@echo "$(C_BLUE) make compile$(C_NONE)"
@echo " Compiles the existing code in 'src/'. Regenerates files if the"
@echo " api spec has changed."
@echo ""
@echo "$(C_BLUE) make test$(C_NONE)"
@echo " Compiles the existing code in 'src/' and runs unit tests."
@echo " Regenerates files if the api spec has changed."
@echo ""
@echo "$(C_BLUE) make jar$(C_NONE)"
@echo " Compiles a 'fat jar' from this project and its dependencies."
@echo ""
@echo "$(C_BLUE) make docker$(C_NONE)"
@echo " Builds a runnable docker image for this service"
@echo ""
@echo "$(C_BLUE) make clean$(C_NONE)"
@echo " Remove files generated by other targets; put project back in"
@echo " its original state."
@echo ""

#
# Project & Environment Setup Targets
# Development environment setup / teardown
#

.PHONY: new-project-initialization
new-project-initialization:
@if [ ! 1 -eq `git rev-list --all --count` ]; then \
echo ; \
echo "$(C_RED)-- ERROR -----------------------------------------------------------------------$(C_NONE)"; \
echo "This make target cannot not be used after a new project already has commits.";\
echo "Merging the histories of the template repository and a project based on it may";\
echo "cause issues and must be done with care.";\
echo "$(C_RED)--------------------------------------------------------------------------------$(C_NONE)";\
echo ; \
exit 1; \
fi
$(MAKE) register-template-repo
@git fetch template
@git merge template/master --allow-unrelated-histories

.PHONY: link-template-repo
link-template-repo:
@git remote add template [email protected]:VEuPathDB/example-jaxrs-container-service.git

# Merges in changes from the template/example repo.
.PHONY: merge-template-repo
merge-template-repo:
@git remote show template > /dev/null 2>&1 || (echo "\n$(C_RED)Template repo has not been registered.$(C_NONE)\n\nRun 'make link-template-repo'\n"; exit 1)
@git fetch template
@git merge template/master

=======
>>>>>>> template/master
.PHONY: install-dev-env
install-dev-env:
./gradlew check-env

.PHONY: clean
clean:
@rm -rf .bin .gradle .tools build vendor
@./gradlew clean
@rm -rf .bin .gradle

#
# Code & Doc Generation
#

.PHONY: raml-gen-code
raml-gen-code:
./gradlew generate-jaxrs

.PHONY: raml-gen-docs
raml-gen-docs:
./gradlew generate-raml-docs

#
# Build & Test Targets
Expand All @@ -80,42 +80,9 @@ jar: build/libs/service.jar
docker:
./gradlew build-docker --stacktrace

#
# Code & Doc Generation
#

.PHONY: raml-gen-code
raml-gen-code:
./gradlew generate-jaxrs

.PHONY: raml-gen-docs
raml-gen-docs:
./gradlew generate-raml-docs


.PHONY: example-build
example-build:
@docker compose -f docker-compose/docker-compose.dev.yml build \
--build-arg=GITHUB_USERNAME=${GITHUB_USERNAME} \
--build-arg=GITHUB_TOKEN=${GITHUB_TOKEN}

.PHONY: example-run
example-run:
@docker compose -f docker-compose/docker-compose.dev.yml up

.PHONY: example-clean
example-clean:
@docker compose -f docker-compose/docker-compose.dev.yml down

#
# File based targets
#

build/libs/service.jar: build.gradle.kts
<<<<<<< HEAD
@echo "$(C_BLUE)Building application jar$(C_NONE)"
@./gradlew clean test shadowJar

=======
./gradlew clean test generate-raml-docs shadowJar
>>>>>>> template/master
47 changes: 3 additions & 44 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,45 +1,4 @@
pluginManagement {
fun requireNonBlankGitHubCred(key: String, env: String) : String {

// First try and load the gradle.properties entry.
if (extra.has(key)) {
val cred = extra[key] as String?

// Well, they defined it, but they did it wrong, so throw an error here.
if (cred.isNullOrBlank()) {
println("Gradle property \"$key\" has been set to a null or blank value.")
throw RuntimeException("Gradle property \"$key\" has been set to a null or blank value.")
}

return cred
}

// They don't have a gradle.properties entry. Check the environment.

val cred = System.getenv(env)

if (cred.isNullOrBlank()) {
println("Environment variable \"$env\" is missing or blank.")
throw RuntimeException("Environment variable \"$env\" is missing or blank.")
}

return cred
}

fun requireGitHubUsername() = requireNonBlankGitHubCred("gpr.user", "GITHUB_USERNAME")
fun requireGitHubToken() = requireNonBlankGitHubCred("gpr.key", "GITHUB_TOKEN")

repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/veupathdb/maven-packages")
credentials {
username = requireGitHubUsername()
password = requireGitHubToken()
}
}
}
// adds repos for gradle plugin resolution and ensures github creds are provided to the build
apply {
from("https://raw.githubusercontent.com/VEuPathDB/lib-gradle-container-utils/v4.8.3/includes/common.settings.gradle.kts")
}
Loading