Skip to content

Commit 6250e68

Browse files
authored
Add initial Docker configuration for the SPARQL and NGINX endpoint, including startup scripts, configuration files and static resources.
1 parent f11dfc5 commit 6250e68

29 files changed

+1268
-264
lines changed

.env.example

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
# Server Configuration
2-
SV_PORT_HOST=5000
2+
PROXY_SERVER_NAME=localhost
33
SV_WORKERS=2
4+
# Common proxy server for NGINX.
5+
NGINX_PORT_HOST=80
6+
NGINX_SSLPORT_HOST=443
47

58
# Security
69
ENABLE_CORS=false
710
ALLOWED_ORIGINS=*
811

9-
# Options
12+
# RDF of filename in folder ./data
1013
CATALOG_FILE=catalog.rdf
14+
15+
# SPARQL Query Configuration
16+
DEFAULT_SPARQL_QUERY="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nSELECT * WHERE {\n ?s ?p ?o .\n} LIMIT 100"
17+
EXAMPLE_SPARQL_QUERIES='{
18+
"HVD info": {
19+
"query": "prefix dct: <http://purl.org/dc/terms/>\nprefix dcatap: <http://data.europa.eu/r5r/>\nprefix dcat: <http://www.w3.org/ns/dcat#>\n\nselect distinct ?title ?hvdCategory ?applicableLegislation ?accessService ?accessURL ?license\nwhere {\n # Filtrar por catálogos ES\n ?catalogo ?cp ?d.\n\n # Dataset y su categoría HVD\n ?d dcatap:applicableLegislation <http://data.europa.eu/eli/reg_impl/2023/138/oj>.\n ?d a dcat:Dataset.\n optional { ?d dcatap:hvdCategory ?hvdCategory. }\n \n # Distribución y sus propiedades\n ?d dcat:distribution ?dist.\n ?dist dcatap:applicableLegislation <http://data.europa.eu/eli/reg_impl/2023/138/oj>.\n \n optional { \n ?dist dct:title ?title.\n FILTER(langMatches(lang(?title), \"es\"))\n } \n optional { ?dist dcatap:applicableLegislation ?applicableLegislation. } \n optional { ?dist dcat:accessURL ?accessURL. } \n optional { ?dist dcat:accessService ?accessService. } \n optional { ?dist dct:license ?license. } \n}\nORDER BY ?dist"
20+
},
21+
"Query types": {
22+
"query": "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nSELECT DISTINCT ?type WHERE {\n ?s rdf:type ?type\n} LIMIT 10"
23+
},
24+
"Count triples": {
25+
"query": "SELECT (COUNT(*) AS ?count) WHERE {\n ?s ?p ?o .\n}"
26+
}
27+
}'
28+
SPARQL_ENDPOINT_TITLE="RDF SPARQL Endpoint-Catalog"
29+
SPARQL_ENDPOINT_DESCRIPTION="Endpoint SPARQl and RDF Catalog to query and explore linked data"
30+
SPARQL_ENDPOINT_VERSION="1.0.0"

README.md

+96-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# README - Serving RDF with Docker & Flask
22

