OWASP/crAPI

ERROR: for crapi-web Container "8054b214c1ec" is unhealthy.

mhmd-git opened this issue · 10 comments

I'm pulling the latest docker images in Kali-Linux then running:
docker-compose -f docker-compose.yml --compatibility up -d
I receive the following response:

ERROR: for crapi-web  Container "8054b214c1ec" is unhealthy.
ERROR: Encountered errors while bringing up the project.

Logs:

 sudo docker logs 8054b214c1ec
Creating test database for alias 'default'...
Creating test database for alias 'mongodb'...
root         ERROR    /workshop/api/mechanic/signup - {'name': 'MechRaju', 'email': 'mechraju@crapi.com', 'mechanic_code': 'TRAC_MEC_3', 'number': '9123456708'} - 400 -{'password': [ErrorDetail(string='This field is required.', code='required')]}
django.request WARNING  Bad Request: /workshop/api/mechanic/signup
.django.request WARNING  Bad Request: /workshop/api/mechanic/signup
.django.request WARNING  Bad Request: /workshop/api/mechanic/signup
.django.request WARNING  Unauthorized: /workshop/api/mechanic/
django.request WARNING  Unauthorized: /workshop/api/mechanic/
.django.request WARNING  Unauthorized: /workshop/api/mechanic/
..root         ERROR    /workshop/api/merchant/contact_mechanic - {'mechanic_api': 'https://www.google.com', 'number_of_repeats': 5, 'mechanic_code': 'TRAC_MEC_3', 'vin': '9NFXO86WBWA082766', 'problem_details': 'My Car is not working'} - 400 -{'repeat_request_if_failed': [ErrorDetail(string='This field is required.', code='required')]}
django.request WARNING  Bad Request: /workshop/api/merchant/contact_mechanic
.root         INFO     Repeat count: 0
root         INFO     Got a valid response at repeat count: 0
.django.request ERROR    Service Unavailable: /workshop/api/merchant/contact_mechanic
..root         INFO     Repeat count: 0
root         INFO     Repeat count: 1
root         INFO     Repeat count: 2
root         INFO     Repeat count: 3
root         INFO     Repeat count: 4
root         INFO     Repeat count: 5
django.request WARNING  Not Found: /workshop/api/merchant/contact_mechanic
.django.request WARNING  Bad Request: /workshop/api/shop/apply_coupon
ProductTest  INFO     {'message': 'TRAC100 Coupon code is already claimed by you!! Please try with another coupon code'}
.root         ERROR    /workshop/api/shop/apply_coupon - {'coupon_code': 'TRAC105', 'amount': 75} - 400 -Coupon matching query does not exist.
django.request WARNING  Bad Request: /workshop/api/shop/apply_coupon
ProductTest  INFO     {'message': 'Coupon not found'}
.django.request WARNING  Bad Request: /workshop/api/shop/apply_coupon
ProductTest  INFO     {'message': '9123456708 Coupon code is already claimed by you!! Please try with another coupon code'}
.ProductTest  INFO     {'credit': 175.0, 'message': 'Coupon successfully applied!'}
.
----------------------------------------------------------------------
Ran 15 tests in 141.909s

OK
Destroying test database for alias 'default'...
Destroying test database for alias 'mongodb'...
This version of djongo does not support "NULL, NOT NULL column validation check" fully. Visit https://www.patreon.com/nesdis
This version of djongo does not support "schema validation using CONSTRAINT" fully. Visit https://www.patreon.com/nesdis
This version of djongo does not support "schema validation using KEY" fully. Visit https://www.patreon.com/nesdis
This version of djongo does not support "schema validation using REFERENCES" fully. Visit https://www.patreon.com/nesdis
This version of djongo does not support "COLUMN DROP NOT NULL " fully. Visit https://www.patreon.com/nesdis
This version of djongo does not support "DROP CASCADE" fully. Visit https://www.patreon.com/nesdis
System check identified no issues (0 silenced).
Operations to perform:
  Apply all migrations: user
Running migrations:
  Applying user.0001_initial... FAKED
Operations to perform:
  Apply all migrations: crapi
Running migrations:
  Applying crapi.0001_initial... OK
Operations to perform:
  Apply all migrations: db
Running migrations:
  Applying db.0001_initial... OK
django.utils.autoreload INFO     Watching for file changes with StatReloader

any update on this, encountered this today as well

