Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker compose configurations #11

Merged
merged 4 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
LOG_LEVEL=INFO
REDASH_API_BASE_URL=
REDASH_API_KEY=
NEXT_PUBLIC_REDASH__URL=${REDASH__URL}
OPEN_SEARCH__URL=http://localhost:9200
OPEN_SEARCH__USERNAME=admin
OPEN_SEARCH__PASSWORD=admin
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ web_modules/
.env.test.local
.env.production.local
.env.local
.env.docker

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# Redash Searcher

Web application for searching Redash queries.
Queries are stored in OpenSearch and synchronized with Redash periodically.

## Start Up

:pencil2: Copy `.env.sample` to `.env.docker` and edit it.

```console
cp .env.sample .env.docker
```

:rocket: Start up containers.

```console
docker compose up
```
29 changes: 27 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
opensearch-dashboards:
Expand All @@ -20,7 +20,7 @@ services:
- cluster.initial_master_nodes=main
- bootstrap.memory_lock=true
- http.host=0.0.0.0
- plugins.security.disabled=true
- plugins.security.ssl.http.enabled=false
- transport.host=127.0.0.1
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
Expand All @@ -37,6 +37,31 @@ services:
networks:
- redash-searcher

redash-searcher-sync:
restart: on-failure
build:
context: ./redash-searcher-sync
dockerfile: Dockerfile
env_file:
- .env.docker
depends_on:
- opensearch-node-main
networks:
- redash-searcher

redash-searcher-web:
restart: on-failure
build:
context: ./redash-searcher-web
dockerfile: Dockerfile
env_file:
- .env.docker
ports:
- 3000:3000
depends_on:
- redash-searcher-sync
networks:
- redash-searcher

volumes:
opensearch-node-main-data:
Expand Down
35 changes: 0 additions & 35 deletions redash-search-sync/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions redash-search-web/next-env.d.ts

This file was deleted.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "redash-search-sync"
name = "redash-searcher-sync"

edition = "2021"
version = "0.1.0"
Expand Down
41 changes: 41 additions & 0 deletions redash-searcher-sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ref: https://dev.to/rogertorres/first-steps-with-docker-rust-30oi
FROM rust:1.66.0-bullseye as build

RUN USER=root cargo new --bin redash-searcher-sync
WORKDIR /redash-searcher-sync

# copy over your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

