According to Docker official website , Docker doesn't support SQL image for M1 processors ; however , it supports installing it by passing " --platform linux/x86_64 mysql" .
Actually , SQL docker is pulled successfully using this command
docker pull --platform linux/x86_64 mysql
the output :
Using default tag: latest
latest: Pulling from library/mysql
a330b6cecb98: Pull complete
9c8f656c32b8: Pull complete
88e473c3f553: Pull complete
062463ea5d2f: Pull complete
daf7e3bdf4b6: Pull complete
1839c0b7aac9: Pull complete
cf0a0cfee6d0: Pull complete
1b42041bb11e: Pull complete
10459d86c7e6: Pull complete
b7199599d5f9: Pull complete
1d6f51e17d45: Pull complete
50e0789bacad: Pull complete
Digest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:late
Now , I want to use SQL container in my integration test , but docker fails to pull SQL.
The code used to initialize SQL test container
#DynamicPropertySource
static void dynamicPropertySource(DynamicPropertyRegistry dynamicPropertyRegistry) {
MySQLContainer<?> container = new MySQLContainer<>("mysql:8.0.26")
.withDatabaseName("sympl")
.withUsername("test")
.withPassword("test")
.withCommand("docker pull --platform linux/x86_64 mysql");
dynamicPropertyRegistry.add("spring.datasource.url", () -> container.getJdbcUrl());
dynamicPropertyRegistry.add("spring.datasource.username", () -> container.getUsername());
dynamicPropertyRegistry.add("spring.datasource.password", () -> container.getPassword());
container.start();
}
I tried to write the code withCommand() and without .withCommand.
After I run the test cases , it gives fails with the following logs :
17:18:25.003 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.003 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.005 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.005 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.015 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext#3faf2e7d testClass = CustomerApiIntegrationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration#4648ce9 testClass = CustomerApiIntegrationTests, locations = '{}', classes = '{class com.sympl.customer.CustomersApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer#78fa769e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer#2c78324b, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer#3fd11d55, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer#6ca18a14, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer#1ec9bd38, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer#0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer#cd1e646, org.springframework.test.context.support.DynamicPropertiesContextCustomizer#aa1b54d2, org.springframework.boot.test.context.SpringBootTestArgs#1, org.springframework.boot.test.context.SpringBootTestWebEnvironment#5890e879], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> false]], class annotated with #DirtiesContext [false] with mode [null].
17:18:25.021 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.021 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.088 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profiles [test]
17:18:25.094 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.3)
2021-09-19 17:18:26.039 INFO 9715 --- [ main] o.t.d.DockerClientProviderStrategy : Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
2021-09-19 17:18:27.294 INFO 9715 --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
2021-09-19 17:18:27.299 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is localhost
2021-09-19 17:18:27.365 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
Server Version: 20.10.8
API Version: 1.41
Operating System: Docker Desktop
Total Memory: 1988 MB
2021-09-19 17:18:27.369 INFO 9715 --- [ main] o.t.utility.ImageNameSubstitutor : Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2021-09-19 17:18:27.547 INFO 9715 --- [ main] o.t.utility.RegistryAuthLocator : Credential helper/store (docker-credential-desktop) does not have credentials for index.docker.io
2021-09-19 17:18:28.202 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
2021-09-19 17:18:28.203 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Checking the system...
2021-09-19 17:18:28.203 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker server version should be at least 1.6.0
2021-09-19 17:18:28.322 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker environment should have more than 2GB free disk space
2021-09-19 17:18:28.388 INFO 9715 --- [ main] 🐳 [mysql:8.0.26] : Pulling docker image: mysql:8.0.26. Please be patient; this may take some time but only needs to be done once.
2021-09-19 17:18:32.326 INFO 9715 --- [stream--1235448] 🐳 [mysql:8.0.26] : Starting to pull image
2021-09-19 17:18:32.369 INFO 9715 --- [stream--1235448] 🐳 [mysql:8.0.26] : Pulling image layers: 0 pending, 0 downloaded, 0 extracted, (0 bytes/0 bytes)
2021-09-19 17:18:32.422 ERROR 9715 --- [ main] o.s.boot.SpringApplication : Application run failed
org.testcontainers.containers.ContainerLaunchException: Container startup failed
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:330) ~[testcontainers-1.15.3.jar:na]
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311) ~[testcontainers-1.15.3.jar:na]
at com.sympl.customer.api.CustomerApiIntegrationTests.dynamicPropertySource(CustomerApiIntegrationTests.java:79) ~[test-classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
Here is the docker logs
I am sure there is a workaround for this , but I couldn't find it till now .
I'm the current PM for Azure SQL Edge at Microsoft dropping by with an update to share. Docker Desktop v4.16 introduced beta support for the Virtualization framework, meaning you can now run x86/amd64 based SQL Server containers on M1/M2 silicon with macOS 13. This will be our recommended path for running SQL server containers on ARM based macOS going forward as it will enable you to develop against SQL Server 2017-2022 in addition to Azure SQL Edge. For a walkthrough on how to enable the feature and run a SQL Server 2022 container on macOS, check out https://devblogs.microsoft.com/azure-sql/development-with-sql-in-containers-on-macos/
Related
I have 16 Unit test case files. Each in this format:
#SpringBootTest
class UserServiceTest {
#Autowired
UserService userService;
#MockBean
SomeDependency someDependency;
#Test
...and so on
}
Whenever I run mvn clean install, it seems that spring is restarting/loading context 16 times. I see these logs 16 times:
[INFO] Running com.base.UserServiceTest
2021-07-16 04:35:39.421 [INFO ] [main] o.s.t.c.s.AbstractTestContextBootstrapper - Neither #ContextConfiguration nor #ContextHierarchy found for test class [com.base.UserServiceTest], using SpringBootContextLoader
2021-07-16 04:35:39.423 [INFO ] [main] o.s.t.c.s.AbstractContextLoader - Could not detect default resource locations for test class [com.base.UserServiceTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2021-07-16 04:35:39.424 [INFO ] [main] o.s.t.c.s.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.base.UserServiceTest]: UserServiceTest does not declare any static, non-private, non-final, nested classes annotated with #Configuration.
2021-07-16 04:35:39.473 [INFO ] [main] o.s.b.t.c.SpringBootTestContextBootstrapper - Found #SpringBootConfiguration com.base.Application for test class com.base.UserServiceTest
2021-07-16 04:35:39.475 [INFO ] [main] o.s.t.c.s.AbstractTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
2021-07-16 04:35:39.476 [INFO ] [main] o.s.t.c.s.AbstractTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener#4dc599a7, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener#635f2d9b, org.springframework.test.context.event.ApplicationEventsTestExecutionListener#7e83380f, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener#6000fc20, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener#1e95926, org.springframework.test.context.support.DirtiesContextTestExecutionListener#1bc08f75, org.springframework.test.context.transaction.TransactionalTestExecutionListener#7ce49f42, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener#1b629d02, org.springframework.test.context.event.EventPublishingTestExecutionListener#5089c721, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener#4fad5162, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener#176bd95a, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener#186edc38, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener#6c0b0db, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener#2343c720, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener#6aab6b1b]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.0)
2021-07-16 04:35:39.520 [INFO ] [main] o.s.b.StartupInfoLogger - Starting UserServiceTest using Java 11.0.2 on
2021-07-16 04:35:39.523 [INFO ] [main] o.s.b.SpringApplication - The following profiles are active: local
2021-07-16 04:35:40.197 [INFO ] [main] o.s.m.w.MockServletContext - Initializing Spring TestDispatcherServlet ''
2021-07-16 04:35:40.197 [INFO ] [main] o.s.w.s.FrameworkServlet - Initializing Servlet ''
2021-07-16 04:35:40.199 [INFO ] [main] o.s.w.s.FrameworkServlet - Completed initialization in 1 ms
2021-07-16 04:35:40.211 [INFO ] [main] o.s.b.StartupInfoLogger - Started UserServiceTest in 0.732 seconds (JVM running for 9.613)
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.918 s - in com.base.UserServiceTest
This causes 2 problems:
There are a lot more tests to be added. Even with 16 test files, it takes around 20 seconds to execute. So the process is slow.
My application uses JPA to connect with DB, and during mvn clean install, although the application builds successfully, it gives this error in logs random number of times:
2021-07-16 04:35:52.741 [ERROR] [main] c.z.h.p.HikariPool - HikariPool-11 - Exception during pool initialization. org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections
I wonder if this context reloading is causing this as I perform mvn clean install often and that there might be a connection leak somewhere.
Using JUnit 5/Jupiter and Spring 5.
Any help in fixing above 2 points is appreciated. Thanks.
Spring Test caches your TestContext and re-uses it for another test if the context configuration fits.
However, if all your tests have a different setup (e.g., the first test wants a mocked version of class A and the second test wants a mocked version of class B), caching won't help and Spring has to start a new context.
If you streamline the context setup for all your tests, Spring will reuse it and hence make the test execution fast.
In addition, the test you added (using #SpringBootTest) is not a unit test (well - it always depends on the definition) as it starts the entire Spring context.
If your plan is to write unit tests for your business logic, rather use just JUnit 5 and Mockito. These tests are fast and there's no Spring support and hence no context started.
For a broad overview of unit, integration, and end-to-end testing strategies for Spring Boot applications, take a look at this article.
I'm having trouble deploying my Spring Boot application on the Google Cloud Platform Flexible environment.
I run the following command to deploy: mvn clean compile package -DskipTests appengine:deploy -P cloud-gcp
The cloud-gcp profile in my pom.xml has the following:
<profiles>
<profile>
<id>cloud-gcp</id>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<version>beta3</version>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This is my app.yaml file located at src/main/appengine/app.yaml:
runtime: java
env: flex
runtime_config:
jdk: openjdk8
env_variables:
SPRING_PROFILES_ACTIVE: "gcp"
handlers:
- url: /.*
script: this field is required, but ignored
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 4
disk_size_gb: 10
Here is my application-gcp.properties:
server.address=0.0.0.0
server.port=8080
# Datasource
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.url=jdbc:postgresql://google/xxx?cloudSqlInstance=xxx:europe-west4:xxx&autoReconnect=true&user=xxx&password=xxx&socketFactory=com.google.cloud.sql.postgres.SocketFactory&useSSL=false
server.error.whitelabel.enabled=false
# Optimize start of application
spring.jmx.enabled=false
# Gcp configuration
spring.cloud.gcp.sql.enabled=false
spring.cloud.gcp.sql.database-name=xxx
spring.cloud.gcp.sql.instance-connection-name=xxx:europe-west4:xxx
spring.cloud.gcp.logging.enabled=true
The compilation is successful, no problems there. The problem occurs when I want to access my Spring Boot application. I constantly get a 502 Error. There is nothing in the logs that gives me a clue on what is wrong:
A 2020-01-20T16:14:17Z . ____ _ __ _ _
A 2020-01-20T16:14:17Z /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
A 2020-01-20T16:14:17Z ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
A 2020-01-20T16:14:17Z \\/ ___)| |_)| | | | | || (_| | ) ) ) )
A 2020-01-20T16:14:17Z ' |____| .__|_| |_|_| |_\__, | / / / /
A 2020-01-20T16:14:17Z =========|_|==============|___/=/_/_/_/
A 2020-01-20T16:14:17Z :: Spring Boot :: (v2.1.5.RELEASE)
com.xxx.api.xxxApplication : Starting xxxApplication v0.0.1-SNAPSHOT on bc233766746a with PID 1 (/app.jar started by root in /)
com.xxx.api.xxxApplication : The following profiles are active: gcp
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
.s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 532ms. Found 17 repository interfaces.
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$2c4dbf14] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$c4fb874e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#6b00f608' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$e9d02a00] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$abce0c46] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
o.apache.catalina.core.StandardService : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.19]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 11326 ms
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
Connecting to Cloud SQL instance [xxx:europe-west4:xxx] via SSL socket.
First Cloud SQL connection, generating RSA key pair.
This is the last lines I have in the logs. Nothing seems to break, no errors as far as I can tell. It seems to correctly connect to the Cloud SQL instance. I'm lost here. I've tried a lot of things, but I always get a 502 request from Spring Boot no matter what.
For information, the /liveness_check and /readiness_check always return 200 even when the server is not launched (which is strange...).
Tell me if you need any more informations on the configuration I am using.
Thank you in advance!
We finally solved our issue. For those who might have the same issue:
The problem was caused by our guava version. We add the version 18.0, which was problematic apparently. We added the following dependencies in the pom.xml:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
</dependency>
And the problem was solved :)
Wow, just doing some venting here but have been pulling my hair out for about 2 weeks now attempting to deploy a spring boot app to google cloud. It's incredibly nerve wracking to hear that a modification of a guava dependency could cause an application to not startup - even far worse make the logs go silent with no trace of what is going on. At the moment, I too am dealing with a situation where there are no application logs to be found and no trace of what is going wrong while just simply trying to hit an endpoint after what google cloud tells me is a successful deploy.
This comment and I'm sure to write others in the future is more aimed at getting other people to vent their frustration as google cloud support is non-existent unless you pay a premium for it. Making matters worse the product appears to be just plain terrible in terms of allowing developers insights into what is actually going wrong when a deployment doesn't work. I hope this gets their attention and I hope others voice their frustration as well because this product is simply unusable when it gives no indication of what is going wrong with a deployment. I've scoured their docs to no avail and it seems others have similar issues. Unfortunately my hands are tied by my client to use google cloud otherwise I would have migrated away from it after seeing first hand some of the very basic ways it is flawed. If you're in the process of evaluating a cloud product I would highly recommend not using google.
I'm setting up spring-boot applications inside docker with docker-compose and need to access a rest endpoint from one application on port 8080 from my localhost. The following endpoint works fine when started locally http://localhost:8080/central/products.
I'm on ubuntu 19.10 and running docker version 18.09.5. When I set up a simple spring-boot application for docker like explained on https://spring.io/guides/gs/spring-boot-docker/, everything works as expected and I can reach the endpoint on http://localhost:8080/. However, when I start more services with docker-compose I'm not able to reach this endpoint from my localhost.
Dockerfile for building the spring-boot application:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","sample.EfridgeCentralApplication"]
docker-compose.yml file that seems to cause the problem:
version: '3.7'
services:
central-london:
image: demo/efridge-central:latest
container_name: central-london
ports:
- 8080:8080
environment:
- SERVER_PORT=8080
- SPRING_PROFILES_ACTIVE=dev
- SPRING_DATA_MONGODB_HOST=mongo-central
- SPRING_DATA_MONGODB_PORT=27017
- APP_RABBIT_HOSTNAME=rabbit-efridge
factory-usa:
image: demo/efridge-factory:latest
container_name: factory-usa
ports:
- 8081:8081
environment:
- SERVER_PORT=8081
- SPRING_PROFILES_ACTIVE=usa
- SPRING_DATA_MONGODB_HOST=mongo-usa
- SPRING_DATA_MONGODB_PORT=27017
- APP_RABBIT_HOSTNAME=rabbit-efridge
factory-china:
image: demo/efridge-factory:latest
container_name: factory-china
ports:
- 8082:8082
environment:
- SERVER_PORT=8082
- SPRING_PROFILES_ACTIVE=china
- SPRING_DATA_MONGODB_HOST=mongo-china
- SPRING_DATA_MONGODB_PORT=27017
- APP_RABBIT_HOSTNAME=rabbit-efridge
mongo-central:
image: mongo:latest
container_name: mongo-central
hostname: mongo-central
ports:
- 27017:27017
mongo-usa:
image: mongo:latest
container_name: mongo-usa
hostname: mongo-usa
ports:
- 27018:27017
mongo-china:
image: mongo:latest
container_name: mongo-china
hostname: mongo-china
ports:
- 27019:27017
rabbit-efridge:
image: rabbitmq:3-management
container_name: rabbit-efridge
hostname: rabbit-efridge
ports:
- 15672:15672
- 5672:5672
Output from docker inspect:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "b91760f810a656e382d702dd408afe3c5ffcdf4c0cd15ea8550150867ac038cc",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
]
}
Logs from spring-boot
2019-07-03 11:54:57.654 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-07-03 11:54:57.803 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-07-03 11:54:57.804 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-07-03 11:54:58.149 INFO 1 --- [ main] o.a.c.c.C.[.[localhost].[/central] : Initializing Spring embedded WebApplicationContext
2019-07-03 11:54:58.150 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6950 ms
2019-07-03 11:54:59.810 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[mongo-central:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-07-03 11:54:59.810 INFO 1 --- [ main] org.mongodb.driver.cluster : Adding discovered server mongo-central:27017 to client view of cluster
2019-07-03 11:55:00.256 INFO 1 --- [o-central:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:11}] to mongo-central:27017
The output from docker inspect of the working spring-boot container and the not working looks almost the same. I can also access the rabbitmq web interface and MongoDB via mongo client. The only thing that does not work is access to the rest endpoint via http://localhost:8080/central/products.
your Dockerfile is lacking the EXPOSE statement, therefore no ports are exposed to the outer world.
once you add EXPOSE 8080 to the bottom of your Dockerfile, your app will be reachable from outside the container.
The problem is caused by the application.properties file, where I still had server.address=localhost specified.
Removing this line solved the problem!
I have an existing database. I created two migrations
$ ls src/main/resources/db/migration/
V1__create_stats.sql V2__create_sources.sql
I set the following in application.properties
# Prevent complaints when starting migrations with existing tables.
flyway.baselineOnMigrate = true
Otherwise it would give the error org.flywaydb.core.api.FlywayException: Found non-empty schemagalaxybadgewithout metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.
When I try to start the app, it skips the migrations and doesn't execute them! I use show tables; in MySQL and see they are not there!
>mvn spring-boot:run
...
2018-05-09 18:43:03.671 INFO 24520 --- [ restartedMain] o.f.core.internal.util.VersionPrinter : Flyway 3.2.1 by Boxfuse
2018-05-09 18:43:04.420 INFO 24520 --- [ restartedMain] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:mysql://localhost:3306/galaxybadge (MySQL 5.5)
2018-05-09 18:43:04.486 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbValidate : Validated 0 migrations (execution time 00:00.030s)
2018-05-09 18:43:04.704 INFO 24520 --- [ restartedMain] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: `galaxybadge`.`schema_version`
2018-05-09 18:43:05.116 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbBaseline : Schema baselined with version: 1
2018-05-09 18:43:05.145 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Current version of schema `galaxybadge`: 1
2018-05-09 18:43:05.146 INFO 24520 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Schema `galaxybadge` is up to date. No migration necessary.
I looked at this answer but it didn't help and seemed to give the wrong property name. Here is the schema_version table it created.
> select * from schema_version;
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| version_rank | installed_rank | version | description | type | script | checksum | installed_by | installed_on | execution_time | success |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
| 1 | 1 | 1 | << Flyway Baseline >> | BASELINE | << Flyway Baseline >> | NULL | root | 2018-05-09 18:43:05 | 0 | 1 |
+--------------+----------------+---------+-----------------------+----------+-----------------------+----------+--------------+---------------------+----------------+---------+
Spring Boot 1.5.6, FlyWay Core 3.2.1
Spring docs -
FlyWay docs
OK I found this https://flywaydb.org/documentation/existing
But didn't follow it. Instead, I moved my migrations from V1__* and V2__* to V2... and V3... and downloaded the production schema into V1__initialize.sql.
mysqldump -h project.us-east-1.rds.amazonaws.com -u username -p --no-data --skip-add-drop-table --compact --skip-set-charset databasename > V1__initialize.sql
Then when I ran Spring mvn spring-boot:run it ran the migrations.
(Well actually there was a lot of debugging of the SQL and I had to drop the tables several times and delete rows out of schema_verion and delete old file names from target/.../migration/ but that's another story.)
I believe it may be possible to set
flyway.baselineVersion=0
and skip the SQL dump (initialization) based on the info here: https://flywaydb.org/documentation/configfiles. However, having the schema available for future devs seems like the right approach.
I still don't understand why it didn't run V2__... migration from the original question. If it starts at 1, then migration 2 is still available to run. Had it worked as expected, then I might have understood the problem sooner.
With a Spring boot application that already have an existing database, configure this in your
application.yml:
flyway:
baseline-on-migrate: true
baseline-version: 0
And start your migration scripts at 1, like this : V1__script_description.sql, V2__script_description.sql, ...
i have a strange problem. I have created a spring application with some functional logic and started it locally - it worked.
Then i have exported my whole project to a .war file and build a docker image to run it also locally - it worked.
Since ca. 2 day...i guess i did some changes...i want to build and run my docker file again, but stops always at this point:
Launching defaultServer (WebSphere Application Server 17.0.0.2/wlp-1.0.17.cl170220170523-1818) on IBM J9 VM, version pxa6480sr4fp10-20170727_01 (SR4 FP10) (en_US)
[AUDIT ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT ] CWWKE0100I: This product is licensed for development, and limited production use. The full license terms can be viewed here: https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/base_ilan/ilan/17.0.0.2/lafiles/en.html
[AUDIT ] CWWKG0093A: Processing configuration drop-ins resource: /opt/ibm/wlp/usr/servers/defaultServer/configDropins/defaults/keystore.xml
[WARNING ] CWWKS3103W: There are no users defined for the BasicRegistry configuration of ID com.ibm.ws.security.registry.basic.config[basic].
[AUDIT ] CWWKZ0058I: Monitoring dropins for applications.
[AUDIT ] CWWKS4104A: LTPA keys created in 6.228 seconds. LTPA key file: /opt/ibm/wlp/output/defaultServer/resources/security/ltpa.keys
[AUDIT ] CWPKI0803A: SSL certificate created in 8.761 seconds. SSL key file: /opt/ibm/wlp/output/defaultServer/resources/security/key.jks
[AUDIT ] CWWKI0001I: The CORBA name server is now available at corbaloc:iiop:localhost:2809/NameService.
[AUDIT ] CWWKT0016I: Web application available (default_host): http://2b88d6a3093b:9080/xxxxxx/
[AUDIT ] CWWKZ0001I: Application xxxxx started in 1.828 seconds.
[AUDIT ] CWWKF0012I: The server installed the following features: [servlet-3.1, beanValidation-1.1, ssl-1.0, jndi-1.0, jca-1.7, ejbPersistentTimer-3.2, appSecurity-2.0, j2eeManagement-1.1, jdbc-4.1, wasJmsServer-1.0, jaxrs-2.0, javaMail-1.5, cdi-1.2, webProfile-7.0, jcaInboundSecurity-1.0, jpa-2.1, jsp-2.3, ejbLite-3.2, managedBeans-1.0, jsf-2.2, ejbHome-3.2, jaxws-2.2, jsonp-1.0, el-3.0, jaxrsClient-2.0, concurrent-1.0, appClientSupport-1.0, ejbRemote-3.2, javaee-7.0, jaxb-2.2, mdb-3.2, jacc-1.5, batch-1.0, ejb-3.2, json-1.0, jaspic-1.1, jpaContainer-2.1, distributedMap-1.0, websocket-1.1, wasJmsSecurity-1.0, wasJmsClient-2.0].
[AUDIT ]
CWWKF0011I: The server defaultServer is ready to run a smarter planet.
My Spring application doesn't start anymore. In general it would continue with this:
2017-10-05 13:34:46.723 INFO 11136 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#c3c60d: startup date [Thu Oct 05 13:34:46 CEST 2017]; root of context hierarchy
2017-10-05 13:34:47.070 INFO 11136 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-10-05 13:34:47.112 INFO 11136 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$240b40b3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.2.RELEASE)
........
If i start my application locally from eclipse, it still works without any problems, but of course i want to build the docker image again.
Where do i have to search, if the SpringApplication start locally from the environment, but not from the docker images/container. Here it stops at
"The server defaultServer is ready to run a smarter planet."
Thank you in adnvance!
----------------- UPDATE -----------------
I found something. My exported .war file has just a size of 134kb. I am sure, it was ca. 35mb before. Does anyone has an idea?