How can I see contracts and events in the ganache UI when deploying vyper contracts locally with brownie? - ganache

Im trying to run: brownie run scripts/deploy_script.py --network development
I have these 2 config files:
# truffle-config.js
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*"
}
},
contracts_directory: '/repos/blockchain/contracts',
contracts_build_directory: '/repos/blockchain/build/contracts',
};
# Brownie config
networks:
default: development
development:
cmd_settings:
port: 8545
dev_deployment_artifacts: true

Related

Docker with Knex and PG: cannot run migration or get data from database but can connect via GUI only

I'm building a project with Node, Knex, PostgreSQL and I'm Dockerizing my project.
The main issue I have I'm unable to run the migration and also to get the data from the DB using Knex.
What I can do is use DB GUI such as Tableplus to connect to the DB.
You can find my project here:
Repo of the project
All I read online is not working for me as
use the service name \ container name -> not working :(
use full postgres url as postgresql://root:password#postgres/dbname'-> not working :(
IP address as 0.0.0.0 not working
IP address as 127.0.0.1 I can use only to run migrations/seeds but not to use the DB as GET/POST
I can use docker.internal.host but then cannot do the migration then
I'm getting always this error
getaddrinfo ENOTFOUND pokedex-db-postgres
I have no more ideas what is wrong so I'm sharing my configuration hoping someone will help me to understand
Docker file
# Builder
FROM node:17.3
RUN mkdir -p /home/node/code/node_modules && chown -R node:node /home/node/code
WORKDIR /home/node/code
COPY package*.json ./
USER node
RUN yarn install
COPY --chown=node:node . .
EXPOSE 8800
ENTRYPOINT [ "yarn", "run", "dev" ]
Docker compose
version: '3.9'
services:
node:
build: .
container_name: pokedex-backend-node
env_file:
- .env
depends_on:
postgresDB:
condition: service_started
ports:
- '8800:8800'
restart: always
volumes:
- ./:/home/node/code
postgresDB:
container_name: pokedex-db-postgres
env_file:
- .env
image: postgres:14.1
networks:
backend-database: null
postgres-pgadmin: null
expose:
- '5343:5432'
ports:
- '5343:5432'
restart: always
volumes:
- ./volumes/postgres-data:/var/lib/postgresql/data
- ./volumes/postgres-init:/docker-entrypoint-initdb.d
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U root']
interval: 10s
start_period: 10s
timeout: 4s
retries: 3
db-admin-pgadmin:
container_name: pokedex-dbadmin-pgadmin
depends_on:
postgresDB:
condition: service_started
env_file:
- .env
image: dpage/pgadmin4:latest
networks:
postgres-pgadmin: null
ports:
- '8900:80'
volumes:
- ./volumes/pgadmin-data:/var/lib/pgadmin
networks:
backend-database: {}
postgres-pgadmin: {}
Knex configuration
const development = {
client: 'pg',
connection: {
host: 'pokedex-db-postgres',
port: config.POSTGRES_PORT,
database: config.POSTGRES_DB,
user: config.POSTGRES_USER,
password: config.POSTGRES_PASSWORD,
},
pool: {
min: 5,
max: 50,
createTimeoutMillis: 3000,
acquireTimeoutMillis: 30000,
idleTimeoutMillis: 30000,
reapIntervalMillis: 1000,
createRetryIntervalMillis: 100,
afterCreate: function (conn, done) {
conn.query('SELECT 1;', function (err) {
if (err) {
log.error('Connection to DB failed %s', err);
}
done(err, conn);
});
},
},
debug: dev ? true : false,
migrations: {
directory: './src/database/migrations',
},
seeds: {
directory: './src/database/seeds',
},
useNullAsDefault: true,
};
Looks like you've defined the networks for pgadmin and postgres but didn't for the node app it explains why your node app doesn't see the other containers getaddrinfo ENOTFOUND pokedex-db-postgres

Strapi CMS, Heroku error: no pg_hba.conf entry for host

Three months ago, I created an Strapi App that has deployed on Heroku, and everything works fine. I used macOS 10.13.6 and node 14.15.4 for the local environment
The configuration of database was created inside a file named database.js which located in rootApp/config/env/production/database.js
The following are everything config inside these file (database.js):
const parse = require('pg-connection-string').parse;
const config = parse(process.env.HEROKU_POSTGRESQL_MAROON_URL);
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: "ec2-35-169-184-61.compute-1.amazonaws.com",
port: 5432,
database: "d3d9tcukxxx",
username: "mwtwuvkwxxxx",
password: "42f0337xxxxx",
},
options: {
ssl:true,
},
},
},
});
But after 3 months (right now), I checked from heroku logs --tail then these app getting an error and the message was:
error error: no pg_hba.conf entry for host "3.86.36.125", user "mwtwuvkwtrqpir", database "d3d9tcukrk5fgh", SSL off
I used Strapi 3.2.5 , and I was deployed on Heroku Postgres with Plan free (Hobby).
I hope everyone helping me for this questions, and hope helping others for same case.
Thank you
We had the same issue on our Heroku instances and just recently found a fix.
Adding rejectUnauthorized to the database config appears to work.
config/database.js
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
username: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
schema: env('DATABASE_SCHEMA', 'public'), // Not Required
ssl: {
rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false), // For self-signed certificates
},
},
options: {
ssl: env.bool('DATABASE_SSL', false),
},
},
},
});
I cannot take full credit however, it was this post on the Strapi forum that led me to the answer:
https://forum.strapi.io/t/error-no-pg-hba-conf-entry-for-host-ssl-off/3409
subsequently this link:
https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#database