# this build step will cache your dependencies
RUN cargo build --release
RUN rm src/*.rs

# copy your source tree
COPY ./src ./src

# build for release
RUN rm ./target/release/deps/redash_searcher_sync*
RUN cargo build --release

# our final base
FROM debian:bullseye-slim


RUN addgroup --system --gid 1001 redash-searcher
RUN adduser --system --uid 1001 redash-searcher-sync

RUN apt-get update \
&& apt-get install -y ca-certificates \
&& update-ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# copy the build artifact from the build stage
COPY --from=build --chown=redash-searcher-sync:redash-searcher /redash-searcher-sync/target/release/redash-searcher-sync .

USER redash-searcher-sync

# set the startup command to run your binary
ENTRYPOINT ["./redash-searcher-sync"]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct RedashConfig {

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct OpenSearchConfig {
pub username: String,
pub password: String,
pub username: Option<String>,
pub password: Option<String>,
pub url: String,
}

Expand Down
File renamed without changes.
21 changes: 11 additions & 10 deletions redash-search-sync/src/main.rs → redash-searcher-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::str::FromStr;

use opensearch::http::transport::{SingleNodeConnectionPool, TransportBuilder};
use opensearch::OpenSearch;
use redash_search_sync::app::App;
use redash_search_sync::configs::Configs;
use redash_search_sync::redash::DefaultRedashClient;
use redash_searcher_sync::app::App;
use redash_searcher_sync::configs::Configs;
use redash_searcher_sync::redash::DefaultRedashClient;
use tracing::Level;

#[tokio::main]
Expand All @@ -21,13 +21,14 @@ async fn main() {
let redash_client =
Box::new(DefaultRedashClient::new(&config.redash.url, &config.redash.api_key).unwrap());
let conn_pool = SingleNodeConnectionPool::new((&config.open_search.url).parse().unwrap());
let transport = TransportBuilder::new(conn_pool)
.auth(opensearch::auth::Credentials::Basic(
(&config.open_search.username).clone(),
(&config.open_search.password).clone(),
))
.build()
.expect("failed to build transport");
let mut builder = TransportBuilder::new(conn_pool);
if !(config.open_search.username.is_none() || config.open_search.password.is_none()) {
builder = builder.auth(opensearch::auth::Credentials::Basic(
config.open_search.username.clone().unwrap(),
config.open_search.password.clone().unwrap(),
));
}
let transport = builder.build().expect("failed to build transport");
let client = OpenSearch::new(transport);

let app = App::new(redash_client, client);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 15 additions & 9 deletions redash-search-web/Dockerfile → redash-searcher-web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Learn more here: https://redash-searcher-web.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

# set public env vars to be replaced at runtime
ENV NEXT_PUBLIC_REDASH__URL=APP_NEXT_PUBLIC_REDASH__URL
RUN yarn build

# If using npm comment out above and use below instead
Expand All @@ -39,21 +41,25 @@ ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN addgroup --system --gid 1001 redash-searcher
RUN adduser --system --uid 1001 redash-searcher-web

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/server ./.next/server
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# https://nexjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=redash-searcher-web:redash-searcher /app/.next/standalone ./
COPY --from=builder --chown=redash-searcher-web:redash-searcher /app/.next/server ./.next/server
COPY --from=builder --chown=redash-searcher-web:redash-searcher /app/.next/static ./.next/static

USER nextjs
USER redash-searcher-web

EXPOSE 3000

ENV PORT 3000

ENTRYPOINT ["node", "server.js"]
COPY --chown=redash-searcher-web:redash-searcher entrypoint.sh ./

ENTRYPOINT [ "bash", "entrypoint.sh" ]

CMD ["node", "server.js"]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import {
} from "@elastic/eui";
import { IResultHitItem } from "../pages/api/models";
import { HighlightedQuery } from "./HighlightedQuery";
import getConfig from "next/config";

const { publicRuntimeConfig } = getConfig();

export interface HitListProps {
hitItems: IResultHitItem[];
}

const REDASH_URL = (process.env.NEXT_PUBLIC_REDASH__URL || "").replace(
/\/$/,
""
);

const HitsList: React.FC<HitListProps> = ({ hitItems }) => {
return (
<EuiFlexGrid gutterSize="xl">
Expand All @@ -29,12 +31,12 @@ const HitsList: React.FC<HitListProps> = ({ hitItems }) => {
<EuiAvatar
name={`logo-${hit.fields.data_source_type}`}
size="l"
imageUrl={`${publicRuntimeConfig.redashURL}/static/images/db-logos/${hit.fields.data_source_type}.png`}
imageUrl={`${REDASH_URL}/static/images/db-logos/${hit.fields.data_source_type}.png`}
color="#e0e5ee"
/>
}
title={hit.fields.name}
href={`${publicRuntimeConfig.redashURL}/queries/${hit.id}`}
href={`${REDASH_URL}/queries/${hit.id}`}
description={hit.fields.description}
>
<EuiFlexGrid gutterSize="xl">
Expand Down
10 changes: 10 additions & 0 deletions redash-searcher-web/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# This is workaround to set public environment variables from runtime
# ref: https://dev.to/itsrennyman/manage-nextpublic-environment-variables-at-runtime-with-docker-53dl

echo "Check that we have NEXT_PUBLIC_REDASH__URL vars"
test -n "$NEXT_PUBLIC_REDASH__URL"

find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_REDASH__URL#$NEXT_PUBLIC_REDASH__URL#g"

exec "$@"
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
const { processEnv } = require("@next/env");

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
compiler: {
emotion: true,
},
publicRuntimeConfig: {
redashURL: (processEnv.REDASH__URL || "").replace(/\/$/, ""),
},
output: "standalone",
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "redash-search-web",
"name": "redash-searcher-web",
"version": "0.1.0",
"private": true,
"scripts": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ import {
SearchkitSchema,
} from "@searchkit/schema";

const searchkitConfig= {
host: "http://localhost:9200",
const getOpenSearchURI = () => {
const openSearchURL = process.env.OPEN_SEARCH__URL || "http://localhost:9200";
const openSearchUsername = process.env.OPEN_SEARCH__USERNAME;
const openSearchPassword = process.env.OPEN_SEARCH__PASSWORD;
if (!(openSearchUsername && openSearchPassword)) {
return openSearchURL;
}
return openSearchURL.replace(
"://",
`://${openSearchUsername}:${openSearchPassword}@`
);
};

const searchkitConfig = {
host: getOpenSearchURI(),
credential: {},
index: "redash",
hits: {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.