No updates yet

Can you try
VERSION=develop docker-compose -f docker-compose.yml pull
and then
VERSION=develop docker-compose -f docker-compose.yml --compatibility up -d
Locally present images might be outdated.

this one produced crapi-workshop unhealthy

┌──(root㉿kali)-[~/API_Lab/crapi]
└─# VERSION=develop docker-compose -f docker-compose.yml pull
Pulling postgresdb ... done
Pulling mongodb ... done
Pulling crapi-identity ... done
Pulling crapi-community ... done
Pulling crapi-workshop ... done
Pulling crapi-web ... done
Pulling mailhog ... done

┌──(root㉿kali)-[~/API_Lab/crapi]
└─# VERSION=develop docker-compose -f docker-compose.yml --compatibility up -d
Recreating postgresdb ... done
Recreating mailhog ... done
Starting mongodb ... done
Recreating crapi-identity ... done
Creating crapi-community ... done

ERROR: for crapi-workshop Container "a06e1aacd28e" is unhealthy.
ERROR: Encountered errors while bringing up the project.

docker logs a06e1aacd28e
Loading default JWKS file.
Picked up JAVA_TOOL_OPTIONS: -Xmx128m

. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' |
| .__|| ||| |_, | / / / /
=========|
|==============|/=////
:: Spring Boot :: (v2.6.1)

2023-01-11 14:59:32.970 INFO 8 --- [ main] com.crapi.CRAPIBootApplication : Starting CRAPIBootApplication using Java 11.0.15 on a06e1aacd28e with PID 8 (/app/identity-service-1.0-SNAPSHOT.jar started by root in /)
2023-01-11 14:59:32.976 INFO 8 --- [ main] com.crapi.CRAPIBootApplication : No active profile set, falling back to default profiles: default
2023-01-11 14:59:37.274 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-01-11 14:59:37.575 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 291 ms. Found 8 JPA repository interfaces.
2023-01-11 14:59:40.695 INFO 8 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-01-11 14:59:40.777 INFO 8 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-01-11 14:59:40.778 INFO 8 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.55]
2023-01-11 14:59:40.967 INFO 8 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-01-11 14:59:40.967 INFO 8 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 7600 ms
2023-01-11 14:59:41.170 WARN 8 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-01-11 14:59:41.683 INFO 8 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-01-11 14:59:42.073 INFO 8 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.1.Final
2023-01-11 14:59:43.083 INFO 8 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2023-01-11 14:59:43.488 INFO 8 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-01-11 14:59:45.282 ERROR 8 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.

org.postgresql.util.PSQLException: FATAL: database "crapi" does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2676) ~[postgresql-42.4.0.jar!/:42.4.0]
at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2788) ~[postgresql-42.4.0.jar!/:42.4.0]
at org.postgresql.core.v3.QueryExecutorImpl.(QueryExecutorImpl.java:174) ~[postgresql-42.4.0.jar!/:42.4.0]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:290) ~[postgresql-42.4.0.jar!/:42.4.0]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.4.0.jar!/:42.4.0]
at org.postgresql.jdbc.PgConnection.(PgConnection.java:223) ~[postgresql-42.4.0.jar!/:42.4.0]
at org.postgresql.Driver.makeConnection(Driver.java:402) ~[postgresql-42.4.0.jar!/:42.4.0]
at org.postgresql.Driver.connect(Driver.java:261) ~[postgresql-42.4.0.jar!/:42.4.0]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.6.1.Final.jar!/:5.6.1.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) ~[hibernate-core-5.6.1.Final.jar!/:5.6.1.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.6.1.Final.jar!/:5.6.1.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.6.1.Final.jar!/:5.6.1.Final]
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.6.1.Final.jar!/:5.6.1.Final]
[snip]

Could you attach the logs of all containers, this will help us debug the issue. Also do upload the logs as a file.

Hopefully this helps

crapi_logs.txt

The error says that there is some issue connecting with the database, most probably postgres container did not come up because of old docker-comopse files.

  1. Can you completely remove all crapi related container instances including postgresql and mongodb using docker container rm command
  2. Remove crapi related docker volumes using docker volume rm command, probably will be named like this, use docker volume ls to find them
docker_mongodb-data
docker_postgresql-data
  1. Download the latest version of docker-compose.yml - since there were some changes to that recently

And then try running it once more?