Strapi giving me DB errors in production, even though I'm using correct credentials

EDIT: I found a file at /config/database.js which is used to connect to sqlite in development. When I change the client name from sqlite to postgres, that's when the trouble starts.
Isn't strapi supposed to ignore files like this in production? How can I get strapi to ignore this file, and just use my postgres db?
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'sqlite',
filename: env('DATABASE_FILENAME', '.tmp/data.db'),
},
options: {
useNullAsDefault: true,
},
},
},
});
End edit.
I'm trying to get my strapi app to start up in production, but it keeps erroring out saying
[2020-07-22T01:15:40.246Z] debug ⛔️ Server wasn't able to start properly.
[2020-07-22T01:15:40.247Z] error error: password authentication failed for user "<redacted>"
The rest of the output is related to pg, which leads me to think that this is a DB connection error.
I can log into my db from the command line using psql -U postgres -W, which confirms that I know my password.
In addition, I'm using pm2 to run things, and instead of using process.env in that file, I just added the db variables directly, but that made no difference.
The application has been built in production mode. I have 3 dbs in pg, one called postgres, one with my apps name, and another called strapi.
Thanks
my /config/enviroronments/production.database.json looks like this
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "bookshelf",
"settings": {
"client": "postgres",
"host": "${process.env.DATABASE_HOST || '127.0.0.1'}",
"port": "${process.env.DATABASE_PORT || 27017}",
"database": "${process.env.DATABASE_NAME || 'strapi'}",
"username": "${process.env.DATABASE_USERNAME || ''}",
"password": "${process.env.DATABASE_PASSWORD || ''}"
},
"options": {
"ssl": false
}
}
}
}
and I have a .env file at the root of the backend app that looks like this
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME="<redacted - all letters>"
DATABASE_USERNAME="<redacted - all letters>"
DATABASE_PASSWORD="<redacted - all letters>"
Found the issue. When I created the app, I used sqlite as my db. As a result, the default database.js file wasn't set up in a way that could be overwritten with env variables.
I created a new local Strapi app with pgsql as my db, and copied the contents of the database.js file to my server. All working now.
New file for reference
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: env('DATABASE_HOST', '127.0.0.1'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'my-strapi-project'),
username: env('DATABASE_USERNAME', 'testing'),
password: env('DATABASE_PASSWORD', 'testing'),
ssl: env.bool('DATABASE_SSL', false),
},
options: {}
},
},
});
I had the same situation in development. I created a strapi app with SQLite and decided to use PostgreSQL. That's where the trouble came in. So the fix was as follows:
app_name/config/database.js
module.exports = ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: env('DATABASE_HOST', '127.0.0.1'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'db_name'),
user: env('DATABASE_USERNAME', 'postgres'),
password: env('DATABASE_PASSWORD', 'postgres'),
ssl: env.bool('DATABASE_SSL', false),
},
},
});
Your dependencies under app_name/package.json should be like
"dependencies": {
"#strapi/strapi": "4.1.8",
"#strapi/plugin-users-permissions": "4.1.8",
"#strapi/plugin-i18n": "4.1.8",
"pg": "8.6.0"
}
[2023-02-19 11:27:27.197] debug: ⛔️ Server wasn't able to start properly.
[2023-02-19 11:27:27.199] error: password authentication failed for user "root"
FIX==>
su - postgres
psql postgres
CREATE ROLE root SUPERUSER LOGIN PASSWORD 'password';
The point of interest here is the module used with strapi .
configuration file database.js
module.exports = ({ env }) => ({
defaultConnection: "default",
connection: {
client: "postgres",
connection: {
host: "127.0.0.1",
port: 5432,
database: "dbname",
username: "postgres",
password: "password",
ssl: false
},
debug: true,
useNullAsDefault: true
}
});
version package.json
"#_sh/strapi-plugin-ckeditor": "^2.0.3",
"#strapi/plugin-i18n": "4.6.1,",
"#strapi/plugin-users-permissions": "4.6.1,",
"#strapi/strapi": "4.6.1,",
"better-sqlite3": "8.0.1",
"pg": "8.6.0"
check version
/etc/postgresql/{{version-postsql}}/main/pg_hba.conf
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
host all postgres 127.0.0.1/32 trust
host all all ::1/128 trust
restart postgresql
sudo systemctl restart postgresql.service
su - postgres
psql
DROP root;
CREATE ROLE root WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWOR 'password......';
CREATEDB dbname;
I don't know why it took the initial role of root but the above simple solution worked for me

