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

feat: new features #51

Merged
merged 4 commits into from
Jan 15, 2025
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
62 changes: 34 additions & 28 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: PR CI

on:
pull_request:
branches: [ develop, main ]
pull_request_target:
types:
- opened
- edited
- synchronize
- reopened

env:
GO111MODULE: on
Expand All @@ -13,30 +17,31 @@ env:
TEST_ARGS: -v -short -coverprofile=coverage.out

jobs:
commitlint:
name: Commit Lint Job
validate_pr_title_job:
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }}
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v4
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install commitlint
run: |
npm install --save-dev @commitlint/{cli,config-conventional}

- name: Validate PR commits with commitlint
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
requireScope: false
# Configure additional validation for the subject based on a regex.
# This example ensures the subject doesn't start with an uppercase character.
subjectPattern: ^(?![A-Z]).+$
# If `subjectPattern` is configured, you can use this property to override
# the default error message that is shown when the pattern doesn't match.
# The variables `subject` and `title` can be used within the message.
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
didn't match the configured pattern. Please ensure that the subject
doesn't start with an uppercase character.

# Linting multiple Dockerfiles to ensure adherence to best practices and coding standards.
hadolint_job:
name: Hadolint Job
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }}
name: Hadolint
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -61,7 +66,8 @@ jobs:
dockerfile: ${{ matrix.dockerfile }}

editor_config_job:
name: Editor Config Job
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }}
name: Check editor config
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand All @@ -79,8 +85,8 @@ jobs:

# Ensures that the code adheres to the lint checks defined in .golangci.yaml.
lint_job:
name: Go lint job for all components
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }}
name: Go lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -125,9 +131,9 @@ jobs:
skip-save-cache: true
working-directory: ${{ matrix.component }}

licenses_check:
name: 3rd Party Licenses Check
if: ${{ github.event.head_commit.committer.name != 'github-actions[bot]' || ! contains(github.head_ref, 'release-please--branches--main') }}
licenses_check_job:
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }}
name: 3rd party licenses check
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -233,8 +239,8 @@ jobs:

# Runs unit tests for all components in this repo
test_job:
name: Test Job for all components
if: ${{ github.base_ref == 'main' && ! contains(github.head_ref, 'release-please--branches--main') }}
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }}
name: Test job
runs-on: ubuntu-latest

strategy:
Expand Down Expand Up @@ -264,9 +270,9 @@ jobs:
run: go test ${{env.TEST_ARGS}} ./...

# Builds docker images for all components of the repo to test if they can successfully be built
Build_docker:
name: Test building docker images
test_docker_image_builds_job:
if: ${{ ! contains(github.head_ref, 'release-please--branches--main') }}
name: Test docker image builds
runs-on: ubuntu-latest

strategy:
Expand Down
34 changes: 19 additions & 15 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ name: PUSH CI

on:
push:
branches: [ develop, main ]
branches:
- main

env:
GO_VERSION: 1.21

jobs:
commitlint:
name: Commit Lint Job
commitlint_job:
name: Commit lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -28,8 +29,8 @@ jobs:
- name: Validate current commit (last commit) with commitlint
run: npx commitlint --last --verbose

