Skip to content

Commit 065033e

Browse files
committed
feat: add dockerfile demo package
1 parent fd631c4 commit 065033e

4 files changed

Lines changed: 130 additions & 0 deletions

File tree

Demo/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!-- Demo/pom.xml -->
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>buttercms-demo</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<dependencies>
12+
<!-- Dependency on the local SDK project -->
13+
<dependency>
14+
<groupId>com.buttercms</groupId>
15+
<artifactId>buttercmsclient</artifactId>
16+
<version>1.12.1</version>
17+
</dependency>
18+
</dependencies>
19+
20+
<build>
21+
<plugins>
22+
<!-- Compile Java sources -->
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-compiler-plugin</artifactId>
26+
<version>3.8.1</version>
27+
<configuration>
28+
<source>1.8</source>
29+
<target>1.8</target>
30+
</configuration>
31+
</plugin>
32+
33+
<!-- Create an executable JAR with dependencies -->
34+
<plugin>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-assembly-plugin</artifactId>
37+
<version>3.3.0</version>
38+
<executions>
39+
<execution>
40+
<id>make-assembly</id>
41+
<phase>package</phase>
42+
<goals>
43+
<goal>single</goal>
44+
</goals>
45+
<configuration>
46+
<archive>
47+
<manifest>
48+
<mainClass>com.demo.Demo</mainClass>
49+
</manifest>
50+
</archive>
51+
<descriptorRefs>
52+
<descriptorRef>jar-with-dependencies</descriptorRef>
53+
</descriptorRefs>
54+
</configuration>
55+
</execution>
56+
</executions>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.demo;
2+
3+
import com.buttercms.ButterCMSClient;
4+
import com.buttercms.model.Page;
5+
import com.buttercms.model.PageResponse;
6+
import com.buttercms.model.PostResponse;
7+
import com.buttercms.model.Post;
8+
import com.demo.PageFields;
9+
10+
import java.util.Map;
11+
import java.util.HashMap;
12+
13+
14+
public class Demo {
15+
public static void main(String[] args) {
16+
String apiKey = System.getenv("API_KEY");
17+
if (apiKey == null || apiKey.isEmpty()) {
18+
System.out.println("API_KEY environment variable is not set");
19+
return;
20+
}
21+
22+
ButterCMSClient client = new ButterCMSClient(apiKey, true);
23+
24+
try {
25+
PageResponse<PageFields> pageResponse = client.getPage("*", "test-page-1", null, PageFields.class);
26+
Page<PageFields> page = pageResponse.getData();
27+
28+
System.out.println("Page Slug: " + page.getSlug());
29+
System.out.println("Page Status: " + page.getStatus());
30+
System.out.println("Page Scheduled date: " + page.getScheduled());
31+
} catch (Exception e) {
32+
System.out.println("Error fetching page: " + e.getMessage());
33+
}
34+
35+
try {
36+
PostResponse postResponse = client.getPost("test-blog-post");
37+
Post post = postResponse.getData();
38+
39+
System.out.println("Post Title: " + post.getTitle());
40+
System.out.println("Post Status: " + post.getStatus());
41+
System.out.println("Post Published date: " + post.getPublished());
42+
System.out.println("Post Scheduled date: " + post.getScheduled());
43+
} catch (Exception e) {
44+
System.out.println("Error fetching post: " + e.getMessage());
45+
}
46+
}
47+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.demo;
2+
3+
public class PageFields {
4+
public String title;
5+
public String description;
6+
}

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Stage 1: Build Java SDK and Demo
2+
FROM openjdk:8-jdk-alpine AS build_java
3+
4+
WORKDIR /src
5+
COPY . .
6+
RUN ./mvnw clean install -DskipTests
7+
RUN ./mvnw -f /src/Demo/pom.xml clean package -DskipTests
8+
9+
# Stage 2: Run the Demo
10+
FROM openjdk:8-jdk-alpine
11+
WORKDIR /app
12+
COPY --from=build_java /src/Demo/target/buttercms-demo-1.0.0-jar-with-dependencies.jar .
13+
14+
ENV API_BASE_URL=https://api.buttercms.com/v2
15+
ENV API_KEY=your_api_key
16+
17+
CMD ["java", "-jar", "buttercms-demo-1.0.0-jar-with-dependencies.jar"]

0 commit comments

Comments
 (0)