diff --git a/.gitignore b/.gitignore index e6921a29aa..b3eb4c17b7 100644 --- a/.gitignore +++ b/.gitignore @@ -117,4 +117,4 @@ lefthook.yml treefmt.toml # local earthly Environments -./local/ +local/* \ No newline at end of file diff --git a/Earthfile b/Earthfile index 57ee486003..99156c0c4c 100644 --- a/Earthfile +++ b/Earthfile @@ -74,7 +74,6 @@ all: # Build and tag all Docker images BUILD ./containers/event-db-migrations+docker --tag=$tag --registry=$registry_final - BUILD ./containers/event-db-graphql+docker --tag=$tag --registry=$registry_final # Build crate images from the workspace BUILD ./src/jormungandr/jormungandr+docker --tag=$tag --registry=$registry_final @@ -128,7 +127,6 @@ tag-workspace: local: LOCALLY BUILD ./containers/event-db-migrations+docker - BUILD ./containers/event-db-graphql+docker BUILD ./src/cat-data-service+docker BUILD ./services/voting-node+docker diff --git a/Makefiles/db.toml b/Makefiles/db.toml index 00dfbbfd8d..90dcd19a1e 100644 --- a/Makefiles/db.toml +++ b/Makefiles/db.toml @@ -6,9 +6,7 @@ install_crate = { crate_name = "refinery_cli", binary = "refinery", test_arg = " # All the prerequisite tooling needed to work with the DB. [tasks.install-db-prereqs] workspace = false -run_task = { name = [ - "install-refinery-cli", - ], parallel = true } +run_task = { name = ["install-refinery-cli"], parallel = true } # Setup the local database ready to run the migrations. [tasks.local-event-db-init] @@ -75,36 +73,14 @@ psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_5.sql ${@} # psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_9.sql ${@} ''' -# Setup the local database graphql configuration. -[tasks.local-event-db-graphql-init] -workspace = false -category = "db" -script_runner = "@shell" -script = ''' -cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db -export ADMIN_ROLE_PW="CHANGE_ME" -export ANON_ROLE_PW="CHANGE_ME" -export ADMIN_USER_PW="CHANGE_ME" - -psql -U postgres -f setup/graphql-setup.sql \ - -v dbName=CatalystEventDev \ - -v dbUser="catalyst-event-dev" \ - -v adminUserFirstName="Admin" \ - -v adminUserLastName="Default" \ - -v adminUserAbout="Default Admin User" \ - -v adminUserEmail="admin.default@projectcatalyst.io" ${@} -''' - - # Setup the local database ready to run the migrations. [tasks.local-event-db-setup] workspace = false category = "db" dependencies = [ "local-event-db-init", - "local-event-db-graphql-init", "run-event-db-migration", - "local-db-historic-data-setup" + "local-db-historic-data-setup", ] # Setup the local database with the test data. @@ -114,11 +90,10 @@ category = "db" dependencies = [ "local-event-db-init", "run-event-db-migration", - "local-db-test-data-setup" + "local-db-test-data-setup", ] - # Run Diesel Migrations, for documentation purposes. [tasks.run-event-doc-db-migration] workspace = false @@ -147,7 +122,4 @@ psql -e -f setup/setup-db.sql \ [tasks.doc-event-db-setup] workspace = false category = "db" -dependencies = [ - "doc-event-db-init", - "run-event-doc-db-migration" -] +dependencies = ["doc-event-db-init", "run-event-doc-db-migration"] diff --git a/README.md b/README.md index 4099a5234e..d9a7d83fbc 100644 --- a/README.md +++ b/README.md @@ -30,38 +30,89 @@ - [What's inside?](#whats-inside) - [Requirements](#requirements) - [Development](#development) - - [Development Environment (NIX Shell)](#development-environment-nix-shell) - - [Development Environment (Manual)](#development-environment-manual) + - [Earthly](#earthly) + - [Manual](#manual) - [Prerequisites](#prerequisites) - [Linux](#linux) - [macOS](#macos) - [Windows](#windows) + - [Nix](#nix) - [Install Extra Packages/Tools](#install-extra-packagestools) - - [Testing](#testing) - - [Deployment](#deployment) - [Building Documentation](#building-documentation) - [Support](#support) - [License](#license) ## What's inside? -TODO: +- [Catalyst Core Governance Engine](catalyst-core/README.md) ## Requirements +- [Rust](https://www.rust-lang.org/tools/install) +- [Docker](https://docs.docker.com/get-docker/) +- [Earthly](https://earthly.dev/get-earthly) + ## Development -### Development Environment (NIX Shell) +### Earthly + +> **Note**: This is the preferred development environment. + +Make sure that docker is running and then run: + +```sh +# This command can take a while to run. +earthly +local +``` + then run: -This is the **preferred** development environment. +```sh +docker-compose -f local/docker-compose.yml up +``` -1. Install NIX : -2. Start a nix development environment (From the repo Root): - `nix develop` +You should now be able to use [Catalyst Core API V1](https://input-output-hk.github.io/catalyst-core/main/07_web_api/catalyst-core-api.html) locally: -### Development Environment (Manual) +Open a new terminal window and run: -~~ ***NOT RECOMMENDED*** ~~ +```sh +curl --request GET \ + --url http://localhost:3030/api/v1/events \ + --header 'Accept: application/json' +``` + +you should get list of events: + +```json +[ + { + "id": 0, + "name": "Catalyst Fund 0", + "starts": "2020-05-22T00:00:00+00:00", + "ends": "2020-06-24T00:00:00+00:00", + "final": true + }, + { + "id": 1, + "name": "Catalyst Fund 1", + "starts": "2020-08-08T00:00:00+00:00", + "ends": "2020-09-22T00:00:00+00:00", + "final": true + }, +. +. +. +. + { + "id": 9, + "name": "Catalyst Fund 9", + "starts": "2022-06-02T00:00:00+00:00", + "ends": "2022-10-11T00:00:00+00:00", + "final": true + } +] +``` + +### Manual #### Prerequisites @@ -87,23 +138,20 @@ brew install protobuf-c libsigsegv libpq libserdes pkg-config choco install protoc openssl sqlite postgresql14 ``` -### Install Extra Packages/Tools +### Nix -This only needs to be done once when the development environment is created. +> **⛔️ Note**: Nix packaging code is deprecated and will be removed in a future. -1. `cargo install cargo-binstall --locked` : see -2. `cargo binstall --no-confirm cargo-make` : see -3. `cargo make install-prereqs` +- Install [Nix](https://nixos.org/download.html) +- Start a nix development environment (from the repo root): `nix develop` -TODO: Can this (or an equivalent) be done by the devshell? - -## Testing - -TODO: +### Install Extra Packages/Tools -## Deployment +This only needs to be done once when the development environment is created. -TODO: +- `cargo install cargo-binstall --locked` +- `cargo binstall --no-confirm cargo-make` +- `cargo make install-prereqs` ## Building Documentation diff --git a/containers/dev-local/docker-compose.yml b/containers/dev-local/docker-compose.yml index 555de3ae61..e4e804bfc8 100644 --- a/containers/dev-local/docker-compose.yml +++ b/containers/dev-local/docker-compose.yml @@ -39,18 +39,6 @@ services: db: condition: service_healthy - graphql: - image: event-db-graphql:latest - environment: - - DATABASE_URL=postgres://catalyst-event-dev:CHANGE_ME@db/CatalystEventDev - - JWT_SECRET=CHANGE_ME - - GRAPHQL_PORT=5000 - ports: - - 5000:5000 - depends_on: - migrations: - condition: service_completed_successfully - cat-data-service: image: cat-data-service:latest environment: diff --git a/containers/event-db-graphql/Earthfile b/containers/event-db-graphql/Earthfile deleted file mode 100644 index 2075db1c45..0000000000 --- a/containers/event-db-graphql/Earthfile +++ /dev/null @@ -1,71 +0,0 @@ -VERSION 0.7 -FROM node:12-alpine -WORKDIR /postgraphile - -builder: - # Clone the source code - GIT CLONE --branch tags/v4.13.0 "https://github.com/graphile/postgraphile" /src - - # Install root dependencies - RUN cp /src/package.json /src/yarn.lock . - RUN yarn install --frozen-lockfile --production=false --no-progress - - # Install postgraphiql dependencies - RUN cp -r /src/postgraphiql postgraphiql - WORKDIR /postgraphile/postgraphiql/ - RUN yarn install --frozen-lockfile --production=false --no-progress - - # Copy the remaining source code - WORKDIR /src - RUN cp tsconfig.json .eslintrc.js .eslintignore prettier.config.js .prettierignore /postgraphile - RUN cp index.js cli.js /postgraphile - RUN cp *.md /postgraphile - RUN cp -r src/ /postgraphile/src - RUN cp -r assets/ /postgraphile/assets - RUN cp -r typings/ /postgraphile/typings - RUN cp -r scripts/ /postgraphile/scripts - - # Run the build script - WORKDIR /postgraphile - RUN ./scripts/build - - SAVE ARTIFACT /postgraphile - -build: - # Clone the source code - GIT CLONE --branch tags/v4.13.0 "https://github.com/graphile/postgraphile" /src - WORKDIR /src - - # Copy scripts - RUN cp index.js cli.js isTurbo.js plugins.js plugins.d.ts /postgraphile - RUN cp docker/.postgraphilerc.js /postgraphile - - # Copy artifacts from builder - COPY +builder/postgraphile/package.json +builder/postgraphile/yarn.lock /postgraphile/ - COPY +builder/postgraphile/build/ /postgraphile/build/ - COPY +builder/postgraphile/build-turbo/ /postgraphile/build-turbo/ - COPY +builder/postgraphile/sponsors.json /postgraphile/ - - # Add plugins - RUN yarn add @graphile-contrib/pg-simplify-inflector - - # Run build one final time - WORKDIR /postgraphile - RUN yarn install --frozen-lockfile --production=true --no-progress - - - # Save the result - SAVE ARTIFACT /postgraphile AS LOCAL output/postgraphile - SAVE IMAGE --cache-hint - -docker: - ARG tag="latest" - ARG registry - COPY +build/postgraphile /postgraphile - COPY entry.sh . - - ENV DEBUG="graphile-build-pg,postgraphile:postgres*" - ENV GRAPHQL_PORT=5000 - EXPOSE 5000 - ENTRYPOINT ["sh", "./entry.sh"] - SAVE IMAGE --push ${registry}event-db-graphql:$tag diff --git a/containers/event-db-graphql/entry.sh b/containers/event-db-graphql/entry.sh deleted file mode 100644 index bb81c3e3b1..0000000000 --- a/containers/event-db-graphql/entry.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -# --------------------------------------------------------------- -# Entrypoint script for migrations container -# --------------------------------------------------------------- -# -# This script serves as the entrypoint for the migrations container. It sets up -# the environment, performing optional database initialization if configured, -# and then runs the migrations. -# -# It expects the following environment variables to be set except where noted: -# -# DATABASE_URL - The URL of the database -# JWT_SECRET - JWT secret for JWT authentication -# GRAPHQL_PORT - The port of the graphql server (optional) -# --------------------------------------------------------------- - -if [ -z "$DATABASE_URL" ]; then - echo "ERROR: DATABASE_URL environment variable is not set." - exit 1 -fi - -if [ -z "$JWT_SECRET" ]; then - echo "ERROR: JWT_SECRET environment variable is not set." - exit 1 -fi - -if [ -z "$GRAPHQL_PORT" ]; then - GRAPHQL_PORT="5000" - echo "WARNING: GRAPHQL_PORT environment variable is not set. Defaulting to 5000." -fi - -npx -c ./cli.js \ - --connection "$DATABASE_URL" \ - --port "$GRAPHQL_PORT" \ - --cors \ - --subscriptions \ - --dynamic-json \ - --no-setof-functions-contain-nulls \ - --no-ignore-rbac \ - --show-error-stack=json \ - --extended-errors hint,detail,errcode \ - --append-plugins @graphile-contrib/pg-simplify-inflector \ - --export-schema-graphql schema.graphql \ - --graphiql "/" \ - --enhance-graphiql \ - --allow-explain \ - --enable-query-batching \ - --legacy-relations omit \ - --schema public,private \ - --default-role cat_anon \ - --jwt-secret "$JWT_SECRET" \ - --jwt-token-identifier private.jwt_token diff --git a/services/voting-node/docker-compose.yml b/services/voting-node/docker-compose.yml index 0da4e5b304..6e613d6bce 100644 --- a/services/voting-node/docker-compose.yml +++ b/services/voting-node/docker-compose.yml @@ -39,18 +39,6 @@ services: postgres: condition: service_healthy - graphql: - image: event-db-graphql:latest - environment: - - DATABASE_URL=postgres://catalyst-event-dev:CHANGE_ME@postgres/CatalystEventDev - - JWT_SECRET=CHANGE_ME - - GRAPHQL_PORT=5000 - ports: - - 5000:5000 - depends_on: - migrations: - condition: service_completed_successfully - cat-data-service: image: cat-data-service:latest environment: @@ -147,7 +135,7 @@ services: otel-collector: image: otel/opentelemetry-collector:latest - command: [ "--config=/etc/otel-collector.yaml" ] + command: ["--config=/etc/otel-collector.yaml"] volumes: - ./extras/otel-collector.yaml:/etc/otel-collector.yaml ports: @@ -170,13 +158,13 @@ services: tempo: image: grafana/tempo:latest - command: [ "-config.file=/etc/tempo.yaml" ] + command: ["-config.file=/etc/tempo.yaml"] volumes: - ./extras/tempo-local.yaml:/etc/tempo.yaml - ./extras/tempo-data:/tmp/tempo ports: - - "3200:3200" # tempo - - "4317" # otlp grpc + - "3200:3200" # tempo + - "4317" # otlp grpc profiles: - "donotstart" diff --git a/src/event-db/setup/dev-db.docker-compose.yml b/src/event-db/setup/dev-db.docker-compose.yml index 5836e8fb86..54f305cbe9 100644 --- a/src/event-db/setup/dev-db.docker-compose.yml +++ b/src/event-db/setup/dev-db.docker-compose.yml @@ -1,9 +1,8 @@ # Start a local development postgres-14 DB # Default username/password = postgres:postgres -version: '3.1' +version: "3.1" services: - db: image: postgres:14 restart: always @@ -37,18 +36,6 @@ services: db: condition: service_healthy - graphql: - image: event-db-graphql:latest - environment: - - DATABASE_URL=postgres://catalyst-event-dev:CHANGE_ME@db/CatalystEventDev - - JWT_SECRET=CHANGE_ME - - GRAPHQL_PORT=5000 - ports: - - 5000:5000 - depends_on: - migrations: - condition: service_completed_successfully - adminer: image: adminer restart: always