-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Joaquin Colacci <[email protected]> Co-authored-by: metamben <[email protected]>
- Loading branch information
1 parent
3493e59
commit 54c7e18
Showing
16 changed files
with
577 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{:aliases | ||
{:user/materialize | ||
{:extra-paths ["PWD/modules/drivers/materialize/test"] | ||
:extra-deps {metabase/materialize {:local/root "PWD/modules/drivers/materialize"}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- "**.md" | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Metabase Repo | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: metabase/metabase | ||
ref: v0.46.7 | ||
|
||
- name: Checkout Driver Repo | ||
uses: actions/checkout@v3 | ||
with: | ||
path: modules/drivers/materialize | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: temurin | ||
java-version: 11 | ||
|
||
- name: Add Materialize TLS instance to /etc/hosts | ||
run: | | ||
sudo echo "127.0.0.1 materialize" | sudo tee -a /etc/hosts | ||
- name: Start Materialize in Docker | ||
uses: isbang/[email protected] | ||
with: | ||
compose-file: "modules/drivers/materialize/docker-compose.yml" | ||
services: | | ||
materialize | ||
init | ||
# Apply the scripts/exclude_tests.diff patch to exclude tests that are not relevant to Materialize | ||
- name: Apply exclude_tests.diff | ||
run: | | ||
git apply modules/drivers/materialize/scripts/exclude_tests.diff | ||
- name: Install Clojure CLI | ||
run: | | ||
curl -O https://download.clojure.org/install/linux-install-1.11.1.1262.sh && | ||
sudo bash ./linux-install-1.11.1.1262.sh | ||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "16" | ||
cache: "yarn" | ||
|
||
- name: Get M2 cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.m2 | ||
~/.gitlibs | ||
key: ${{ runner.os }}-materialize-${{ hashFiles('**/deps.edn') }} | ||
|
||
- name: Prepare stuff for pulses | ||
run: yarn build-static-viz | ||
|
||
# Use custom deps.edn containing "user/materialize" alias to include driver sources | ||
- name: Run tests | ||
run: | | ||
mkdir -p /home/runner/.config/clojure | ||
cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" > /home/runner/.config/clojure/deps.edn | ||
DRIVERS=materialize clojure -X:dev:drivers:drivers-dev:test:user/materialize | ||
- name: Build Materialize driver | ||
run: | | ||
echo "{:deps {metabase/materialize {:local/root \"materialize\" }}}" > modules/drivers/deps.edn | ||
bin/build-driver.sh materialize | ||
ls -lah resources/modules | ||
- name: Archive driver JAR | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: materialize.metabase-driver.jar | ||
path: resources/modules/materialize.metabase-driver.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/target | ||
.clj-kondo/ | ||
.lsp/ | ||
.cpcache/ | ||
.build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
## Getting started | ||
|
||
* Please report any issues you encounter during operations. | ||
* Feel free to create a pull request, preferably with a test or five. | ||
|
||
## Setting up a development environment | ||
|
||
### Requirements | ||
|
||
* Clojure 1.11+ | ||
* OpenJDK 17 | ||
* Node.js 16.x | ||
* Yarn | ||
|
||
For testing: Docker Compose | ||
|
||
Please refer to the extensive documentation available on the Metabase website: [Guide to writing a Metabase driver](https://www.metabase.com/docs/latest/developers-guide/drivers/start.html) | ||
|
||
Materialize driver's code should be inside the main Metabase repository checkout in `modules/drivers/materialize` directory. | ||
|
||
The easiest way to set up a development environment is as follows (mostly the same as in the [CI](https://github.com/MaterializeInc/metabase-materialize-driver/blob/master/.github/workflows/tests.yml)): | ||
|
||
* Clone Metabase and Materialize driver repositories | ||
```bash | ||
git clone https://github.com/metabase/metabase.git | ||
cd metabase | ||
checkout v0.46.7 | ||
git clone https://github.com/MaterializeInc/metabase-materialize-driver.git modules/drivers/materialize | ||
``` | ||
|
||
* Create custom Clojure profiles, you can get it using the following command: | ||
|
||
```bash | ||
cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" | tr -d '\n' | ||
``` | ||
|
||
Modifying `~/.clojure/deps.edn` will create two useful profiles: `user/materialize` that adds driver's sources to the classpath, and `user/test` that includes all the Metabase tests that are guaranteed to work with the driver. | ||
|
||
* Install the Metabase dependencies: | ||
|
||
```bash | ||
clojure -X:deps:drivers prep | ||
``` | ||
|
||
* Build the frontend: | ||
|
||
```bash | ||
yarn && yarn build-static-viz | ||
``` | ||
|
||
* Add `/etc/hosts` entry | ||
|
||
Required for TLS tests. | ||
|
||
```bash | ||
sudo -- sh -c "echo 127.0.0.1 materialize >> /etc/hosts" | ||
``` | ||
|
||
* Start Materialize as a Docker container | ||
|
||
```bash | ||
docker compose -f modules/drivers/materialize/docker-compose.yml up -d materialize init | ||
``` | ||
|
||
Now, you should be able to run the tests: | ||
|
||
```bash | ||
mz_deps=$(cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" | tr -d '\n') | ||
DRIVERS=materialize clojure -Sdeps ${mz_deps} -X:dev:drivers:drivers-dev:test:user/materialize | ||
``` | ||
|
||
you can see that we have our profiles `:user/materialize:user/test` added to the command above, and with `DRIVERS=materialize` we instruct Metabase to run the tests only for Materialize. | ||
|
||
> **Note** Omitting `DRIVERS` will run the tests for all the built-in database drivers. | ||
If you want to run tests for only a specific test: | ||
|
||
```bash | ||
mz_deps=$(cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" | tr -d '\n') | ||
DRIVERS=materialize clojure -Sdeps ${mz_deps} -X:dev:drivers:drivers-dev:test:user/materialize :only metabase.query-processor.middleware.parameters.mbql-test | ||
``` | ||
|
||
## Building a jar | ||
|
||
You need to add an entry for Materialize in `modules/drivers/deps.edn` | ||
|
||
```clj | ||
{:deps | ||
{... | ||
metabase/materialize {:local/root "materialize"} | ||
...}} | ||
``` | ||
|
||
or just run this from the root Metabase directory, overwriting the entire file: | ||
|
||
```bash | ||
echo "{:deps {metabase/materialize {:local/root \"materialize\" }}}" > modules/drivers/deps.edn | ||
``` | ||
|
||
Now, you should be able to build the final jar: | ||
|
||
```bash | ||
bin/build-driver.sh materialize | ||
``` | ||
|
||
As the result, `resources/modules/materialize.metabase-driver.jar` should be created. | ||
|
||
For smoke testing, there is a Metabase with the link to the driver available as a Docker container: | ||
|
||
```bash | ||
docker compose -f modules/drivers/materialize/docker-compose.yml up -d metabase | ||
``` | ||
|
||
It should pick up the driver jar as a volume. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
ARG METABASE_VERSION=latest | ||
FROM metabase/metabase:${METABASE_VERSION} | ||
|
||
ADD target/dist/materialize-driver.jar /plugins/ | ||
ADD .build/materialize-driver.jar /plugins/ | ||
RUN chmod 744 /plugins/materialize-driver.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.