Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinRay97 committed Jul 3, 2024
1 parent 180f013 commit 720a1c0
Show file tree
Hide file tree
Showing 9 changed files with 720 additions and 799 deletions.
24 changes: 19 additions & 5 deletions ndc-cli.dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
FROM registry.access.redhat.com/ubi9/openjdk-17:1.18-4
# Build stage
FROM registry.access.redhat.com/ubi9/openjdk-21:1.20-2 AS build

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'

WORKDIR /app
COPY . /app
WORKDIR /build
COPY . /build

# Run Gradle build
USER root
RUN ./gradlew :ndc-cli:installDist --no-daemon --console=plain -x test

ENTRYPOINT ["/app/ndc-cli/build/install/ndc-cli/bin/ndc-cli"]
# Final stage
FROM registry.access.redhat.com/ubi9/openjdk-21:1.20-2

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
WORKDIR /app

# The "/app/output" directory is used by the NDC CLI "update" command as a bind-mount volume:
#
# docker run \
# -e HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH \
# -v ${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH}:/app/output
RUN mkdir -p /app/output && chmod 777 /app/output

COPY --from=build /build/ndc-cli/build/install/ndc-cli /app
ENTRYPOINT ["/app/bin/ndc-cli"]
23 changes: 20 additions & 3 deletions ndc-cli/src/main/kotlin/io/hasura/cli/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import picocli.CommandLine
import picocli.CommandLine.*
import java.io.File
import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermissions
import kotlin.system.exitProcess

enum class DatabaseType {
Expand Down Expand Up @@ -46,7 +48,7 @@ class CLI {
names = ["-d", "--database"],
description = ["Type of the database to introspect"]
)
database: DatabaseType?,
database: DatabaseType,
@Option(
names = ["-s", "--schemas"],
arity = "0..*",
Expand All @@ -57,7 +59,7 @@ class CLI {
schemas: List<String> = emptyList()
) {

val configGenerator = when (database ?: DatabaseType.ORACLE) {
val configGenerator = when (database) {
DatabaseType.ORACLE -> OracleConfigGenerator
DatabaseType.MYSQL -> MySQLConfigGenerator
DatabaseType.SNOWFLAKE -> SnowflakeConfigGenerator
Expand All @@ -68,7 +70,22 @@ class CLI {
schemas = schemas
)

mapper.writerWithDefaultPrettyPrinter().writeValue(File(outfile),config)
val file = File(outfile)
try {
mapper.writerWithDefaultPrettyPrinter().writeValue(file, config)
} catch (e: Exception) {
println("Error writing configuration to file: ${e.message}")

val parentDir = file.parentFile
val permissions = Files.getPosixFilePermissions(parentDir.toPath())
val posixPermissions = PosixFilePermissions.toString(permissions)

println("Parent directory: ${parentDir.absolutePath}")
println("Readable: ${parentDir.canRead()}, Writable: ${parentDir.canWrite()}")
println("Permissions: $posixPermissions")

exitProcess(1)
}
}

companion object {
Expand Down
11 changes: 5 additions & 6 deletions ndc-connector-mysql/.hasura-connector/connector-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
packagingDefinition:
type: PrebuiltDockerImage
dockerImage: "ndc-jvm-cli:v1"
dockerImage: "ghcr.io/hasura/ndc-jvm-mysql:v0.1.0-test.2"
supportedEnvironmentVariables:
- name: HASURA_JDBC_URL
- name: JDBC_URL
description: "The JDBC URL to connect to the database"
commands:
update: |
docker run \
-e HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH \
-v ${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH}:/app/output \
ndc-jvm-cli:v1 update $HASURA_JDBC_URL \
ghcr.io/hasura/ndc-jvm-cli:v0.1.0-test.2 update $JDBC_URL \
--database MYSQL \
--schemas $HASURA_JDBC_SCHEMAS \
--outfile /app/output/configuration.json
--schemas $JDBC_SCHEMAS \
--outfile /app/output/configuration.json
4 changes: 2 additions & 2 deletions ndc-connector-mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ documentation [here](https://hasura.io/docs/3.0/getting-started/connect-to-data/
Add your credentials to `my_subgraph/connector/my_sql/.env.local`

```env title="my_subgraph/connector/my_mysql/.env.local"
HASURA_JDBC_URL="jdbc:MySQL:thin:@//host.docker.internal:1521/XE?user=<user>&password=<password>"
JDBC_URL="jdbc:MySQL:thin:@//host.docker.internal:1521/XE?user=<user>&password=<password>"
```

### 3. Intropsect your indices
### 3. Introspect your indices

```bash title="From the root of your project run:"
ddn connector introspect --connector my_subgraph/connector/my_mysql/connector.yaml
Expand Down
10 changes: 5 additions & 5 deletions ndc-connector-oracle/.hasura-connector/connector-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
packagingDefinition:
type: PrebuiltDockerImage
dockerImage: "ndc-jvm-cli:v1"
dockerImage: "ghcr.io/hasura/ndc-jvm-oracle:v0.1.0-test.2"
supportedEnvironmentVariables:
- name: HASURA_JDBC_URL
- name: JDBC_URL
description: "The JDBC URL to connect to the database"
- name: HASURA_JDBC_SCHEMAS
- name: JDBC_SCHEMAS
description: "A comma-separated list of schemas to include in the metadata"
commands:
update: |
docker run \
-e HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH \
-v ${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH}:/app/output \
ndc-jvm-cli:v1 update $HASURA_JDBC_URL \
ghcr.io/hasura/ndc-jvm-cli:v0.1.0-test.2 update $JDBC_URL \
--database ORACLE \
--schemas $HASURA_JDBC_SCHEMAS \
--schemas $JDBC_SCHEMAS \
--outfile /app/output/configuration.json
4 changes: 2 additions & 2 deletions ndc-connector-oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ documentation [here](https://hasura.io/docs/3.0/getting-started/connect-to-data/
Add your credentials to `my_subgraph/connector/my_sql/.env.local`

```env title="my_subgraph/connector/my_oracle/.env.local"
HASURA_JDBC_URL="jdbc:oracle:thin:@//host.docker.internal:1521/XE?user=<user>&password=<password>"
JDBC_URL="jdbc:oracle:thin:@//host.docker.internal:1521/XE?user=<user>&password=<password>"
```

### 3. Intropsect your indices
### 3. Introspect your indices

```bash title="From the root of your project run:"
ddn connector introspect --connector my_subgraph/connector/my_oracle/connector.yaml
Expand Down
Loading

0 comments on commit 720a1c0

Please sign in to comment.