license_headers:
name: Add License Headers
license_headers_job:
name: Add license headers
if: github.event.head_commit.committer.name != 'github-actions[bot]'
runs-on: ubuntu-latest
permissions:
Expand All @@ -54,7 +55,7 @@ jobs:
- name: Add missing license headers
run: nwa add -c "Syntio Ltd." -s **/*.xml ./registry ./validator

- name: Check and Commit changes
- name: Check and commit changes
id: check_commit
run: |
git config user.name "github-actions[bot]"
Expand All @@ -74,16 +75,16 @@ jobs:
git checkout -b "add-license-headers-${{ github.run_id }}"
git push origin HEAD

- name: Create Pull Request
- name: Create pull request
if: env.changes_committed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --base ${{ github.ref_name }} --head "add-license-headers-${{ github.run_id }}" --title "style: add license headers" --body "This PR adds license headers to the affected files. Recommendation: Merge this PR using the rebase-merge method"

Upload_docker:
name: Build, Push and Sign Docker Images
if: github.ref_name == 'main'
upload_docker_images_job:
if: github.event.head_commit.committer.name == 'github-actions[bot]' || startsWith(github.event.head_commit.message.name, 'feat') || startsWith(github.event.head_commit.message.name, 'fix')
name: Build, push and sign Docker images
runs-on: ubuntu-latest
permissions:
id-token: write # required to generate JWT token
Expand All @@ -110,9 +111,13 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Set Tag
- name: Set image tag
run: |
TAG=$(cat version.txt)
if [ ${{ github.event.head_commit.committer.name }} == 'github-actions[bot]' ]; then
TAG=$(cat version.txt)
else
TAG=$(echo $GITHUB_SHA | cut -c 1-7)
fi
echo "TAG=$TAG" >> $GITHUB_ENV

- name: Docker Hub Login
Expand All @@ -138,11 +143,11 @@ jobs:
docker push syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }}

- name: Install cosign
if: ${{ env.TAG_EXISTS == 'false' }}
if: ${{ github.event.head_commit.committer.name == 'github-actions[bot]' && env.TAG_EXISTS == 'false' }}
uses: sigstore/[email protected]

- name: Sign the Docker image
if: ${{ env.TAG_EXISTS == 'false' }}
if: ${{ github.event.head_commit.committer.name == 'github-actions[bot]' && env.TAG_EXISTS == 'false' }}
run: |
digest=$(docker inspect --format='{{index .RepoDigests 0}}' syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }})
cosign sign --yes "$digest"
Expand All @@ -152,7 +157,6 @@ jobs:
run: echo "Docker image syntioinc/dataphos-${{ matrix.component.image-name }}:${{ env.TAG }} already exists. Skipping push."

release-please:
if: github.ref_name == 'main'
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [1.1.1](https://github.com/dataphos/schema-registry/compare/v1.1.0...v1.1.1) (2024-11-26)


### Bug Fixes

* header schema error ([7328844](https://github.com/dataphos/schema-registry/commit/7328844e6e6309e3c99c7c2f9c750aba984a994e))
* header validation fix ([d5708e2](https://github.com/dataphos/schema-registry/commit/d5708e271d173ff1a697b07bb1c62b7b506db383))

## [1.1.0](https://github.com/dataphos/schema-registry/compare/v1.0.0...v1.1.0) (2024-11-20)


Expand Down
2 changes: 1 addition & 1 deletion registry/cmd/sr-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func registerSchema(registerCommand *flag.FlagSet) {
if !added {
log.Print("schema already exists")
} else {
log.Print("created schema under the id ", details.VersionID)
log.Printf("created schema under the id %s and version %s", details.SchemaID, details.Version)
}
}

Expand Down
5 changes: 5 additions & 0 deletions registry/docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SR_HOST=host.docker.internal
SR_DBNAME=postgres
SR_USER=postgres
SR_PASSWORD=
SR_TABLE_PREFIX=syntio_schema.
53 changes: 53 additions & 0 deletions registry/docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: schema-registry
services:
postgres:
image: postgres:17
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: # Please provide the password. Needs to match SR_PASSWORD in the .env file.
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 30s
timeout: 60s
retries: 5
start_period: 80s
initdb:
depends_on:
postgres:
condition: service_healthy
build:
context: ../../
dockerfile: ./registry/docker/initdb/Dockerfile
env_file:
- .env
compatibility-checker:
build:
context: ../../
dockerfile: ./registry/docker/compatibility-checker/Dockerfile
ports:
- 8088:8088
validity-checker:
build:
context: ../../
dockerfile: ./registry/docker/validity-checker/Dockerfile
ports:
- 8089:8089
schema-registry:
depends_on:
initdb:
condition: service_completed_successfully
compatibility-checker:
condition: service_started
validity-checker:
condition: service_started
build:
context: ../../
dockerfile: ./registry/docker/registry/Dockerfile
ports:
- 8080:8080
env_file:
- .env
environment:
COMPATIBILITY_CHECKER_URL: http://host.docker.internal:8088
VALIDITY_CHECKER_URL: http://host.docker.internal:8089
1 change: 1 addition & 0 deletions registry/registry/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
var ErrNotFound = errors.New("not found")
var ErrUnknownComp = errors.New("unknown value for compatibility_mode")
var ErrUnknownVal = errors.New("unknown value for validity mode")
var ErrUnknownFormat = errors.New("unknown value for schema format")
var ErrNotValid = errors.New("schema is not valid")
var ErrNotComp = errors.New("schemas are not compatible")
var ErrInvalidValueHeader = errors.New("invalid header value")
Expand Down
1 change: 0 additions & 1 deletion registry/registry/repository/postgres/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func intoRegistrySchema(schema Schema) registry.Schema {
// intoRegistryVersionDetails maps VersionDetails from repository to service layer.
func intoRegistryVersionDetails(VersionDetails VersionDetails) registry.VersionDetails {
return registry.VersionDetails{
VersionID: strconv.Itoa(int(VersionDetails.VersionID)),
Version: VersionDetails.Version,
SchemaID: strconv.Itoa(int(VersionDetails.SchemaID)),
Specification: VersionDetails.Specification,
Expand Down
22 changes: 16 additions & 6 deletions registry/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ func (h Handler) GetSpecificationByIdAndVersion(w http.ResponseWriter, r *http.R
log.Println(err)
}

body, _ := json.Marshal(specification)
writeResponse(w, responseBodyAndCode{
Body: body,
Body: specification,
Code: http.StatusOK,
})
}
Expand Down Expand Up @@ -359,8 +358,8 @@ func (h Handler) GetSchemas(w http.ResponseWriter, _ *http.Request) {
if err != nil {
if errors.Is(err, registry.ErrNotFound) {
writeResponse(w, responseBodyAndCode{
Body: serializeErrorMessage(http.StatusText(http.StatusNotFound)),
Code: http.StatusNotFound,
Body: serializeErrorMessage("No active schemas registered in the Registry"),
Code: http.StatusNoContent,
})
return
}
Expand Down Expand Up @@ -535,8 +534,19 @@ func (h Handler) SearchSchemas(w http.ResponseWriter, r *http.Request) {
// @Failure 500
// @Router /schemas [post]
func (h Handler) PostSchema(w http.ResponseWriter, r *http.Request) {

registerRequest, err := readSchemaRegisterRequest(r.Body)
if err != nil {
if errors.Is(err, registry.ErrUnknownFormat) {
body, _ := json.Marshal(report{
Message: "Bad request: unknown format value",
})
writeResponse(w, responseBodyAndCode{
Body: body,
Code: http.StatusBadRequest,
})
return
}
writeResponse(w, responseBodyAndCode{
Body: serializeErrorMessage(http.StatusText(http.StatusBadRequest)),
Code: http.StatusBadRequest,
Expand All @@ -548,7 +558,7 @@ func (h Handler) PostSchema(w http.ResponseWriter, r *http.Request) {
if err != nil {
if errors.Is(err, registry.ErrUnknownComp) {
body, _ := json.Marshal(report{
Message: "Bad request: unknown value for compatibility_mode",
Message: "Bad request: unknown compatibility_mode value",
})
writeResponse(w, responseBodyAndCode{
Body: body,
Expand All @@ -559,7 +569,7 @@ func (h Handler) PostSchema(w http.ResponseWriter, r *http.Request) {

if errors.Is(err, registry.ErrUnknownVal) {
body, _ := json.Marshal(report{
Message: "Bad request: unknown value for validity_mode",
Message: "Bad request: unknown validity_mode value",
})
writeResponse(w, responseBodyAndCode{
Body: body,
Expand Down
Loading
Loading