We have success...I had to stop all docker containers and I removed them all from my system, then I also stopped all docker volumes and removed them as well. Redownloaded CRAPI, and no errors.

docker container stop mongodb
docker container rm mongodb

docker volume ls
DRIVER VOLUME NAME
local 9ae75f973c5868ca7e0b86eae352e3a53e449bdf2101d3881eeaf412ed91b8cd
local a0a748cb16e9572a46d2bbbbf47fe1271715cff539ca314aaa02e4c95c753640
local crapi_mongodb-data
local crapi_postgresql-data

docker volume rm crapi_mongodb-data

docker ps -aq
f349b59bca37
a06e1aacd28e
affdbaf1f293
93ac1ffa2788

docker rm f349b59bca37
docker rm a06e1aacd28e
docker stop affdbaf1f293
docker rm affdbaf1f293
docker stop 93ac1ffa2788
docker rm 93ac1ffa2788

docker volume ls
DRIVER VOLUME NAME
local 9ae75f973c5868ca7e0b86eae352e3a53e449bdf2101d3881eeaf412ed91b8cd
local a0a748cb16e9572a46d2bbbbf47fe1271715cff539ca314aaa02e4c95c753640
local crapi_postgresql-data

docker volume rm crapi_postgresql-data
docker volume rm 9ae75f973c5868ca7e0b86eae352e3a53e449bdf2101d3881eeaf412ed91b8cd
docker volume rm a0a748cb16e9572a46d2bbbbf47fe1271715cff539ca314aaa02e4c95c753640

curl -o docker-compose.yml https://raw.githubusercontent.com/OWASP/crAPI/develop/deploy/docker/docker-compose.yml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6209 100 6209 0 0 1125 0 0:00:05 0:00:05 --:--:-- 1511

┌──(root㉿kali)-[~/API_Lab]
└─# VERSION=develop docker-compose pull

Pulling postgresdb ... done
Pulling mongodb ... done
Pulling crapi-identity ... done
Pulling crapi-community ... done
Pulling crapi-workshop ... done
Pulling crapi-web ... done
Pulling mailhog ... done

┌──(root㉿kali)-[~/API_Lab]
└─# VERSION=develop docker-compose -f docker-compose.yml --compatibility up -d
Creating network "api_lab_default" with the default driver
Creating volume "api_lab_mongodb-data" with default driver
Creating volume "api_lab_postgresql-data" with default driver
Creating mailhog ... done
Creating mongodb ... done
Creating postgresdb ... done
Creating crapi-identity ... done
Creating crapi-community ... done
Creating crapi-workshop ... done
Creating crapi-web ... done

that was not helpful
vagrant documentation is totally inaccurate

Hey, I had the same issue: where crapi-web had an error, though managed to use the "restart" command

──(kali㉿kali)-[~/Labs/crAPI]
└─$ sudo docker-compose start
Starting postgresdb ... done
Starting mongodb ... done
Starting crapi-identity ... done
Starting crapi-community ... done
Starting crapi-workshop ... done
Starting crapi-web ... error
Starting mailhog ... done
Starting api.crapi.io ... done

ERROR: for crapi-web Container "74f550385d99" is unhealthy.

┌──(kali㉿kali)-[~/Labs/crAPI]
└─$ sudo docker-compose ps
Name Command State Ports

api.crapi.io /app/server Up (unhealthy) 443/tcp
crapi-community /bin/sh -c /app/main Up (healthy)
crapi-identity /entrypoint.sh Up (healthy)
crapi-web /bin/sh -c /etc/nginx/ngin ... Exit 255 127.0.0.1:8888->80/tcp
crapi-workshop /bin/sh -c /app/runner.sh Exit 0
mailhog MailHog Up (healthy) 1025/tcp, 127.0.0.1:8025->8025/tcp
mongodb docker-entrypoint.sh mongod Up (healthy) 27017/tcp
postgresdb docker-entrypoint.sh postgres Up (healthy) 5432/tcp

┌──(kali㉿kali)-[~/Labs/crAPI]
└─$

┌──(kali㉿kali)-[~/Labs/crAPI]
└─$ sudo docker-compose restart
Restarting crapi-web ... done
Restarting crapi-workshop ... done
Restarting crapi-community ... done
Restarting crapi-identity ... done
Restarting mailhog ... done
Restarting mongodb ... done
Restarting postgresdb ... done
Restarting api.crapi.io ... done