From cd0af7b348fde48dbe906e0551101701488a438e Mon Sep 17 00:00:00 2001 From: Qinfeng Chen Date: Fri, 27 Jul 2018 15:40:00 +0100 Subject: [PATCH] docker image (#7) * publish docker image * fix working dir * circle ci change * fix docker, docsify, update readme * comments and update readme * fix build scripts * update readme * remove apk cache --- .circleci/config.yml | 24 ++++++++++++++++ .nojekyll | 0 README.md | 61 +++++++++++++++++++++++------------------ index.html | 21 ++++++++++++++ scripts/Dockerfile | 13 +++++++++ scripts/build_docker.sh | 18 ++++++++++++ 6 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 .nojekyll create mode 100644 index.html create mode 100644 scripts/Dockerfile create mode 100755 scripts/build_docker.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 72f8b663..71b15422 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,6 +41,26 @@ jobs: - store_artifacts: path: ~/poms + publish-docker: + docker: + - image: circleci/openjdk:8u171-jdk + 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 palantir/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 palantir/recipe-example-server:$(git describe --tags --always --first-parent) + docker push palantir/recipe-example-server:latest + fi workflows: version: 2 @@ -50,3 +70,7 @@ workflows: filters: tags: only: /.*/ + - publish-docker: + requires: + - build + filters: { tags: { only: /.*/ } } diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/README.md b/README.md index 364be076..b493f41a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# conjure-java-example +s# conjure-java-example A small recipe application that demonstrates the simple usage of conjure tooling. ## Overview -#### Tools and Libraries +### Tools and Libraries This example project uses the following tools and libraries, please consult their respective documentation for more information. @@ -16,7 +16,7 @@ This example project uses the following tools and libraries, please consult thei * [gradle-baseline](https://github.com/palantir/gradle-baseline) - a gradle plugin for configuring code quality tools in builds and projects. * [dropwizard](https://www.dropwizard.io/1.3.5/docs/) - a simple framework for building web services -#### Project Structure +### Project Structure * `recipe-example-api` - a sub-project that defines recipe-example APIs in Conjure and generates both java and typescript bindings. @@ -48,25 +48,8 @@ This example project uses the following tools and libraries, please consult thei ├── recipe-example-server │   ├── build.gradle │   ├── src - │   │   ├── main - │   │   │   └── java - │   │   │   └── com - │   │   │   └── palantir - │   │   │   └── conjure - │   │   │   └── examples - │   │   │   ├── RecipeBookApplication.java - │   │   │   ├── RecipeBookConfiguration.java - │   │   │   └── resources - │   │   │   └── RecipeBookResource.java - │   │   └── test - │   │   ├── java - │   │   │   └── com - │   │   │   └── palantir - │   │   │   └── conjure - │   │   │   └── examples - │   │   │   └── RecipeBookApplicationTest.java - │   │   └── resources - │   │   └── test.yml + │   │   ├── main/java + │   │   └── test/java │   └── var │   └── conf │   └── recipes.yml @@ -82,22 +65,22 @@ This example project uses the following tools and libraries, please consult thei ## Development -#### Useful Gradle Commands: +### Useful Gradle Commands: * `./gradlew tasks` for tasks available in this project. * `./gradlew idea` for IntelliJ * `./gradlew eclipse` for Eclipse * `./gradlew run` for running the server or use IDE to debug it -#### Generate New or Modify Existing APIs +### Generate New or Modify Existing APIs -##### Modify existing APIs +#### Modify existing APIs To modify the existing bindings in this project: 1. Make changes to the `recipe-example-api/src/main/conjure/recipe-api.yml` file 2. Run `./gradlew compileConjure` or a more specific task such as `./gradlew compileConjureObjects`, to check if the changes compile 3. Or run `./gradlew idea` or `./gradlew eclipse` to update the bindings for your IDE -##### Generate new binding for a different language +#### Generate new binding for a different language To generate bindings for a new language. Note that currently `gradle-conjure` plugin only supports generation of java, typescript, and python bindings. 1. Add a new sub project under `recipe-example-api` by modifying the `settings.gradle` file. ```diff @@ -112,7 +95,7 @@ To generate bindings for a new language. Note that currently `gradle-conjure` pl ``` 4. run `./gradlew compileConjure` to generate new bindings for python. -##### Generate Java retrofit interfaces +#### Generate Java retrofit interfaces Similar to how we add the conjure generation for python above, we can add a new project to generate java retrofit interfaces 1. add a new sub project under `recipe-example-api` by modifying the `settings.gradle` file. ```diff @@ -122,3 +105,27 @@ Similar to how we add the conjure generation for python above, we can add a new ``` 2. Optional: use the gradle script `configure` closure in `recipe-example-api/build.gradle` to configure project specific settings for the new sub project. 3. run `./gradlew compileConjureRetrofit` to generate new bindings for python. + +### Writing Clients + +Please see the following subsections for examples of writing recipe clients in different languages. To dev against this recipe application, you can either run the server locally via `./gradlew run` or spin up a docker container using the `palantir/recipe-example-server:latest` image. + +#### Java client +The tests in `recipe-example-server/src/test/java` illustrate simple examples of how you would use a vanilla feign client to interact with the application. E.g. + + ``` + Feign client = Feign.builder() + .contract(new JAXRSContract()) + .client(new Client.Default(null, null)) + .encoder(new JacksonEncoder()) + .decoder(new JacksonDecoder()) + .target(RecipeBookService.class, + String.format("http://localhost:%d/examples/api/", RULE.getLocalPort())); + + Recipe recipe = client.getRecipe(recipeName); + ``` +#### Typescript client +Please refer to [conjure-typescript-example](https://github.com/palantir/conjure-typescript-example) for an example implementation. + +#### TODO add conjure-java runtime example +#### TODO add tracing example diff --git a/index.html b/index.html new file mode 100644 index 00000000..f48a9142 --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + Document + + + + + + +
+ + + + diff --git a/scripts/Dockerfile b/scripts/Dockerfile new file mode 100644 index 00000000..92588e0a --- /dev/null +++ b/scripts/Dockerfile @@ -0,0 +1,13 @@ +FROM java:8u111-jdk-alpine + +RUN set -eux; \ + mkdir -p /opt/palantir/services; + +ADD recipe-example-server/ /opt/palantir/services/recipe-example-server + +RUN chmod +x /opt/palantir/services/recipe-example-server/bin/recipe-example-server + +EXPOSE 8000 + +WORKDIR /opt/palantir/services/recipe-example-server/ +ENTRYPOINT ["./bin/recipe-example-server", "server", "var/conf/recipes.yml"] diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh new file mode 100755 index 00000000..0ce3d0d2 --- /dev/null +++ b/scripts/build_docker.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -ex +cd "$(dirname "${BASH_SOURCE[0]}" )"/.. + +VERSION=$(git describe --tags --always --first-parent) +DEST=build/docker + +rm -rf $DEST +mkdir -p $DEST/recipe-example-server/var/conf + +cp ./scripts/Dockerfile $DEST/ +tar -xf "./recipe-example-server/build/distributions/recipe-example-server-${VERSION}.tar" -C $DEST/recipe-example-server --strip-components=1 +cp ./recipe-example-server/var/conf/recipes.yml $DEST/recipe-example-server/var/conf + +cd $DEST +docker build -t "palantir/recipe-example-server:$VERSION" . +docker tag "palantir/recipe-example-server:$VERSION" "palantir/recipe-example-server:latest" +