Can't make my Phoenix app build on Heroku CI - heroku

I can't manage to make my Phoenix 1.2 app to run on Heroku CI.
It seems it's trying to create a new database, and even though I configured an alias, it's still performing ecto.create.
Here is Heroku CI output:
-----> Running Elixir buildpack tests... 10:25:25.751 [warn] Warning: No valid AppSignal configuration found, continuing with AppSignal metrics disabled. 10:25:26.071 [error] GenServer #PID<0.903.0> terminating
** (Postgrex.Error) FATAL (insufficient_privilege): permission denied for database "template1" User does not have CONNECT privilege.
(db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 Last message: nil
** (Mix) The database for PhenixDisplays.Repo couldn't be created: FATAL (insufficient_privilege): permission denied for database "template1" User does not have CONNECT privilege.
-----> Elixir buildpack tests failed with exit status 1
My mix.exs aliases function
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
"test": ["ecto.migrate", "test"]
]
end
And my repo setup in test.exs
config :phenix_displays, PhenixDisplays.Repo,
adapter: Ecto.Adapters.Postgres,
url: System.get_env("DATABASE_URL") || "postgres://postgres:postgres#localhost:5432/phenix_displays_test",
pool: Ecto.Adapters.SQL.Sandbox,
extensions: [{Geo.PostGIS.Extension, library: Geo}, {PhenixDisplays.Postgrex.Box2D, []}]

It might be that mix ecto.setup is being called as part of the preparations to run your tests. HerokuCI seems to use an app.json file for configuration of your tests. This is an example I found at https://devcenter.heroku.com/articles/heroku-ci
{
"environments": {
"test": {
"scripts": {
"test-setup": "gem install rubocop",
"test": "rubocop ."
}
}
}
}
Make sure that the correct test-setup is configured and that it only runs the commands you want it to run.

Related

Why can't I get my github action to run under the proper project when the workload identity is in another pool

I have 2 gcp projects pool-infra pool-dev. I use a github action to run a mvn command the configuration look like this...
- name: Authenticate with pure-infra project
uses: 'google-github-actions/auth#v0.8.1'
with:
service_account: my#pool-infra.iam.gserviceaccount.com
workload_identity_provider: projects/<pool-infra-id>/locations/global/workloadIdentityPools/....
token_format: 'access_token'
project_id: pure-platform-dev
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud#v1'
with:
project_id: pool-app
- name: Run Package
working-directory: my-service
run: |
gcloud config set project pool-app
gcloud config get project
mvn clean package jacoco:report
But I see an error that suggests the project ID is incorrect...
"errors": [
{
"domain": "usageLimits",
"message": "Cloud SQL Admin API has not been used in project <pool-infra-num> before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sqladmin.googleapis.com/overview?project=<pool-infra-num> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com"
}
],
I would expect those project nums to be for pool-app not infra. What am I missing? How do I properly set the project for the mvn project?
This is coming from the JDBC connection pool when it tries to connect.

Spring Boot app in Docker container not starting in Cloud Run after building successfully - cannot access jarfile

