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: manage hasura metadata #335

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
704da28
feat: install hasura-cli in dockerfile, add env for hasura-cli, add c…
fibonacci998 Aug 22, 2023
b66275e
fix: create new .env.hasura; update install hasura in dockerfile; upd…
fibonacci998 Aug 23, 2023
60e0baa
feat: remove command run hasura through npm, update README use hasura
fibonacci998 Aug 23, 2023
9a37c6a
fix: remove env not used
fibonacci998 Aug 23, 2023
81deb1d
fix: change Dockerfile to node:16 (hasura cli cannot used with node:1…
fibonacci998 Aug 28, 2023
6ff5c72
feat: create dockerfile for hasura-cli
fibonacci998 Sep 5, 2023
32535c4
feat: create ci to build hasura
fibonacci998 Sep 6, 2023
8500faf
feat: update ci for hasura
fibonacci998 Sep 6, 2023
748c238
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
53af8e0
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
ecfa8bb
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
23927ff
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
2c4ac4e
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
a6a57bd
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
1a5a93f
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
6694b86
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
7976d21
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
a548a50
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
b997f15
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
6d66a03
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
75dc2a7
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
345d841
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
6619399
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
9dc6fd1
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
3a17f37
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
ff8a1f2
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
cd97ae8
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
d006a96
fix: update ci for hasura build
fibonacci998 Sep 6, 2023
c1752e1
feat: create empty hasura directory
fibonacci998 Sep 6, 2023
d2b812f
fix: remove test branch in ci
fibonacci998 Sep 6, 2023
ae2832d
feat: add dockerfile.hasura to ci
fibonacci998 Sep 6, 2023
ed9e30f
fix: update workdir in dockerfile.hasura
fibonacci998 Sep 6, 2023
ca877d1
feat: update gitops after build hasura
fibonacci998 Sep 19, 2023
3e19a04
fix: add condition to run update manifest hasura
fibonacci998 Sep 19, 2023
c14d7c8
fix: set output to job build-hasura-metadata
fibonacci998 Sep 22, 2023
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
4 changes: 4 additions & 0 deletions .env.hasura.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Use for hasura cli
HASURA_GRAPHQL_VERSION=3
HASURA_GRAPHQL_ENDPOINT=
HASURA_GRAPHQL_ADMIN_SECRET=
63 changes: 62 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,46 @@ jobs:
NPM_TOKEN: ${{ secrets.KEY_NPM_RC }}
run: |
./ci/build.sh
build-hasura-metadata:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set environment variable
run: |
SHORT_SHA_COMMIT=$(git rev-parse --short HEAD)
echo CONTAINER_RELEASE_IMAGE=ghcr.io/aura-nw/horoscope-hasura:${GITHUB_REF_NAME}_${SHORT_SHA_COMMIT} >> $GITHUB_ENV
- name: Check hasura changes
id: NUMBER_CHANGES
run: |
STATUS=`git diff HEAD^ HEAD hasura`
NUMBER_CHANGES=${#STATUS}
echo $NUMBER_CHANGES
echo NUMBER_CHANGES=$NUMBER_CHANGES >> $GITHUB_OUTPUT
- name: Build and push
if: ${{steps.NUMBER_CHANGES.outputs.NUMBER_CHANGES != 0}}
uses: docker/build-push-action@v4
with:
file: Dockerfile.hasura
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
${{ env.CONTAINER_RELEASE_IMAGE }}
outputs:
NUMBER_CHANGES: ${{ steps.NUMBER_CHANGES.outputs.NUMBER_CHANGES }}

updateManifest:
update-manifest:
runs-on: [ubuntu-latest]
needs: [lint, test, build]
steps:
Expand All @@ -49,3 +87,26 @@ jobs:
PERSONAL_ACCESS_TOKEN: ${{ secrets.REGISTRY_PASSWORD }}
run: |
./ci/updateManifest.sh
update-manifest-hasura:
runs-on: [ubuntu-latest]
needs: [build-hasura-metadata]
if: ${{needs.build-hasura-metadata.outputs.NUMBER_CHANGES != 0}}
steps:
- uses: actions/checkout@v3
- uses: imranismail/setup-kustomize@v2
- name: Set environment variable
run: |
SHORT_SHA_COMMIT=$(git rev-parse --short HEAD)
echo CONTAINER_RELEASE_IMAGE=ghcr.io/aura-nw/horoscope-hasura:${GITHUB_REF_NAME}_${SHORT_SHA_COMMIT} >> $GITHUB_ENV
echo REPO_MANIFEST_NAME=gitops >> $GITHUB_ENV
echo REPO_MANIFEST_URL=github.com/aura-nw/gitops.git >> $GITHUB_ENV
echo REPO_MANIFEST_BRANCH=master >> $GITHUB_ENV
echo REPO_MANIFEST_ENV_DEV=./clusters/k8s-dev/horoscope-v2/horoscope-crawl-auratestnet >> $GITHUB_ENV
echo REPO_MANIFEST_ENV_STAGING=./clusters/k8s-testnet-euphoria/horoscope-v2/horoscope-crawl-euphoria >> $GITHUB_ENV
echo REPO_MANIFEST_ENV_MAIN=./clusters/k8s-prod/horoscope-v2/horoscope-crawl-xstaxy >> $GITHUB_ENV
echo REPO_MANIFEST_TAG_IMAGE=image_hasura >> $GITHUB_ENV
- name: Update manifest
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.REGISTRY_PASSWORD }}
run: |
./ci/updateManifest.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typings/

# dotenv environment variables file
.env
.env.hasura

# next.js build output
.next
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile.hasura
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:16

## Install hasura cli
RUN curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash

# Working directory
WORKDIR /app

# Copy source
COPY . .

# cd to hasura directory
WORKDIR /app/hasura

# Apply metadata
CMD ["hasura", "metadata", "apply"]
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,36 @@ then start service

```
# create file env
cp .env.example .env
cp .env.sample .env

# run with moleculer cli
npm run dev
```

### Hasura metadata migration

Read [link](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/) to install Hasura CLI for your operating system. To make update to hasura metadata programmatically, use sample code below:

```
# init hasura directory
hasura init hasura

# create file env hasura
cp .env.hasura.sample hasura/.env

# go to hasura directory
cd hasura

# export current metadata from hasura
hasura metadata export

# check current diff between local and hasura server
hasura metadata diff

# apply current hasura metadata to server
hasura metadata apply
```

## Configuration

[Config Moleculer](.env.sample), refer [docs](https://moleculer.services/docs/0.14/configuration.html) to get detail configurations
Expand Down
6 changes: 6 additions & 0 deletions hasura/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 3
endpoint: http://localhost:8080
metadata_directory: metadata
actions:
kind: synchronous
handler_webhook_baseurl: http://localhost:3000
Empty file added hasura/metadata/actions.graphql
Empty file.
6 changes: 6 additions & 0 deletions hasura/metadata/actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
actions: []
custom_types:
enums: []
input_objects: []
objects: []
scalars: []
1 change: 1 addition & 0 deletions hasura/metadata/allow_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions hasura/metadata/cron_triggers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions hasura/metadata/databases/databases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions hasura/metadata/remote_schemas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions hasura/metadata/version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 3
Loading