Skip to content

Commit

Permalink
docker image (#7)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
qinfchen authored Jul 27, 2018
1 parent cfa7f2b commit cd0af7b
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 27 deletions.
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,3 +70,7 @@ workflows:
filters:
tags:
only: /.*/
- publish-docker:
requires:
- build
filters: { tags: { only: /.*/ } }
Empty file added .nojekyll
Empty file.
61 changes: 34 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
name: '',
repo: ''
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
18 changes: 18 additions & 0 deletions scripts/build_docker.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit cd0af7b

Please sign in to comment.