I've set up continuous deployment to Cloud Run from GitHub for my Spring Boot project, and while it's successfully building in Cloud Build, when I go over to Cloud Run, I get the following error under Creating Revision:
The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable.
When I go over to the Logs, I see the following errors:
2022-09-23 09:42:47.881 BST
Error: Unable to access jarfile /app/target/educity-manager-0.0.1-SNAPSHOT.jar
{
insertId: "632d7187000d739d29eb84ad"
labels: {5}
logName: "projects/educity-manager/logs/run.googleapis.com%2Fstderr"
receiveTimestamp: "2022-09-23T08:42:47.883252595Z"
resource: {2}
textPayload: "Error: Unable to access jarfile /app/target/educity-manager-0.0.1-SNAPSHOT.jar"
timestamp: "2022-09-23T08:42:47.881565Z"
}
2022-09-23 09:43:48.800 BST
run.googleapis.com
…ager/revisions/educity-manager-00011-fod
Ready condition status changed to False for Revision educity-manager-00011-fod with message: Deploying Revision.
{
insertId: "w6ptr6d20ve"
logName: "projects/educity-manager/logs/cloudaudit.googleapis.com%2Fsystem_event"
protoPayload: {
#type: "type.googleapis.com/google.cloud.audit.AuditLog"
resourceName: "namespaces/educity-manager/revisions/educity-manager-00011-fod"
response: {6}
serviceName: "run.googleapis.com"
status: {2}}
receiveTimestamp: "2022-09-23T08:43:49.631015104Z"
resource: {2}
severity: "ERROR"
timestamp: "2022-09-23T08:43:48.800371Z"
}
Dockerfile is as follows (and looking at the build log all of the commands in it completed successfully):
FROM openjdk:17-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
COPY . /app
ENTRYPOINT [ "java","-jar","/app/target/educity-manager-0.0.1-SNAPSHOT.jar" ]
I've read that Cloud Run defaults to exposing Port 8080, but just to be on the safe side I've put server.port=${PORT:8080} in my application.properties file (but it seems to make no difference one way or the other).
I have run into similar issues in the past. Usually, I am able to resolve this issue by:
specifying the port in the application itself (as you indicated in your post), and
exposing the required port in my dockerfile eg. EXPOSE 8080
Oh my good god I have done it. After two full days of digging, I realised that because I was doing it through github, my .gitignore file was excluding the /target folder containing the jar file, so Cloud Build never got the jar file mentioned in the Dockerfile.
I am going to have a cry and then go to the pub.

Can not deploy my contract on ganache-cli using ETH mainnet fork

I used ganache-cli in combination with my Infura key to fork ETH mainnet so I could use the Uniswap router in my development environment:
ganache-cli --fork https://mainnet.infura.io/v3/<mykeyhere>
This starts my local ganache blockchain without any errors. However when I deploy my contract with truffle:
truffle(development)> deploy
I keep getting the following error:
Compiling your contracts...
===========================
✓ Fetching solc version list from solc-bin. Attempt #1
✓ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/MollyCoin.sol
> Artifacts written to /home/dogperson/Code/MollyCoin/build/contracts
> Compiled successfully using:
- solc: 0.6.12+commit.27d51765.Emscripten.clang
UnhandledRejections detected
Promise {
<rejected> CodedError: Given input "NaN" is not a number.
at /home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:174:23
at process.promise (internal/process/task_queues.js:97:5)
at ProviderHandler.queueRequest (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:178:36)
at ProviderHandler.request (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/provider-handler.js:58:9)
at earliestBlock (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/helpers.js:149:5)
at previousClosestAncestor (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/helpers.js:77:19)
at PersistentCache.cache [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/persistent-cache.js:142:47)
at Fork.cache [as initCache] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/fork.js:209:21)
at Fork.fallback [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/fork.js:206:13)
at Blockchain.async [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/blockchain.js:629:22)
at EthereumProvider.async [as initialize] (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/provider.js:195:5)
at Connector.connect (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/connector.js:49:5) {
code: -32000
}
} CodedError: Given input "NaN" is not a number.
at /home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:174:23
at process.promise (internal/process/task_queues.js:97:5)
at ProviderHandler.queueRequest (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/base-handler.js:178:36)
at ProviderHandler.request (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/handlers/provider-handler.js:58:9)
at earliestBlock (/home/dogperson/.nvm/versions/node/v12.22.9/lib/node_modules/truffle/node_modules/ganache/dist/node/webpack:/Ganache/chains/ethereum/ethereum/lib/src/forking/persistent-cache/helpers.js
The contract deploys just fine if I run ganache-cli without --fork. Also if I connect Remix to my forked ganache-cli through Metamask, I am also able to deploy and interact with the contract just fine, which makes me believe that the issue might be with truffle.
Extra info:
Truffle version: 5.5.13
Truffle config file
I tried to do the same thing as you and encountered the same error.
After some research I believe the issue is that ganache is read-only when used to fork mainnet (or any testnet). You can't make any transactions. Only calls.
I was able to achieve the objective by using Hardhat instead of ganache.
First I installed hardhat and initialized the sample project:
https://hardhat.org/guides/project-setup.html
Then I ran hardhat with:
npx hardhat node --fork "https://mainnet.infura.io/v3/<ACCOUNT>"
Then I ran "truffle console" in a separate terminal window, with the following lines in truffle-config.js:
const HDWalletProvider = require('#truffle/hdwallet-provider');
const mnemonic = "test test test test test test test test test test test junk";
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
provider: () => new HDWalletProvider(mnemonic, "http://127.0.0.1:8545"),
}
}
}
The mnemonic I used is "test test test test test test test test test test test junk" because that is Hardhat's default mnemonic and I was not immediately able to figure out how to configure Hardhat with a different mnemonic.
Before running the truffle console, remember to install the hdwalletprovider npm package in your truffle directory: https://www.npmjs.com/package/#truffle/hdwallet-provider
At this point I have a running truffle console connected to local hardhat process which is connected to infura. I can make transactions to deploy and interact with contracts.
Hope this helps, and good luck.