can't find index of object

I have the following code in config.yaml
mongodb:
local:
host: "mongodb://127.0.0.1"
databaseName: "testApp"
port: 27017
development:
host:
databaseName: ""
port: 27017
production:
host:
databaseName: ""
port: 27017
I start the app with
"local": "set NODE_ENV='local' && tsnd --respawn app/main.ts --experimental-modules"
I load it in the app
global.config = yaml.safeLoad(fs.readFileSync('config.yaml', 'utf8'));
connect();
with a type
export interface IConfig {
mongodb: {
[key:string]: {
host: string
databaseName: string
port: number
},
local: {
host: string
databaseName: string
port: number
},
development: {
host: string
databaseName: string
port: number
},
production: {
host: string
databaseName: string
port: number
}
}
}
in the app I then try to access it =>
connect() {
const env = process.env.NODE_ENV as ( 'local' | 'development' | 'production');
console.log(process.env.NODE_ENV!, global.config.token[process.env.NODE_ENV!], global.config.token.local)
}
and here the result
I don't understand why I can't access the parameter with string. In the interface, I added the [key:string] but even without it doesn't change anything. I also tried remove the 'local' in the commad when I start the app. The file should be loaded Synchronously, so it's not a delay problem.

Defining Sequelize on google cloud sql nodejs

Hi i having an issue connecting to Google Cloud SQL from GAE.
My app is running inside docker container here is the docker file
FROM node:8.10.0-alpine
ARG NODE_ENV=production
ENV NODE_ENV=$NODE_ENV
# env like sql user db instance connection name
# Set a working directory
WORKDIR /usr/src/app
COPY ./build/package.json .
COPY ./build/yarn.lock .
# Install Node.js dependencies
RUN yarn install --production --no-progress
# Copy application files
COPY ./build .
COPY ./src/db/seeders ./seeds
COPY ./src/db/migrations ./migrations
COPY ./scripts ./scripts
RUN yarn run db:seed # -> failed to run this line
RUN yarn run db:migrate
# Run the container under "node" user by default
USER node
CMD [ "node", "server.js" ]
to connect to the db i'm using Sequealize this is my connection config
module.exports = {
production: {
dialect: 'postgres',
seederStorage: 'sequelize',
seederStorageTableName: 'sequelize_seeder',
username: process.env.SQL_USER,
password: process.env.SQL_PASSWORD,
database: process.env.SQL_DATABASE,
host: `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`,
logging: true,
dialectOptions: {
socketPath: `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`,
supportBigNumbers: true,
bigNumberStrings: true,
ssl: false,
},
pool: {
max: 5,
idle: 30000,
acquire: 60000,
},
operatorsAliases: false,
define: {
freezeTableName: true,
},
},
};
I tried almost everything from setting the host to localhost/127.0.0.1
While doing so i'm getting SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:5432
If i'm setting host: host:/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}``
I'm getting a different error
SequelizeConnectionError: connect ENOENT {MY_INSTANCE_CONNECTION_NAME}.s.PGSQL.5432
my app.yaml file
env: flex
runtime: custom
env_variables:
#env db user etc..
beta_settings:
cloud_sql_instances: MY_INSTANCE_CONNECTION_NAME
I tried to log in with knex and I managed to connect so i assuming something wrong with my configuration
Spent whole day today trying to connect from Google App Engine app to Google Cloud SQL (PostreSQL) when deploying through Bitbucket pipelines.
Here is the configs that worked for me (may be they will save someone few hours of life):
const sequelize = new Sequelize(DB_NAME, USERNAME, PASSWORD, {
dialect: 'postgres',
// e.g. host: '/cloudsql/my-awesome-project:us-central1:my-cloud-sql-instance'
host: '/cloudsql/${INSTANCE_CONNECTION_NAME}',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
dialectOptions: {
// e.g. socketPath: '/cloudsql/my-awesome-project:us-central1:my-cloud-sql-instance'
// same as host string above
socketPath: '/cloudsql/${INSTANCE_CONNECTION_NAME}'
},
logging: false,
operatorsAliases: false
});
app.yaml file:
runtime: nodejs
env: flex
# make sure to include code below
beta_settings:
cloud_sql_instances: my-awesome-project:us-central1:my-cloud-sql-instance
In my case when I did not provide host it failed as well all other variants with connections string when connecting to the Google Cloud SQL.
Cheers!
It looks like something is wrong with the params passed to sequlize.
Try using a simple connection string
var conString = "postgres://UserName:Password#Host:5432/YourDatabase";

Resources