Skip to content
Merged
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
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: CI
# Run in master and dev branches and in all pull requests to those branches
on:
push:
branches: [ master ]
branches: [ master, webapi-3.0 ]
pull_request:
branches: [ master ]
branches: [ master, webapi-3.0 ]

env:
DOCKER_IMAGE: ohdsi/webapi
Expand Down Expand Up @@ -82,14 +82,14 @@ jobs:
id: build_params
run: |
echo "::set-output name=sha8::${GITHUB_SHA::8}"
if [ ${{ github.event_name == 'pull_request' }} ]; then
echo "::set-output name=push::false"
echo "::set-output name=load::true"
echo "::set-output name=platforms::linux/amd64"
else
if [ "${{ github.event_name }}" != "pull_request" ] && [ "${{ github.ref }}" == "refs/heads/master" ]; then
echo "::set-output name=push::true"
echo "::set-output name=load::false"
echo "::set-output name=platforms::linux/amd64,linux/arm64"
else
echo "::set-output name=push::false"
echo "::set-output name=load::true"
echo "::set-output name=platforms::linux/amd64"
fi

- name: Login to DockerHub
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-

- name: Build code
- name: Build JAR
run: mvn -B -DskipTests=true -DskipUnitTests=true -P${{ env.MAVEN_PROFILE }} package

# Upload it to GitHub
- name: Build WAR
run: mvn -B -DskipTests=true -DskipUnitTests=true -P${{ env.MAVEN_PROFILE }},war package

# Upload both JAR and WAR to GitHub release
- name: Upload to GitHub
uses: AButler/upload-release-assets@v2.0
with:
files: 'target/WebAPI.war'
files: 'target/WebAPI.jar;target/WebAPI.war'
repo-token: ${{ secrets.GITHUB_TOKEN }}

# Build and push tagged release docker image to
Expand Down
29 changes: 8 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN curl -LSsO https://github.com/open-telemetry/opentelemetry-java-instrumentat
COPY pom.xml /code/
RUN mkdir .git \
&& mvn package \
-Dpackaging.type=jar \
-P${MAVEN_PROFILE}

ARG GIT_BRANCH=unknown
Expand All @@ -20,24 +21,18 @@ ARG GIT_COMMIT_ID_ABBREV=unknown
# Compile code and repackage it
COPY src /code/src
RUN mvn package ${MAVEN_PARAMS} \
-Dpackaging.type=jar \
-Dgit.branch=${GIT_BRANCH} \
-Dgit.commit.id.abbrev=${GIT_COMMIT_ID_ABBREV} \
-P${MAVEN_PROFILE} \
&& mkdir war \
&& mv target/WebAPI.war war \
&& cd war \
&& jar -xf WebAPI.war \
&& rm WebAPI.war
-P${MAVEN_PROFILE}

# OHDSI WebAPI and ATLAS web application running as a Spring Boot application with Java 21
# OHDSI WebAPI running as a Spring Boot executable JAR with Java 21
FROM index.docker.io/library/eclipse-temurin:21-jre

MAINTAINER Lee Evans - www.ltscomputingllc.com

# Any Java options to pass along, e.g. memory, garbage collection, etc.
ENV JAVA_OPTS=""
# Additional classpath parameters to pass along. If provided, start with colon ":"
ENV CLASSPATH=""
# Default Java options. The first entry is a fix for when java reads secure random numbers:
# in a containerized system using /dev/random may reduce entropy too much, causing slowdowns.
# https://ruleoftech.com/2016/avoiding-jvm-delays-caused-by-random-number-generation
Expand All @@ -47,21 +42,13 @@ ENV DEFAULT_JAVA_OPTS="-Djava.security.egd=file:///dev/./urandom"
WORKDIR /var/lib/ohdsi/webapi

COPY --from=builder /code/opentelemetry-javaagent.jar .

