Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Nov 6, 2024
0 parents commit 2300e66
Show file tree
Hide file tree
Showing 1,074 changed files with 339,384 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .ackrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--ignore-dir=build
--ignore-dir=vendor
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/** linguist-generated=true
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Sourcemeta Registry CI

on:
pull_request:

concurrency:
group: registry-ci-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Dependencies
- run: pipx install clang-format==19.1.0
- uses: intelligence-ai/[email protected]
- name: Install Hurl
run: |
curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/${{ env.HURL_VERSION }}/hurl_${{ env.HURL_VERSION }}_amd64.deb
sudo apt install ./hurl_${{ env.HURL_VERSION }}_amd64.deb
rm hurl_${{ env.HURL_VERSION }}_amd64.deb
env:
HURL_VERSION: 5.0.1

# Linting
- run: make configure PRESET=Release INDEX=OFF SERVER=OFF
- run: make lint PRESET=Release

# Testing
- run: docker build --tag registry . --progress plain
- run: docker compose build
- run: docker compose up --detach --wait
- run: make test PRESET=Release
- run: docker compose down
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
/build
Brewfile.lock.json
.DS_Store
5 changes: 5 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
brew "cmake"
brew "hurl"
brew "jq"
tap "sourcemeta/apps"
cask "sourcemeta/apps/jsonschema"
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.16)
project(registry VERSION 0.0.1 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(vendor/noa/cmake/noa.cmake)

# Options
option(REGISTRY_DEVELOPMENT "Build the Registry in development mode" OFF)
option(REGISTRY_SERVER "Build the Registry server" ON)
option(REGISTRY_INDEX "Build the Registry index tool" ON)

find_package(JSONToolkit REQUIRED)
find_package(Blaze REQUIRED)
find_package(Hydra REQUIRED)

# Always optimize the current architecture
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mtune=native")

if(REGISTRY_INDEX)
add_subdirectory(src/index)
endif()

if(REGISTRY_SERVER)
add_subdirectory(src/server)
endif()

if(REGISTRY_DEVELOPMENT)
noa_target_clang_format(SOURCES src/*.h src/*.cc)
endif()
5 changes: 5 additions & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
noa https://github.com/sourcemeta/noa caad2e1ceedf9fd1a18686a6a6d1e2b9757ead75
jsontoolkit https://github.com/sourcemeta/jsontoolkit c6d056cc608bf98705ad7700c8c891e1cf6865a0
blaze https://github.com/sourcemeta/blaze 970e8aef78f0140551dde12e0784b30595580f49
hydra https://github.com/sourcemeta/hydra 8c266c752192bfe40484436c1874a9795c637633
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM debian:bookworm AS builder
RUN apt-get --yes update && apt-get install --yes --no-install-recommends \
build-essential cmake && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY cmake /source/cmake
COPY src /source/src
COPY schemas /source/schemas
COPY vendor /source/vendor
COPY CMakeLists.txt /source/CMakeLists.txt

RUN cmake -S /source -B ./build \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DREGISTRY_INDEX:BOOL=ON \
-DREGISTRY_SERVER:BOOL=ON \
-DREGISTRY_DEVELOPMENT:BOOL=OFF \
-DBUILD_SHARED_LIBS:BOOL=OFF

RUN cmake --build /build --config Release --parallel 2
RUN cmake --install ./build --prefix /usr --verbose \
--config Release --component sourcemeta_registry

FROM debian:bookworm-slim
RUN apt-get --yes update && apt-get install --yes --no-install-recommends \
ca-certificates && apt-get clean && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/bin/sourcemeta-registry-index \
/usr/bin/sourcemeta-registry-index
COPY --from=builder /usr/bin/sourcemeta-registry-server \
/usr/bin/sourcemeta-registry-server
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
All rights reserved. You can only use this software under a commercial license,
as set out in <https://www.sourcemeta.com/licensing/>.
63 changes: 63 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Programs
CMAKE ?= cmake
HURL ?= hurl
JSONSCHEMA ?= jsonschema
DOCKER ?= docker

# Options
INDEX ?= ON
SERVER ?= ON
PRESET ?= Debug
OUTPUT ?= ./build
PREFIX ?= $(OUTPUT)/dist
SANDBOX ?= ./test/sandbox

.PHONY: all
all: configure compile

.PHONY: configure
configure:
$(CMAKE) -S . -B $(OUTPUT) \
-DCMAKE_BUILD_TYPE:STRING=$(PRESET) \
-DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON \
-DREGISTRY_DEVELOPMENT:BOOL=ON \
-DREGISTRY_INDEX:BOOL=$(INDEX) \
-DREGISTRY_SERVER:BOOL=$(SERVER) \
-DBUILD_SHARED_LIBS:BOOL=OFF

.PHONY: compile
compile:
$(JSONSCHEMA) fmt --verbose schemas/*.json
$(JSONSCHEMA) lint --verbose schemas/*.json
$(CMAKE) --build $(OUTPUT) --config $(PRESET) --target clang_format
$(CMAKE) --build $(OUTPUT) --config $(PRESET) --parallel 4
$(CMAKE) --install $(OUTPUT) --prefix $(PREFIX) --config $(PRESET) --verbose \
--component sourcemeta_registry

.PHONY: lint
lint:
$(JSONSCHEMA) fmt --check --verbose schemas/*.json
$(JSONSCHEMA) lint --verbose schemas/*.json
$(CMAKE) --build $(OUTPUT) --config $(PRESET) --target clang_format

.PHONY: test
test:
$(HURL) --test \
--variable base=$(shell jq --raw-output '.url' < $(SANDBOX)/configuration.json) \
test/e2e/*.hurl

.PHONY: sandbox
sandbox: compile
$(PREFIX)/bin/sourcemeta-registry-index $(SANDBOX)/configuration.json $(OUTPUT)/sandbox
./test/sandbox/manifest-check.sh $(OUTPUT)/sandbox $(SANDBOX)/manifest.txt
$(PREFIX)/bin/sourcemeta-registry-server $(OUTPUT)/sandbox

.PHONY: docker
docker:
$(DOCKER) build --tag registry . --progress plain
$(DOCKER) compose up --build

.PHONY: clean
clean:
$(CMAKE) -E rm -R -f build
$(DOCKER) system prune --force --all --volumes || true
5 changes: 5 additions & 0 deletions cmake/FindBlaze.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if(NOT Blaze_FOUND)
set(BLAZE_INSTALL OFF CACHE BOOL "disable installation")
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/blaze")
set(Blaze_FOUND ON)
endif()
6 changes: 6 additions & 0 deletions cmake/FindHydra.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if(NOT Hydra_FOUND)
set(HYDRA_INSTALL OFF CACHE BOOL "disable installation")
set(HYDRA_BUCKET OFF CACHE BOOL "disable S3 bucket support")
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/hydra")
set(Hydra_FOUND ON)
endif()
5 changes: 5 additions & 0 deletions cmake/FindJSONToolkit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if(NOT JSONToolkit_FOUND)
set(JSONTOOLKIT_INSTALL OFF CACHE BOOL "disable installation")
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/jsontoolkit")
set(JSONToolkit_FOUND ON)
endif()
6 changes: 6 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
sandbox:
build:
context: test/sandbox
ports:
- 8000:8000
40 changes: 40 additions & 0 deletions schemas/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"url",
"port",
"collections"
],
"properties": {
"collections": {
"type": "object",
"additionalProperties": {
"type": "object",
"required": [
"base",
"path"
],
"properties": {
"base": {
"type": "string",
"format": "url"
},
"path": {
"type": "string"
}
},
"additionalProperties": false
}
},
"port": {
"type": "integer",
"minimum": 0
},
"url": {
"type": "string",
"format": "url"
}
},
"additionalProperties": false
}
18 changes: 18 additions & 0 deletions src/index/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_executable(schema_registry_index index.cc configure.h.in)

noa_add_default_options(PRIVATE schema_registry_index)
set_target_properties(schema_registry_index PROPERTIES OUTPUT_NAME sourcemeta-registry-index)
target_link_libraries(schema_registry_index PRIVATE sourcemeta::jsontoolkit::uri)
target_link_libraries(schema_registry_index PRIVATE sourcemeta::jsontoolkit::json)
target_link_libraries(schema_registry_index PRIVATE sourcemeta::jsontoolkit::jsonschema)
target_link_libraries(schema_registry_index PRIVATE sourcemeta::blaze::compiler)
target_link_libraries(schema_registry_index PRIVATE sourcemeta::blaze::evaluator)

file(READ "${PROJECT_SOURCE_DIR}/schemas/configuration.json" SCHEMA_CONFIGURATION)
configure_file(configure.h.in configure.h @ONLY)
target_include_directories(schema_registry_index PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")

include(GNUInstallDirs)
install(TARGETS schema_registry_index
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT sourcemeta_registry)
11 changes: 11 additions & 0 deletions src/index/configure.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef SOURCEMETA_REGISTRY_INDEX_CONFIGURE_H_
#define SOURCEMETA_REGISTRY_INDEX_CONFIGURE_H_

#include <string_view> // std::string_view

namespace sourcemeta::registry {
constexpr std::string_view PROJECT_VERSION{"@PROJECT_VERSION@"};
constexpr std::string_view SCHEMA_CONFIGURATION{R"EOF(@SCHEMA_CONFIGURATION@)EOF"};
}

#endif
Loading

0 comments on commit 2300e66

Please sign in to comment.