diff --git a/.dockerignore b/.dockerignore index 3559649..ea3a36a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ -.idea -node_modules -docker-compose.* +**/.idea +**/node_modules +**/docker-compose.* .dockerignore diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index a37992d..ccd18d6 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -28,8 +28,7 @@ jobs: - name: Run Sample App in Docker run: | cp .env.docker.example .env.docker && - npm run docker:up -- -d && - while ! nc -z localhost 4400; do sleep 1; done + npm run docker:e2e:up -- --wait - name: Install Chrome v111 uses: browser-actions/setup-chrome@v1 diff --git a/docker-compose.local-dist.yml b/docker-compose.local-dist.yml new file mode 100644 index 0000000..7b24a77 --- /dev/null +++ b/docker-compose.local-dist.yml @@ -0,0 +1,9 @@ +services: + metabase: + volumes: + - type: bind + source: ./local-dist/metabase.jar + target: /app/metabase.jar + read_only: true + bind: + create_host_path: false diff --git a/docker-compose.yml b/docker-compose.yml index 8b53042..85558d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,8 @@ services: metabase: - build: - context: . - dockerfile: metabase/Dockerfile + image: metabase/metabase-enterprise:v1.55.x environment: - MB_CONFIG_FILE_PATH: "./app/init-config.yml" + MB_CONFIG_FILE_PATH: "./app/config.yml" MB_JETTY_PORT: "${MB_PORT}" MB_EDITION: "ee" MB_SITE_URL: "http://localhost:${MB_PORT}/" @@ -19,6 +17,8 @@ services: retries: 10 ports: - "${MB_PORT}:${MB_PORT}" + volumes: + - ./metabase/config.yml:/app/config.yml next-sample-app-router: depends_on: @@ -38,6 +38,11 @@ services: NEXT_PUBLIC_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}" METABASE_INSTANCE_URL: "http://metabase:${MB_PORT}" METABASE_JWT_SHARED_SECRET: "${METABASE_JWT_SHARED_SECRET}" + healthcheck: + test: curl --fail -X GET -I "http://localhost:${CLIENT_PORT_APP_ROUTER}/" || exit 1 + interval: 2s + timeout: 2s + retries: 5 ports: - "${CLIENT_PORT_APP_ROUTER}:${CLIENT_PORT_APP_ROUTER}" volumes: @@ -51,7 +56,7 @@ services: context: . dockerfile: ./next-sample-pages-router/Dockerfile args: - PORT: "${CLIENT_PORT_APP_ROUTER}" + PORT: "${CLIENT_PORT_PAGES_ROUTER}" NEXT_PUBLIC_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}" METABASE_INSTANCE_URL: "http://metabase:${MB_PORT}" METABASE_JWT_SHARED_SECRET: "${METABASE_JWT_SHARED_SECRET}" @@ -61,6 +66,11 @@ services: NEXT_PUBLIC_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}" METABASE_INSTANCE_URL: "http://metabase:${MB_PORT}" METABASE_JWT_SHARED_SECRET: "${METABASE_JWT_SHARED_SECRET}" + healthcheck: + test: curl --fail -X GET -I "http://localhost:${CLIENT_PORT_PAGES_ROUTER}/" || exit 1 + interval: 2s + timeout: 2s + retries: 5 ports: - "${CLIENT_PORT_PAGES_ROUTER}:${CLIENT_PORT_PAGES_ROUTER}" volumes: diff --git a/metabase/Dockerfile b/metabase/Dockerfile deleted file mode 100644 index d2250c1..0000000 --- a/metabase/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM metabase/metabase-enterprise:v1.55.x - -COPY ./metabase /app/ -COPY ./local-dist /app/local-dist - -RUN if [ -f ./app/local-dist/metabase.jar ]; then \ - echo "Local metabase.jar is found in ./app/local-dist, running it..."; \ - cp ./app/local-dist/metabase.jar /app/metabase.jar; \ - else \ - echo "Local metabase.jar is not found in ./app/local-dist, skipping copy"; \ - fi diff --git a/metabase/init-config.yml b/metabase/config.yml similarity index 100% rename from metabase/init-config.yml rename to metabase/config.yml diff --git a/package.json b/package.json index fe46897..3487996 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "scripts": { "start": "npm run docker:up", "docker:up": "docker compose --env-file .env.docker up", - "docker:down": "docker compose --env-file .env.docker down --rmi all --volumes" + "docker:e2e:up": "yarn docker:up", + "docker:local-dist:up": "docker compose -f docker-compose.yml -f docker-compose.local-dist.yml --env-file .env.docker up", + "docker:down": "docker compose --env-file .env.docker down", + "docker:rm": "yarn docker:down --rmi all --volumes" } } diff --git a/readme.md b/readme.md index 59b70c7..ff2c392 100644 --- a/readme.md +++ b/readme.md @@ -31,14 +31,21 @@ This option should be used if you don't want to test Metabase Embedding SDK with From the root directory: - Copy `.env.docker.example` to `.env.docker` and replace `` with your premium embedding token -- Start all services in Docker with `yarn start` +- Start all services in Docker with `yarn docker:up` It will: -- poll a Metabase image and run it -- build and run both `next-sample-app-router` and `next-sample-pages-router` apps +- Poll a Metabase image and run it +- Build and run containers with both `next-sample-app-router` and `next-sample-pages-router` apps and run it The pages router sample will start on port 4401 and the app router sample will start on port 4400. +#### Local development (For Metabase developers) + +- To run containers with a locally built `metabase.jar`, copy it to the `./local-dist` folder as `./local-dist/metabase.jar`. +- To run containers with a locally built Embedding SDK package, copy it to the `./local-dist` folder as `./local-dist/embedding-sdk`. +- Run `yarn docker:local-dist:up` to start containers and use locally built dist from the `./local-dist` folder. +- To remove containers and images completely run `yarn docker:rm`. + ## Authentication Both apps provide an endpoint for user authentication, replace the logic to match your authentication system.