Skip to content

Commit

Permalink
fix build and drop dropwizard in favour of undertow (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmsf authored Nov 16, 2021
1 parent 9eae414 commit c02bf7b
Show file tree
Hide file tree
Showing 31 changed files with 490 additions and 361 deletions.
55 changes: 36 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/openjdk:8u171-jdk-node-browsers
- image: cimg/openjdk:15.0.2-node
environment:
GRADLE_OPTS: -Dorg.gradle.console=plain -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
steps:
Expand All @@ -23,7 +23,20 @@ jobs:
paths:
- ~/.gradle/caches

- run: ./gradlew --parallel build
- run: ./gradlew --parallel build -x test

- run:
name: run the server in background so tests in the next step have something to hit.
command: |
./gradlew run
background: true

- run:
name: wait till the server is operational before running the tests
command: |
sleep 30
- run: ./gradlew test

- run:
command: |
Expand All @@ -43,24 +56,28 @@ jobs:
path: ~/poms
publish-docker:
docker:
- image: circleci/openjdk:8u171-jdk
- image: cimg/openjdk:15.0.2-node
steps:
- setup_remote_docker
- checkout
- restore_cache:
key: gradle-wrapper-v2-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- restore_cache:
key: gradle-cache-v2-{{ checksum "versions.props" }}-{{ checksum "build.gradle" }}
- run: ./gradlew distTar
- run: ./scripts/build_docker.sh
- run: docker run palantirtechnologies/recipe-example-server:$(git describe --tags --always --first-parent) --help
- deploy:
command: |
if [[ "${CIRCLE_BRANCH}" == "develop" || "${CIRCLE_TAG}" =~ [0-9]+(\.[0-9]+)+(-[a-zA-Z]+[0-9]*)* ]]; then
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
docker push palantirtechnologies/recipe-example-server:$(git describe --tags --always --first-parent)
docker push palantirtechnologies/recipe-example-server:latest
fi
- setup_remote_docker
- checkout
- restore_cache:
key: gradle-wrapper-v2-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- restore_cache:
key: gradle-cache-v2-{{ checksum "versions.props" }}-{{ checksum "build.gradle" }}
- run: ./gradlew distTar
- run: ./scripts/build_docker.sh
- run:
name: This command actually doesn't do anything, just runs the server. We're keeping it here as an example.
command: |
docker run palantirtechnologies/recipe-example-server:$(git describe --tags --always --first-parent) --help
background: true
- deploy:
command: |
if [[ "${CIRCLE_BRANCH}" == "develop" || "${CIRCLE_TAG}" =~ [0-9]+(\.[0-9]+)+(-[a-zA-Z]+[0-9]*)* ]]; then
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
docker push palantirtechnologies/recipe-example-server:$(git describe --tags --always --first-parent)
docker push palantirtechnologies/recipe-example-server:latest
fi
workflows:
version: 2
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,29 @@ Recipe recipe = recipeBook.getRecipe(recipeName);

#### Typescript client
Please refer to [conjure-typescript-example](https://github.com/palantir/conjure-typescript-example) for an example implementation.


## Certificates
```
/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\
/!\ Please do not use these certificates in prod! /!\
/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\
```
The certificates presented with this server are an example so that the tests run in HTTPs. These were generated by following the steps below. All passwords are "changeit"

```
keytool -genkey -alias bmc -keyalg RSA -keystore keystore.jks -keysize 2048 -dname "CN=localhost,OU=AQ,O=AQ,C=AQ" -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -validity 3650
openssl req -new -x509 -keyout ca-key -out ca-cert
keytool -keystore KeyStore.jks -alias bmc -certreq -file cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 365 -CAcreateserial -passin pass:changeit
keytool -keystore KeyStore.jks -alias CARoot -import -file ca-cert
keytool -keystore KeyStore.jks -alias bmc -import -file cert-signed
keytool -keystore truststore.jks -alias bmc -import -file ca-cert
```
11 changes: 4 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
buildscript {
repositories {
repositories {
mavenCentral()
maven { url 'https://dl.bintray.com/palantir/releases/' }
maven { url 'https://plugins.gradle.org/m2/' }
}
gradlePluginPortal()
mavenCentral()
}

dependencies {
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.2.1'
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.4.0'
classpath 'com.palantir.javaformat:gradle-palantir-java-format:1.0.1'
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:1.25.0'
classpath 'com.palantir.baseline:gradle-baseline-java:2.49.2'
Expand All @@ -31,8 +28,8 @@ allprojects {

repositories {
mavenCentral()
maven { url 'https://dl.bintray.com/palantir/releases/' }
}

}

configure(subprojects - project(':recipe-example-api')) {
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-544.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: wip fix build
links:
- https://github.com/palantir/conjure-java-example/pull/544
4 changes: 4 additions & 0 deletions recipe-example-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ conjure {
typescript {
packageName = "conjure-recipe-example-api" // default package name is the project name, `recipe-example-api`
}

java {
undertowServicePrefixes = true
}
}
1 change: 1 addition & 0 deletions recipe-example-api/recipe-example-api-undertow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src/generated/java/
8 changes: 8 additions & 0 deletions recipe-example-api/src/main/conjure/configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
types:
definitions:
default-package: com.palantir.conjure.examples.recipe
objects:
Configuration:
fields:
port: integer
host: string
17 changes: 10 additions & 7 deletions recipe-example-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ dependencies {

implementation project(':recipe-example-api:recipe-example-api-objects')
implementation project(':recipe-example-api:recipe-example-api-jersey')
implementation project(':recipe-example-api:recipe-example-api-undertow')

implementation 'com.palantir.conjure.java:conjure-java-undertow-runtime'

implementation 'com.google.guava:guava'
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml"
implementation 'com.palantir.conjure.java.runtime:conjure-java-jackson-serialization'
implementation 'com.palantir.conjure.java.runtime:conjure-java-jersey-server'
implementation 'com.palantir.websecurity:dropwizard-web-security'
implementation 'io.dropwizard:dropwizard-core'
implementation 'com.palantir.conjure.java.runtime:keystores'
implementation 'com.palantir.conjure.java.api:ssl-config'

compile "org.slf4j:slf4j-simple"
implementation 'org.slf4j:slf4j-api'

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'io.dropwizard:dropwizard-testing'
testImplementation 'com.palantir.conjure.java.runtime:conjure-java-jaxrs-client'
testImplementation 'com.palantir.conjure.java.api:test-utils'
testImplementation 'org.junit.jupiter:junit-jupiter'

}

mainClassName = 'com.palantir.conjure.examples.RecipeBookApplication'

run {
args 'server', 'var/conf/recipes.yml'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.conjure.examples;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.palantir.conjure.examples.recipe.Configuration;
import java.io.File;
import java.io.IOException;

public final class ConfigurationLoader {

private ConfigurationLoader() {
// noop
}

public static Configuration load() throws IOException {
return ConfigurationLoader.load("var/conf/conf.yml");
}

public static Configuration load(String path) throws IOException {
ObjectMapper om = new ObjectMapper(new YAMLFactory());
return om.readValue(new File(path), Configuration.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,37 +16,73 @@

package com.palantir.conjure.examples;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableSet;
import com.palantir.conjure.examples.recipe.Configuration;
import com.palantir.conjure.examples.recipe.api.BakeStep;
import com.palantir.conjure.examples.recipe.api.Ingredient;
import com.palantir.conjure.examples.recipe.api.Recipe;
import com.palantir.conjure.examples.recipe.api.RecipeBookServiceEndpoints;
import com.palantir.conjure.examples.recipe.api.RecipeName;
import com.palantir.conjure.examples.recipe.api.RecipeStep;
import com.palantir.conjure.examples.recipe.api.Temperature;
import com.palantir.conjure.examples.recipe.api.TemperatureUnit;
import com.palantir.conjure.examples.resources.RecipeBookResource;
import com.palantir.conjure.java.serialization.ObjectMappers;
import com.palantir.conjure.java.server.jersey.ConjureJerseyFeature;
import com.palantir.websecurity.WebSecurityBundle;
import io.dropwizard.Application;
import io.dropwizard.jackson.DiscoverableSubtypeResolver;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

public final class RecipeBookApplication extends Application<RecipeBookConfiguration> {

public static void main(String[] args) throws Exception {
new RecipeBookApplication().run(args);
}
import com.palantir.conjure.java.api.config.ssl.SslConfiguration;
import com.palantir.conjure.java.config.ssl.SslSocketFactories;
import com.palantir.conjure.java.undertow.runtime.ConjureHandler;
import io.undertow.Handlers;
import io.undertow.Undertow;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Set;
import javax.net.ssl.SSLContext;

public final class RecipeBookApplication {

@Override
public void initialize(Bootstrap<RecipeBookConfiguration> bootstrap) {
ObjectMapper conjureObjectMapper = ObjectMappers.newServerObjectMapper()
// needs discoverable subtype resolver for DW polymorphic configuration mechanism
.setSubtypeResolver(new DiscoverableSubtypeResolver());
bootstrap.setObjectMapper(conjureObjectMapper);
bootstrap.addBundle(new WebSecurityBundle());
protected static final String KEY_STORE_PATH = "src/test/resources/certs/keystore.jks"; // password changeit
protected static final String TRUSTSTORE_PATH = "src/test/resources/certs/truststore.jks"; // password changeit

private RecipeBookApplication() {
// noop
}

@Override
public void run(RecipeBookConfiguration configuration, Environment environment) {
RecipeBookResource resource = new RecipeBookResource(configuration.getRecipes());
environment.jersey().register(resource);
public static void main(String[] _args) throws IOException {
Configuration conf = ConfigurationLoader.load();

SslConfiguration sslConfig =
SslConfiguration.of(Paths.get(TRUSTSTORE_PATH), Paths.get(KEY_STORE_PATH), "changeit");
SSLContext sslContext = SslSocketFactories.createSslContext(sslConfig);

Undertow server = Undertow.builder()
.addHttpsListener(conf.getPort(), conf.getHost(), sslContext)
.setHandler(Handlers.path()
.addPrefixPath(
"api/",
ConjureHandler.builder()
.services(RecipeBookServiceEndpoints.of(new RecipeBookResource(someRecipes())))
.build()))
.build();

server.start();
}

// must register ConjureJerseyFeature to map conjure error types.
environment.jersey().register(ConjureJerseyFeature.INSTANCE);
private static Set<Recipe> someRecipes() {
return ImmutableSet.of(
Recipe.builder()
.name(RecipeName.of("roasted broccoli with garlic"))
.steps(ImmutableSet.of(
RecipeStep.chop(Ingredient.valueOf("3 cloves of garlic")),
RecipeStep.mix(ImmutableSet.of(
Ingredient.of("2 tbsp extra olive oil"), Ingredient.of("chopped garlic"))),
RecipeStep.bake(BakeStep.of(Temperature.of(230, TemperatureUnit.CELSIUS), 1200))))
.build(),
Recipe.builder()
.name(RecipeName.of("baked potatoes"))
.steps(ImmutableSet.of(
RecipeStep.mix(ImmutableSet.of(
Ingredient.of("rub oil all over the potatoes"),
Ingredient.of("Rub salt all over the potatoes"))),
RecipeStep.bake(BakeStep.of(Temperature.of(220, TemperatureUnit.CELSIUS), 2700))))
.build());
}
}

This file was deleted.

Loading

0 comments on commit c02bf7b

Please sign in to comment.