Skip to content

Commit

Permalink
feat: PRO-2455 refactor local docker setup instructions and local pos…
Browse files Browse the repository at this point in the history
…tgres database docker file setup to project root directory
  • Loading branch information
kanthgithub committed Jun 25, 2024
1 parent 1e47614 commit 024696e
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ DEFAULT_API_KEY=""
WEBHOOK_URL=
HMAC_SECRET=
DATABASE_URL=
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_NAME=
DATABASE_SCHEMA_NAME=arka
DATABASE_SSL_ENABLED=false
DATABASE_SSL_REJECT_UNAUTHORIZED=false
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,114 @@ To run your own instance of this, please [follow these steps.](https://github.co

You can see a [list of available endpoints here](https://github.com/etherspot/arka/tree/master/backend#available-endpoints--).


### Local - Setup

#### environment for backend

1. Start Docker postgres database

```sh
cd local-setup
```

```sh
docker-compose up -d
```

- Verify if the postgres docker instance is up and running

```sh
docker ps -a
```

```sh
docker logs --follow local-setup-db-1
```

- It must show up logs similar to this

```
PostgreSQL init process complete; ready for start up.
2024-06-24 19:31:56.739 UTC [1] LOG: starting PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-06-24 19:31:56.740 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2024-06-24 19:31:56.740 UTC [1] LOG: listening on IPv6 address "::", port 5432
2024-06-24 19:31:56.741 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-06-24 19:31:56.744 UTC [66] LOG: database system was shut down at 2024-06-24 19:31:56 UTC
2024-06-24 19:31:56.748 UTC [1] LOG: database system is ready to accept connections
```

2. create .env

```sh
cp .env.example .env
```

3. populate these environment variables

```sh
LOG_LEVEL=
API_HOST=
API_PORT=
UNSAFE_MODE=true
SUPPORTED_NETWORKS=
CRON_PRIVATE_KEY=
DEFAULT_INDEXER_ENDPOINT=
FEE_MARKUP=0
MULTI_TOKEN_MARKUP=
ADMIN_WALLET_ADDRESS=
ETHERSCAN_GAS_ORACLES=""
DEFAULT_API_KEY=""
WEBHOOK_URL=
HMAC_SECRET=
DATABASE_URL=
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_NAME=
DATABASE_SCHEMA_NAME=arka
DATABASE_SSL_ENABLED=false
DATABASE_SSL_REJECT_UNAUTHORIZED=false
```

4. start docker instance for backend, admin_frontend, frontend

```sh
docker-compose up --build -d
```

5. Here we need to create a network and tag backend & postgres on same network

```sh
docker network create arka-network
```

6. add postgres instance to docker network

```sh
docker network connect arka-network local-setup-db-1
```

7. add arka backend docker instance to docker-network

```sh
docker network connect arka-network arka-backend-1
```

8. restart backend docker instance

```sh
docker-compose up -d
```

9. verify backend logs

```sh
docker logs arka-backend-1
```

## 🖥 Arka Admin Frontend

This contains ability to change configuration that are available in sql.
This contains ability to change system configuration, apiKeys and apiKey-config that are available in database.

## 🖥 Arka Frontend

Expand Down
95 changes: 2 additions & 93 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,97 +184,6 @@ Parameters:

## Local Docker Networks

1. Ensure the postgres docker instance is up and running
1. Follow steps for local network setup in main readme.MD file in project root-directory
[project-readme-steps](../README.md)

```sh
cd backend/local-setup
```

2. Start `postgres` database instance

```sh
docker-compose up -d
```

3. Here we need to create a network and tag backend & postgres on same network

```sh
docker network create arka-network
```

```sh
docker network connect arka-network local-setup-db-1
```

4. change to backend directory

```sh
cd ../
```

5. create environment file

```sh
touch .env.example .env
```

6. set values for

```sh
# postgres environment variables
DATABASE_URL=""
DATABASE_USER=""
DATABASE_PASSWORD=""
DATABASE_NAME=""
```

7. change to project root directory

```sh
cd ../
```

8. create .env

```sh
cp .env.example .env
```

9. populate these environment variables

```sh
LOG_LEVEL=debug
API_HOST=0.0.0.0
API_PORT=5050
UNSAFE_MODE=true
SUPPORTED_NETWORKS=
CRON_PRIVATE_KEY=""
DEFAULT_INDEXER_ENDPOINT=http://localhost:3003
FEE_MARKUP=0
MULTI_TOKEN_MARKUP=1150000
ADMIN_WALLET_ADDRESS=""
ETHERSCAN_GAS_ORACLES=""
DEFAULT_API_KEY=""
WEBHOOK_URL=""
HMAC_SECRET=""
DATABASE_URL=""
DATABASE_SCHEMA_NAME=arka
```

10. start docker instance for backend, admin_frontend, frontend

```sh
docker-compose up --build -d
```

11. add arka backend docker instance to docker-network

```sh
docker network connect arka-network arka-backend-1
```

12. restart backend docker instance

```sh
docker-compose up -d
```
1 change: 1 addition & 0 deletions backend/scripts/migration.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { Umzug, SequelizeStorage } = require('umzug');
const dotenv = require('dotenv');
dotenv.config({ path: path.resolve(__dirname, '../.env') });

// node backend/scripts/migration.cjs
async function runMigrations() {
let sequelize;
try {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/sponsorship-policy-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ const sponsorshipPolicyRoutes: FastifyPluginAsync = async (server) => {
if (!apiKeyData) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY });

// get sponsorshipPolicy for the user from walletAddress and entrypoint version
const sponsorshipPolicy: SponsorshipPolicy | null = await server.sponsorshipPolicyRepository.findOneByWalletAddressAndSupportedEPVersion(apiKeyData?.walletAddress, getEPVersion(epVersion), chainId);
const sponsorshipPolicy: SponsorshipPolicy | null = await server.sponsorshipPolicyRepository.findOneByWalletAddressAndSupportedEPVersionAndChain(apiKeyData?.walletAddress, getEPVersion(epVersion), chainId);
if (!sponsorshipPolicy) {
const errorMessage: string = generateErrorMessage(ErrorMessage.ACTIVE_SPONSORSHIP_POLICY_NOT_FOUND, { walletAddress: apiKeyData?.walletAddress, epVersion: epVersion, chainId: chainId });
return reply.code(ReturnCode.FAILURE).send({ error: errorMessage });
Expand Down Expand Up @@ -452,7 +452,7 @@ const sponsorshipPolicyRoutes: FastifyPluginAsync = async (server) => {
}

// get sponsorshipPolicy for the user from walletAddress and entrypoint version
const sponsorshipPolicy: SponsorshipPolicy | null = await server.sponsorshipPolicyRepository.findOneByWalletAddressAndSupportedEPVersion(walletAddress, getEPVersion(epVersion), chainId);
const sponsorshipPolicy: SponsorshipPolicy | null = await server.sponsorshipPolicyRepository.findOneByWalletAddressAndSupportedEPVersion(walletAddress, getEPVersion(epVersion));
if (!sponsorshipPolicy) {
const errorMessage: string = generateErrorMessage(ErrorMessage.ACTIVE_SPONSORSHIP_POLICY_NOT_FOUND, { walletAddress: walletAddress, epVersion: epVersion, chainId: chainId });
return reply.code(ReturnCode.FAILURE).send({ error: errorMessage });
Expand Down
5 changes: 3 additions & 2 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const initializeServer = async (): Promise<void> => {
const buffer = Buffer.from(paymastersAdrbase64, 'base64');
const DEPLOYED_ERC20_PAYMASTERS = JSON.parse(buffer.toString());
Object.keys(DEPLOYED_ERC20_PAYMASTERS).forEach(async (chain) => {
const networkConfig = getNetworkConfig(chain, '');
//EP-v6 entrypoint address
const networkConfig = getNetworkConfig(chain, '', "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789");
if (networkConfig) {
const deployedPaymasters: string[] = DEPLOYED_ERC20_PAYMASTERS[chain];
const provider = new providers.JsonRpcProvider(networkConfig.bundler);
Expand Down Expand Up @@ -223,7 +224,7 @@ const initializeServer = async (): Promise<void> => {
}
customPaymasters = { ...customPaymasters, ...multiTokenPaymasters };
for (const chainId in customPaymasters) {
const networkConfig = getNetworkConfig(chainId, '');
const networkConfig = getNetworkConfig(chainId, '', "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789");
if (networkConfig) {
for (const symbol in customPaymasters[chainId]) {
checkDeposit(customPaymasters[chainId][symbol], networkConfig.bundler, process.env.WEBHOOK_URL, networkConfig.thresholdValue ?? '0.001', Number(chainId), server.log)
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 024696e

Please sign in to comment.