Skip to content

Commit

Permalink
introduce storage connector
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Jan 6, 2025
0 parents commit 964034a
Show file tree
Hide file tree
Showing 200 changed files with 22,516 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.hasura-connector/
*.hml
.github/
assets/
11 changes: 11 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
STORAGE_ENDPOINT=http://minio:9000
ACCESS_KEY_ID=test-key
SECRET_ACCESS_KEY=randomsecret
DEFAULT_BUCKET=default
S3_STORAGE_ENDPOINT=http://s3mock:9090
S3_ACCESS_KEY_ID=test-key
S3_SECRET_ACCESS_KEY=randomsecret
S3_DEFAULT_BUCKET=bucket1

APP_STORAGE_READ_URL="http://local.hasura.dev:8080"
APP_STORAGE_WRITE_URL="http://local.hasura.dev:8080"
10 changes: 10 additions & 0 deletions .github/scripts/plugin-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

export CLI_VERSION=$GITHUB_REF_NAME
export MACOS_AMD64_SHA256=$(sha256sum "_output/ndc-storage-darwin-amd64" | awk '{ print $1 }')
export MACOS_ARM64_SHA256=$(sha256sum "_output/ndc-storage-darwin-arm64" | awk '{ print $1 }')
export LINUX_AMD64_SHA256=$(sha256sum "_output/ndc-storage-linux-amd64" | awk '{ print $1 }')
export LINUX_ARM64_SHA256=$(sha256sum "_output/ndc-storage-linux-arm64" | awk '{ print $1 }')
export WINDOWS_AMD64_SHA256=$(sha256sum "_output/ndc-storage-windows-amd64.exe" | awk '{ print $1 }')

envsubst < .github/scripts/plugin-manifest.yaml > release/manifest.yaml
41 changes: 41 additions & 0 deletions .github/scripts/plugin-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: ndc-storage
version: "${CLI_VERSION}"
shortDescription: "CLI plugin for Hasura Prometheus data connector"
homepage: https://github.com/hasura/ndc-storage
hidden: true
platforms:
- selector: darwin-arm64
uri: "https://github.com/hasura/ndc-storage/releases/download/${CLI_VERSION}/ndc-storage-darwin-arm64"
sha256: "${MACOS_ARM64_SHA256}"
bin: "ndc-storage"
files:
- from: "./ndc-storage-darwin-arm64"
to: "ndc-storage"
- selector: linux-arm64
uri: "https://github.com/hasura/ndc-storage/releases/download/${CLI_VERSION}/ndc-storage-linux-arm64"
sha256: "${LINUX_ARM64_SHA256}"
bin: "ndc-storage"
files:
- from: "./ndc-storage-linux-arm64"
to: "ndc-storage"
- selector: darwin-amd64
uri: "https://github.com/hasura/ndc-storage/releases/download/${CLI_VERSION}/ndc-storage-darwin-amd64"
sha256: "${MACOS_AMD64_SHA256}"
bin: "ndc-storage"
files:
- from: "./ndc-storage-darwin-amd64"
to: "ndc-storage"
- selector: windows-amd64
uri: "https://github.com/hasura/ndc-storage/releases/download/${CLI_VERSION}/ndc-storage-windows-amd64.exe"
sha256: "${WINDOWS_AMD64_SHA256}"
bin: "ndc-storage.exe"
files:
- from: "./ndc-storage-windows-amd64.exe"
to: "ndc-storage.exe"
- selector: linux-amd64
uri: "https://github.com/hasura/ndc-storage/releases/download/${CLI_VERSION}/ndc-storage-linux-amd64"
sha256: "${LINUX_AMD64_SHA256}"
bin: "ndc-storage"
files:
- from: "./ndc-storage-linux-amd64"
to: "ndc-storage"
46 changes: 46 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Lint

on:
push:
paths:
- "**.go"
- "go.mod"
- "go.sum"
- ".github/workflows/*.yaml"

env:
GO_VERSION: 1.23

jobs:
detect-modules:
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- id: set-modules
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT

golangci-lint:
needs: detect-modules
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Format
run: |
diff -u <(echo -n) <(gofmt -d -s .)
cd ndc-http-schema && diff -u <(echo -n) <(gofmt -d -s .)
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=5m
working-directory: ${{ matrix.modules }}
104 changes: 104 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Release container definition
on:
push:
tags:
- "*"

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE_NAME: hasura/ndc-storage

jobs:
tests:
uses: ./.github/workflows/test.yaml

release-image:
name: Release ndc-storage image
runs-on: ubuntu-latest
needs: [tests]
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get version from tag
id: get-version
run: |
echo "tagged_version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
shell: bash

- name: Extract metadata (tags, labels) for Docker
id: docker-metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ steps.get-version.outputs.tagged_version }}
build-cli-binaries:
name: build the CLI binaries
runs-on: ubuntu-latest
needs: [release-image]
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: build the CLI
run: |
VERSION="$GITHUB_REF_NAME" make ci-build-configuration
mkdir release
.github/scripts/plugin-manifest.sh
mv _output/* release
- uses: actions/upload-artifact@v4
with:
path: release/manifest.yaml
if-no-files-found: error
name: plugin-manifest

- uses: actions/upload-artifact@v4
with:
path: release/ndc-storage-*
if-no-files-found: error
name: artifact

- name: Get version from tag
id: get-version
run: |
echo "tagged_version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
shell: bash

- name: Build connector definition
run: |
./scripts/build-manifest.sh
env:
VERSION: ${{ steps.get-version.outputs.tagged_version }}

- name: create a draft release
uses: ncipollo/release-action@v1
with:
draft: true
tag: ${{ steps.get-version.outputs.tagged_version }}
artifacts: release/*
55 changes: 55 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Unit tests

on:
workflow_call:
pull_request:
push:
branches:
- main

jobs:
test-go:
name: Run unit and integration tests
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Format
run: diff -u <(echo -n) <(gofmt -d -s .)
- name: Vet
run: go vet ./...
- name: Run tests
run: |
./scripts/test.sh
- name: Go coverage format
if: ${{ github.event_name == 'pull_request' }}
run: |
go get github.com/boumenot/gocover-cobertura
go install github.com/boumenot/gocover-cobertura
gocover-cobertura < coverage.out > coverage.xml
- name: Code Coverage Summary Report
uses: irongut/[email protected]
if: ${{ github.event_name == 'pull_request' }}
with:
filename: coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "40 70"
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ github.event_name == 'pull_request' }}
with:
path: code-coverage-results.md
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Text editor settings
.idea/

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
tmp/

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace files
go.work
go.work.sum

# Release directory
release/
_output/
67 changes: 67 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
linters:
enable-all: true
disable:
- err113
- lll
- exportloopref
- depguard
- godot
- wrapcheck
- varnamelen
- exhaustruct
- ireturn
- gochecknoglobals
- nilnil
- mnd
- recvcheck

linters-settings:
lll:
line-length: 180

funlen:
lines: 100
statements: 50
ignore-comments: true

cyclop:
max-complexity: 20
skip-tests: true

dupl:
# Tokens count to trigger issue.
# Default: 150
threshold: 200

nestif:
min-complexity: 10

wsl:
strict-append: false
allow-cuddle-declarations: true

gosec:
excludes:
- G115
- G306

# gocritic:
# disabled-checks:
# - appendAssign
# gocyclo:
# min-complexity: 40

revive:
max-open-files: 2048
rules:
- name: var-naming
disabled: true

stylecheck:
checks:
- all
- -ST1003

issues:
exclude-files:
- ".*_test\\.go$"
Loading

0 comments on commit 964034a

Please sign in to comment.