diff --git a/.env.hasura.sample b/.env.hasura.sample new file mode 100644 index 000000000..d29b574cd --- /dev/null +++ b/.env.hasura.sample @@ -0,0 +1,4 @@ +# Use for hasura cli +HASURA_GRAPHQL_VERSION=3 +HASURA_GRAPHQL_ENDPOINT= +HASURA_GRAPHQL_ADMIN_SECRET= \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45ceaea3b..6140e7aae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 diff --git a/.gitignore b/.gitignore index ff976db11..8c4ee3b8a 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ typings/ # dotenv environment variables file .env +.env.hasura # next.js build output .next diff --git a/Dockerfile.hasura b/Dockerfile.hasura new file mode 100644 index 000000000..93ff2a2fb --- /dev/null +++ b/Dockerfile.hasura @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 4f59a85d1..ef73cc647 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/hasura/config.yaml b/hasura/config.yaml new file mode 100644 index 000000000..725c8005e --- /dev/null +++ b/hasura/config.yaml @@ -0,0 +1,6 @@ +version: 3 +endpoint: http://localhost:8080 +metadata_directory: metadata +actions: + kind: synchronous + handler_webhook_baseurl: http://localhost:3000 diff --git a/hasura/metadata/actions.graphql b/hasura/metadata/actions.graphql new file mode 100644 index 000000000..e69de29bb diff --git a/hasura/metadata/actions.yaml b/hasura/metadata/actions.yaml new file mode 100644 index 000000000..1979211cb --- /dev/null +++ b/hasura/metadata/actions.yaml @@ -0,0 +1,6 @@ +actions: [] +custom_types: + enums: [] + input_objects: [] + objects: [] + scalars: [] diff --git a/hasura/metadata/allow_list.yaml b/hasura/metadata/allow_list.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/metadata/allow_list.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/metadata/cron_triggers.yaml b/hasura/metadata/cron_triggers.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/metadata/cron_triggers.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/metadata/databases/databases.yaml b/hasura/metadata/databases/databases.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/metadata/databases/databases.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/metadata/query_collections.yaml b/hasura/metadata/query_collections.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/metadata/query_collections.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/metadata/remote_schemas.yaml b/hasura/metadata/remote_schemas.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/metadata/remote_schemas.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/metadata/version.yaml b/hasura/metadata/version.yaml new file mode 100644 index 000000000..0a70affa4 --- /dev/null +++ b/hasura/metadata/version.yaml @@ -0,0 +1 @@ +version: 3