Skip to content

Commit 05407bb

Browse files
authored
feat: Add package command (#194)
Fixes cloudquery/cloudquery-issues#790
1 parent 5f42036 commit 05407bb

File tree

18 files changed

+564
-4
lines changed

18 files changed

+564
-4
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ jobs:
1919
distribution: "temurin"
2020
java-version: "18"
2121
cache: "gradle"
22+
- # Required for the package command tests to work
23+
name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
2225
- name: Validate Gradle wrapper
2326
uses: gradle/wrapper-validation-action@63d15e7a1e697b1de6f3ba0507106f89100c8518
2427
- name: Build package
2528
run: ./gradlew build
2629
env:
2730
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
GITHUB_ACTOR: ${{ github.actor }}
2832
- name: Publish Test Report
2933
uses: mikepenz/action-junit-report@v4
3034
if: success() || failure() # always run even if the previous step fails

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ build
3232
# Intellij
3333
.idea
3434
.cq
35+
36+
dist

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM --platform=$BUILDPLATFORM gradle:8.3-jdk20 as build
2+
ARG GITHUB_ACTOR
3+
ARG GITHUB_TOKEN
4+
5+
WORKDIR /code
6+
7+
COPY . .
8+
9+
RUN gradle jar --no-daemon
10+
11+
FROM eclipse-temurin:20-jre
12+
13+
COPY --from=build /code/lib/build/libs/*.jar /app/app.jar
14+
15+
EXPOSE 7777
16+
17+
ENV _JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED"
18+
19+
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
20+
21+
CMD [ "serve", "--address", "localhost:7777", "--log-format", "json", "--log-level", "info" ]

docs/overview.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# MemDB Plugin
2+
3+
Test docs for the MemDB plugin.

lib/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies {
4040
implementation 'io.cloudquery:plugin-pb-java:0.0.15'
4141
implementation 'org.apache.arrow:arrow-memory-core:12.0.1'
4242
implementation 'org.apache.arrow:arrow-vector:12.0.1'
43+
implementation 'commons-io:commons-io:2.15.1'
4344

4445
implementation "com.fasterxml.jackson.core:jackson-core:2.16.1"
4546
implementation "com.fasterxml.jackson.core:jackson-annotations:2.16.1"
@@ -77,6 +78,17 @@ java {
7778
}
7879
}
7980

81+
jar {
82+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
83+
manifest {
84+
attributes "Main-Class": "io.cloudquery.MainClass"
85+
}
86+
87+
from {
88+
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
89+
}
90+
}
91+
8092
publishing {
8193
repositories {
8294
maven {

lib/src/main/java/io/cloudquery/memdb/MemDB.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.cloudquery.plugin.ClientNotInitializedException;
66
import io.cloudquery.plugin.NewClientOptions;
77
import io.cloudquery.plugin.Plugin;
8+
import io.cloudquery.plugin.PluginKind;
89
import io.cloudquery.plugin.TableOutputStream;
910
import io.cloudquery.scheduler.Scheduler;
1011
import io.cloudquery.schema.ClientMeta;
@@ -88,6 +89,8 @@ public void resolve(
8889

8990
public MemDB() {
9091
super("memdb", "0.0.1");
92+
setTeam("cloudquery");
93+
setKind(PluginKind.Source);
9194
}
9295

9396
@Override
@@ -144,12 +147,14 @@ public void close() {
144147

145148
@Override
146149
public ClientMeta newClient(String spec, NewClientOptions options) throws Exception {
147-
this.spec = Spec.fromJSON(spec);
148150
this.allTables = getTables();
149151
Tables.transformTables(this.allTables);
150152
for (Table table : this.allTables) {
151153
table.addCQIDs();
152154
}
155+
if (!options.isNoConnection()) {
156+
this.spec = Spec.fromJSON(spec);
157+
}
153158
return new MemDBClient();
154159
}
155160
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.cloudquery.plugin;
2+
3+
public enum BuildArch {
4+
AMD64("amd64"),
5+
ARM64("arm64");
6+
7+
public final String arch;
8+
9+
private BuildArch(String arch) {
10+
this.arch = arch;
11+
}
12+
13+
public String toString() {
14+
return this.arch;
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.cloudquery.plugin;
2+
3+
public enum BuildOS {
4+
Windows("windows"),
5+
Linux("linux"),
6+
Darwin("darwin");
7+
8+
public final String os;
9+
10+
private BuildOS(String os) {
11+
this.os = os;
12+
}
13+
14+
public String toString() {
15+
return this.os;
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.cloudquery.plugin;
2+
3+
import lombok.Getter;
4+
import lombok.NonNull;
5+
import lombok.RequiredArgsConstructor;
6+
7+
@RequiredArgsConstructor
8+
@Getter
9+
public class BuildTarget {
10+
@NonNull protected final BuildOS os;
11+
@NonNull protected final BuildArch arch;
12+
}

lib/src/main/java/io/cloudquery/plugin/Plugin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@
1717
public abstract class Plugin {
1818
@NonNull protected final String name;
1919
@NonNull protected final String version;
20+
2021
@Setter protected Logger logger;
2122
@Setter protected String jsonSchema;
23+
24+
@Setter protected String team;
25+
@Setter protected PluginKind kind;
26+
@Setter protected String dockerfile = "Dockerfile";
27+
28+
@Setter
29+
protected BuildTarget[] buildTargets =
30+
new BuildTarget[] {
31+
new BuildTarget(BuildOS.Linux, BuildArch.ARM64),
32+
new BuildTarget(BuildOS.Linux, BuildArch.AMD64),
33+
};
34+
2235
protected ClientMeta client;
2336

2437
public void init(String spec, NewClientOptions options) throws Exception {

0 commit comments

Comments
 (0)