# deploy the just built OHDSI WebAPI war file
# copy resources in order of fewest changes to most changes.
# This way, the libraries step is not duplicated if the dependencies
# do not change.
COPY --from=builder /code/war/WEB-INF/lib*/* WEB-INF/lib/
COPY --from=builder /code/war/org org
COPY --from=builder /code/war/WEB-INF/classes WEB-INF/classes
COPY --from=builder /code/war/META-INF META-INF
COPY --from=builder /code/target/WebAPI.jar .

EXPOSE 8080

USER 101

# Directly run the code as a WAR.
# Run the executable JAR
CMD exec java ${DEFAULT_JAVA_OPTS} ${JAVA_OPTS} \
-cp ".:WebAPI.jar:WEB-INF/lib/*.jar${CLASSPATH}" \
org.springframework.boot.loader.WarLauncher
--add-opens java.naming/com.sun.jndi.ldap=ALL-UNNAMED \
-jar WebAPI.jar
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ The API Documentation is found at [http://webapidoc.ohdsi.org/](http://webapidoc

Documentation can be found a the [Web API Installation Guide](https://github.com/OHDSI/WebAPI/wiki) which covers the system requirements and installation instructions.

## JAR Build (Executable)

WebAPI can also be built as a self-contained executable JAR with embedded Tomcat:

```bash
# Build as JAR
mvn clean package -DskipTests -Dpackaging.type=jar

# Run
java -jar target/WebAPI.jar --spring.profiles.active=webapi-postgresql
```

## SAML Auth support

The following parameters are used:
Expand Down Expand Up @@ -82,20 +94,20 @@ It was chosen to use embedded PG instead of H2 for unit tests since H2 doesn't s

To start the application locally, the following quick steps (all commands are executed from repository root directory)

1. Ensure that you have the following tools installed: Java 1.8, maven (check via `mvn -v`), docker-ce (check via `docker -v`), psql command line client
1. Ensure that you have the following tools installed: Java 1.8, maven (check via `mvn -v`), docker-ce (check via `docker -v`), psql command line client
(check via psql --version) or other tool that allows to connect to postgres DB.
2. Run `mvn clean install` and make sure it completes successfully, resolve dependency issues if any.
3. Create a new database in docker: `docker create --name postgres-webapi -p 8432:5432 -e POSTGRES_PASSWORD=ohdsi postgres:15.0-alpine`.
4. Start DB container: `docker start postgres-webapi`.
Verify that you can connect via psql console (`PGPASSWORD='ohdsi' psql -d postgresql://localhost:8432/?user=postgres`).
5. If your default java version is too high (e.g. 17), set JAVA_HOME to point to 1.8 installaction, for example `export JAVA_HOME=/usr/lib/jvm/zulu8-ca-amd64`
5. If your default java version is too high (e.g. 17), set JAVA_HOME to point to 1.8 installaction, for example `export JAVA_HOME=/usr/lib/jvm/zulu8-ca-amd64`
6. Start WebAPI `mvn clean install spring-boot:run -Dmaven.test.skip=true -P webapi-postgresql -s src/dev/settings.xml -f pom.xml`
7. Log in with the username of your liking
8. Grant this newly created user admin privileges by running the following sql `INSERT INTO sec_user_role (user_id, role_id, origin) VALUES (1000, 2, 'SYSTEM');`
and log in again.

At this point you have the application running and admin account operational. To actually use it, additional steps are required to set up privileges
and at least one CDM database. They are covered in the respective documentation sections.
At this point you have the application running and admin account operational. To actually use it, additional steps are required to set up privileges
and at least one CDM database. They are covered in the respective documentation sections.

## License
OHDSI WebAPI is licensed under Apache License 2.0
OHDSI WebAPI is licensed under Apache License 2.0
69 changes: 52 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

<groupId>org.ohdsi</groupId>
<artifactId>WebAPI</artifactId>
<packaging>war</packaging>
<packaging>${packaging.type}</packaging>
<version>3.0.0-SNAPSHOT</version>
<name>WebAPI</name>
<properties>
<packaging.type>war</packaging.type>
<build.number>${BUILD_NUMBER}</build.number>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Spring Boot manages spring.version as well -->
Expand Down Expand Up @@ -416,7 +417,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<!-- executable-war via 'java -jar WebAPI-exec.war' currently fails with Jersey FileNotFound exception. TODO -->
<configuration>
<!-- Since we filter properties files via Maven, do not add resources. -->
<addResources>false</addResources>
Expand Down Expand Up @@ -476,15 +476,6 @@
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down Expand Up @@ -689,16 +680,14 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>

<!-- We are intentionally overriding the Tomcat version from Spring Boot 1.5.22.RELEASE -->
<!-- and assuming tomcat-jdbc.jar will be in the Tomcat installation folder (\apache-tomcat-8.5.xxx\lib). -->
<!-- WebAPI.war.original should not contain overridden libraries -->
<!-- Embedded Tomcat dependencies for executable JAR -->
<!-- Note: WAR packaging is available via 'mvn package -Pwar' profile -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
Expand All @@ -711,7 +700,6 @@
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
Expand Down Expand Up @@ -779,12 +767,15 @@
</exclusion>
</exclusions>
</dependency> -->
<!-- javax.servlet-api is now provided by spring-boot-starter-tomcat (Jakarta Servlet API) -->
<!-- This old javax.servlet dependency can be removed for JAR packaging -->
<!--
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
Expand Down Expand Up @@ -1902,5 +1893,49 @@
</dependency>
</dependencies>
</profile>

<!-- WAR packaging profile - use with: mvn package -Pwar -->
<profile>
<id>war</id>
<properties>
<packaging.type>war</packaging.type>
</properties>
Comment thread
p-hoffmann marked this conversation as resolved.
<dependencies>
<!-- Mark embedded Tomcat as provided for external servlet container deployment -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>build-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<attachClasses>true</attachClasses>
<warName>WebAPI</warName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Comment thread
p-hoffmann marked this conversation as resolved.
</profile>
</profiles>
</project>
21 changes: 11 additions & 10 deletions src/main/java/org/ohdsi/webapi/WebApi.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.ohdsi.webapi;

import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;

Expand All @@ -15,25 +15,26 @@


/**
* Launch as java application or deploy as WAR (@link {@link WebApplication}
* will source this file).
* OHDSI WebAPI Spring Boot Application
*
* Supports both JAR and WAR deployment:
* - JAR: java -jar WebAPI.jar (embedded Tomcat)
* - WAR: Deploy to external servlet container (mvn package -Pwar)
*/
@EnableScheduling
@SpringBootApplication(exclude={HibernateJpaAutoConfiguration.class, ErrorMvcAutoConfiguration.class})
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class WebApi extends SpringBootServletInitializer {



@Override
protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
return application.sources(WebApi.class);
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(WebApi.class);
}

public static void main(final String[] args) throws Exception
{
TomcatURLStreamHandlerFactory.disable();
new SpringApplicationBuilder(WebApi.class).run(args);
SpringApplication.run(WebApi.class, args);
}

@PostConstruct
Expand Down
Loading