33
## Overview
4-
This project provides a simple **Dockerized RDF endpoint** that serves an `.rdf` file with the correct `Content-Type: application/rdf+xml`, ensuring compatibility with **DCAT-AP federators** and **RDF parsers** like `rdflib`.
4+
This project provides a simple **Dockerized RDF endpoint** that serves an `.rdf` file an provides an SPARQL Endpoint based on [`vemonet/rdflib-endpoint`](https://github.com/vemonet/rdflib-endpoint)
55

6+
The RDF file using the correct `Content-Type: application/rdf+xml`, ensuring compatibility with **DCAT-AP federators** and **RDF parsers** like `rdflib`.
67

78
## Quick Start
89
Use [Codespaces](https://github.com/features/codespaces) to test `easy-rdf-endpoint` in your browser
@@ -18,22 +19,22 @@ Before starting the deployment, you'll need to set up a `.env` file. This file i
1819
1. Clone project
1920
```shell
2021
cd /path/to/my/project
21-
git clone https://github.com/mjanez/easy-rdf-endpoint.git & cd ckan-docker
22+
git clone https://github.com/mjanez/easy-rdf-endpoint.git & cd easy-rdf-endpoint
2223
```
2324

24-
2. Copy the `.env.example` template and modify the resulting `.env` to suit your needs.
25+
2. Copy the [`.env.example`](.env.example) template and modify the resulting `.env` to suit your needs.
2526

2627
```shell
2728
cp .env.example .env
2829
```
2930

30-
Adjust the vars as necessary
31+
Adjust the vars as necessary, example:
3132
```ini
32-
# Host Ports
33-
SV_PORT_HOST=5000
33+
# Server Configuration
34+
PROXY_SERVER_NAME=my-example-sparql-server.org
3435
35-
# Options
36-
CATALOG_FILE=catalog.rdf
36+
# RDF of filename in folder ./data
37+
CATALOG_FILE=my-custom-catalog.rdf
3738
```
3839

3940
3. Build & up the container.
@@ -42,27 +43,101 @@ Before starting the deployment, you'll need to set up a `.env` file. This file i
4243
docker compose up -d
4344
```
4445

45-
Then, access your RDF file at:
46-
47-
👉 `http://localhost:5000/catalog.rdf`
46+
Then, access your RDF file an [endpoints](#endpoints).
4847

4948
---
5049

50+
### Endpoints
51+
The endpoints will be available at:
52+
* Landing page[`http://localhost:5000`](http://localhost:5000)
53+
* Access your RDF file at: [`http://localhost:5000/catalog`](http://localhost:5000/catalog)
54+
* Default query editor (Yasgui): [`http://localhost:5000/sparql-editor`](http://localhost:5000/sparql-editor)
55+
* SPARQL endpoint: [`http://localhost:5000/sparql`](http://localhost5000/sparql)
56+
5157
## Project Structure
52-
```
53-
/rdf-server
54-
│── /data/catalog.rdf # Your RDF file (replace with your own)
55-
│── /scr/app.py # Flask server to serve RDF
56-
│── /src/requirements.txt # Python dependencies
57-
│── /docker/Dockerfile # Docker setup
58+
```sh
59+
/easy-rdf-endpoint
60+
│── /data/catalog.rdf # Your Catalog RDF file (replace with your own)
61+
│── /doc/ # References, as images or documents, used in repo
62+
│── /easy-rdf-endpoint/ # RDF+SPARQL Endpoint setup
63+
│── /nginx/ # NGINX docker setup
64+
│── /src/ # Now using NGINX instead of the old RDF serving mode
65+
│── .env.example # Sample ENVVars file for use with Docker Compose
5866
│── docker-compose.yml # Docker Compose config
5967
│── README.md # Documentation
6068
```
6169

62-
## Notes
63-
- Replace `catalog.rdf` with your actual RDF file.
64-
- Modify `app.py` if you need additional routes or enhancements.
65-
- Works with **Codespaces, Docker, Kubernetes, and any containerized environment**.
70+
[!NOTE]
71+
> - Replace `catalog.rdf` with your actual RDF file.
72+
> - Works with **Codespaces, Docker, Kubernetes, and any containerized environment**.
73+
74+
## Update SSL Certificate
75+
To update the local SSL certificate, follow these steps:
76+
77+
1. Generate a new certificate and private key:
78+
```sh
79+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
80+
-keyout nginx/setup/easy-rdf-endpoint_local.key \
81+
-out nginx/setup/easy-rdf-endpoint_local.crt \
82+
-subj "/C=ES/ST=Madrid/L=Madrid/O=Development/CN=localhost"
83+
```
84+
85+
2. Verify that the files have been created correctly:
86+
```sh
87+
ls -l nginx/setup/easy-rdf-endpoint_local.*
88+
```
89+
90+
3. Restart the `nginx` container to apply the changes:
91+
```sh
92+
docker compose restart nginx
93+
```
94+
95+
> [!CAUTION]
96+
> This certificate is for local development only. In production, use a valid certificate from a certificate authority.
97+
98+
## Development
99+
100+
### Using DevContainers
101+
This project supports development using DevContainers, which provides a consistent development environment for all contributors.
102+
103+
**Requirements**:
104+
* [Docker](https://docs.docker.com/get-docker/)
105+
- [VS Code](https://code.visualstudio.com/) or [GitHub Codespaces](https://github.com/features/codespaces)
106+
- [VS Code Remote - Containers extension](https://docs.rancherdesktop.io/how-to-guides/vs-code-remote-containers/)
107+
108+
#### Getting Started with DevContainer
109+
1. Clone the repository:
110+
```bash
111+
git clone https://github.com/mjanez/easy-rdf-endpoint.git
112+
cd easy-rdf-endpoint
113+
```
114+
115+
2. Open in VS Code:
116+
```bash
117+
code .
118+
```
119+
120+
3. When prompted "*Reopen in Container*", click "*Reopen in Container*". Alternatively:
121+
- Press `F1`
122+
- Type "*Remote-Containers: Reopen in Container*"
123+
- Press *Enter*
124+
125+
VS Code will build and start the development container. This may take a few minutes the first time.
126+
127+
#### What's Included
128+
The development container includes:
129+
- Python 3.11 environment
130+
- Required Python packages pre-installed
131+
- Popular VS Code extensions for Python/Docker development
132+
- Git configuration
133+
- Port forwarding for the application
134+
135+
#### Working in the Container
136+
Once inside the container you can:
137+
- Run the application: `exec gunicorn --bind 0.0.0.0:5000 app:app`
138+
- Modify the [`easy-rdf-endpoint/setup/rdflib-endpoint/sparql_override.py`](./easy-rdf-endpoint/setup/rdflib-endpoint/sparql_override.py)
139+
- Execute SPARQL queries: `http://localhost:5000/sparql`
140+
- Debug with VS Code's integrated debugger
66141
67142
## License
68143
This project is licensed under the **MIT License**.
115 KB
Loading

docker-compose.yml

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
services:
2-
rdf-endpoint:
2+
nginx:
33
build:
44
context: .
5-
dockerfile: docker/Dockerfile
5+
dockerfile: nginx/Dockerfile
6+
env_file:
7+
- .env
8+
logging:
9+
driver: "json-file"
10+
options:
11+
max-size: "100m"
12+
max-file: "10"
13+
depends_on:
14+
- sparql-endpoint
15+
volumes:
16+
- ./data/${CATALOG_FILE}:/usr/share/nginx/html/catalog.rdf
17+
ports:
18+
- "0.0.0.0:${NGINX_PORT_HOST}:80"
19+
- "0.0.0.0:${NGINX_SSLPORT_HOST}:443"
20+
restart: on-failure:3
21+
22+
sparql-endpoint:
23+
build:
24+
context: .
25+
dockerfile: easy-rdf-endpoint/Dockerfile.sparql
626
env_file:
727
- .env
828
logging:
929
driver: "json-file"
1030
options:
1131
max-size: "10m"
1232
max-file: "5"
13-
ports:
14-
- "${SV_PORT_HOST}:5000"
1533
volumes:
16-
- ./data/${CATALOG_FILE}:/app/catalog.rdf
17-
healthcheck:
18-
test: ["CMD", "curl", "-f", "http://localhost:5000/catalog.rdf"]
19-
interval: 30s
20-
timeout: 10s
21-
retries: 3
34+
- ./data/${CATALOG_FILE}:/app/data/catalog.rdf
35+
restart: on-failure:3
36+

0 commit comments

Comments
 (0)