Skip to content

Commit

Permalink
Merge pull request #5 from zazuko/docker-env
Browse files Browse the repository at this point in the history
[Docker] Allow the use of environment variables for the configuration
  • Loading branch information
ludovicm67 authored Jun 10, 2024
2 parents e8d63c8 + 1d8ac75 commit 8bd888f
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 15 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ RUN sed -i "s/<VERSION>/${VERSION}/" ./projects/blueprint/src/build/build.ts
RUN npm run build blueprint

# Second step: serve the builded app
FROM nginx:1.23.4-alpine
FROM nginx:1.27.0-alpine

# Install some tools
RUN apk add --no-cache jq

RUN mkdir -p /app
WORKDIR /app
COPY nginx.conf /etc/nginx/nginx.conf
COPY entrypoint.sh /docker-entrypoint.d/00-blueprint-entrypoint.sh
RUN chmod +x /docker-entrypoint.d/00-blueprint-entrypoint.sh
COPY --from=builder /app/dist/blueprint/browser/ .

EXPOSE 80
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ In case you are using the `neptune` dialect you need to provide the OpenSearch e
}
```

## Using Docker

You can use our Docker image to run Blueprint.

```sh
docker pull ghcr.io/zazuko/blueprint:latest
```

It will listen on port 80.

The following environment variables can be set:

- `ENDPOINT_URL`: the SPARQL endpoint URL (required)
- `SPARQL_CONSOLE_URL`: the SPARQL console URL (default placeholder value: `http://example.com/sparql/#query`)
- `GRAPH_EXPLORER_URL`: the Graph Explorer URL (default placeholder value: `http://example.com/graph-explorer/?resource`)
- `FULL_TEXT_SEARCH_DIALECT`: the full text search dialect (default value: `fuseki`)
- `NEPTUNE_FTS_ENDPOINT`: the OpenSearch endpoint for the Neptune dialect (in case you are using `neptune` dialect)

If any of the required environment variables are not set, the container will be started using the development configuration.

You can also mount a custom configuration file to `/app/config.json`.

You should make sure that `ENDPOINT_URL`, `SPARQL_CONSOLE_URL` and `GRAPH_EXPLORER_URL` are reachable from the browser.
Make sure that `ENDPOINT_URL` is configured to allow CORS requests.

You can use [Trifid](https://github.com/zazuko/trifid) to proxy any SPARQL endpoint and to expose a SPARQL console and Graph Explorer.
You can also use it to dereference URIs.

## Development

### Configuration
Expand Down
67 changes: 67 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

##################################################################
# Check for required environment variables #
# In case they are not set, use default config.json file instead #
##################################################################

if [ -z "${ENDPOINT_URL}" ]; then
echo "ENDPOINT_URL is not set, let's keep the current config.json file."
exit 0
fi

#########################################################
# Set default values for optional environment variables #
#########################################################

if [ -z "${SPARQL_CONSOLE_URL}" ]; then
echo "SPARQL_CONSOLE_URL is not set, let's use 'http://example.com/sparql/#query' as default value."
SPARQL_CONSOLE_URL="http://example.com/sparql/#query"
fi

if [ -z "${GRAPH_EXPLORER_URL}" ]; then
echo "GRAPH_EXPLORER_URL is not set, let's use 'http://example.com/graph-explorer/?resource' as default value."
GRAPH_EXPLORER_URL="http://example.com/graph-explorer/?resource"
fi

if [ -z "${FULL_TEXT_SEARCH_DIALECT}" ]; then
echo "FULL_TEXT_SEARCH_DIALECT is not set, let's use 'fuseki' as default value."
FULL_TEXT_SEARCH_DIALECT="fuseki"
fi

if [ -z "${NEPTUNE_FTS_ENDPOINT}" ]; then
# Check if the full-text search endpoint is set to "neptune", and only display the warning message in this case
if [ "${FULL_TEXT_SEARCH_DIALECT}" = "neptune" ]; then
echo "NEPTUNE_FTS_ENDPOINT is not set, let's use 'http://example.com/' as default value."
fi
NEPTUNE_FTS_ENDPOINT="http://example.com/"
fi

########################################################
# Generate config.json file from environment variables #
########################################################

echo "Generating config.json file with the following values:"
echo "- ENDPOINT_URL: ${ENDPOINT_URL}"
echo "- SPARQL_CONSOLE_URL: ${SPARQL_CONSOLE_URL}"
echo "- GRAPH_EXPLORER_URL: ${GRAPH_EXPLORER_URL}"
echo "- FULL_TEXT_SEARCH_DIALECT: ${FULL_TEXT_SEARCH_DIALECT}"
echo "- NEPTUNE_FTS_ENDPOINT: ${NEPTUNE_FTS_ENDPOINT}"

jq -n \
--arg endpointUrl "${ENDPOINT_URL}" \
--arg sparqlConsoleUrl "${SPARQL_CONSOLE_URL}" \
--arg graphExplorerUrl "${GRAPH_EXPLORER_URL}" \
--arg fullTextSearchDialect "${FULL_TEXT_SEARCH_DIALECT}" \
--arg ftsEndpoint "${NEPTUNE_FTS_ENDPOINT}" \
'{
"endpointUrl": $endpointUrl,
"sparqlConsoleUrl": $sparqlConsoleUrl,
"graphExplorerUrl": $graphExplorerUrl,
"fullTextSearchDialect": $fullTextSearchDialect,
"neptune": {
"ftsEndpoint": $ftsEndpoint
}
}' > /app/config.json

exit 0
12 changes: 6 additions & 6 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ http {
include /etc/nginx/mime.types;

server{
listen 80;
root /app;
index index.html;
location / {
try_files $uri$args $uri$args/ /index.html;
}
listen 80;
root /app;
index index.html;
location / {
try_files $uri$args $uri$args/ /index.html;
}
}
}
6 changes: 0 additions & 6 deletions stack/blueprint/config.json

This file was deleted.

8 changes: 6 additions & 2 deletions stack/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ services:
build:
context: ..
dockerfile: Dockerfile
volumes:
- ./blueprint/config.json:/app/config.json:ro
ports:
- 8081:80
environment:
# NOTE: 127.0.0.1 is in the context of the browser (frontend), not the server (backend)
- ENDPOINT_URL=http://127.0.0.1:8080/query
- SPARQL_CONSOLE_URL=http://127.0.0.1:8080/sparql/#query
- GRAPH_EXPLORER_URL=http://127.0.0.1:8080/graph-explorer/?resource
- FULL_TEXT_SEARCH_DIALECT=fuseki

trifid:
image: ghcr.io/zazuko/trifid:v5
Expand Down

0 comments on commit 8bd888f

Please sign in to comment.