yarn deploy give error with Command failed with exit code 1 when running collection-examples-as

I am trying to run the collection-examples-as near example but when I run yarn deploy it gives me the following error
$ near dev-deploy --wasmFile="./contract.wasm"
Starting deployment. Account id: dev-1637744501224-6323200, node:
https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file:
./contract.wasm
An error occurred
Error: ENOENT: no such file or directory, open './contract.wasm'
[Error: ENOENT: no such file or directory, open './contract.wasm'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: './contract.wasm'
}
error Command failed with exit code 1.
I think the error is it can't find the path to ./contract.wasm so I run yarn build the I tried to deploy it again using yarn deploy but I got another error which is:
$ near dev-deploy --wasmFile="./contract.wasm"
Starting deployment. Account id: dev-1637744501224-6323200, node:
https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file:
./contract.wasm
An error occurred
Error: Can not sign transactions for account dev-1637744501224-6323200 on network
default, no matching key pair found in
InMemorySigner(MergeKeyStore(UnencryptedFileSystemKeyStore(/home/rasha/.near-
credentials), UnencryptedFileSystemKeyStore(/home/rasha/collection-examples-
as/neardev))).
{
type: 'KeyNotFound',
context: undefined
}
any help or suggestions?
There's an issue with old versions of near-cli and dev-deploy.
As a workaround, you can try running the latest cli directly from your terminal:
near dev-deploy --wasmFile="./contract.wasm" -f
Just check that you installed the latest version of near-cli, currently 2.2.0. You can check your version with near --version.
Be sure to run yarn build first, so you'll have the compiled contract.wasm file.
Note: When you run yarn deploy, it uses the old near-cli version defined in package.json. (probably some old version like 1.6.0)
You might also want to check this GitHub issue (dev-deploy error): https://github.com/near/create-near-app/issues/1408

Specified query type "Query" not found in document when deploying to heroku

I am trying to deploy a typescript-graphql-postgres server onto heroku. The build was successful, however, when run I get the following from heroku logs:
UnhandledPromiseRejectionWarning: Error: Specified query type "Query"
not found in document. 2018-11-08T08:54:52.660051+00:00 app[web.1]: at
/app/node_modules/graphql/utilities/buildASTSchema.js:184:15
Anyone encountered and know the fix?
btw, when I run on my computer, the code works
Resolved. I need to copy graphql files into the relevant modules folders
below is what I added to my package.json for those who run into the same issue
"build": "rimraf dist && tsc && copyfiles -u 1 src/**/*.graphql dist",

Resources