Skip to content

Commit 469d6f7

Browse files
committed
1832 Add Liquibase-only Docker command for running database migrations without full server boot
1 parent 1c9d0b1 commit 469d6f7

File tree

4 files changed

+130
-8
lines changed

4 files changed

+130
-8
lines changed

server/apps/server-app/Dockerfile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@ RUN mkdir ${ARG_APPLICATION_HOME}/tls/trusted
1515
WORKDIR /opt/bytechef
1616

1717
COPY build/libs/server-app*.jar server/server-app.jar
18+
COPY docker-entrypoint.sh docker-entrypoint.sh
19+
RUN chmod +x docker-entrypoint.sh
1820

19-
ENTRYPOINT exec \
20-
java \
21-
-Dfile.encoding=UTF-8 -Duser.timezone=GMT \
22-
-Djava.io.tmpdir=/opt/bytechef/server/tmp \
23-
-Dserver.tomcat.basedir=/opt/bytechef/server \
24-
-Dserver.tomcat.accesslog.directory=/opt/bytechef/server/logs \
25-
-Dloader.path=/opt/bytechef/external_jars \
26-
-jar server/server-app.jar
21+
ENTRYPOINT ["./docker-entrypoint.sh"]
2722

2823
FROM bytechef-server-base AS bytechef-server
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
3+
JAVA_BASE_OPTS="-Dfile.encoding=UTF-8 -Duser.timezone=GMT \
4+
-Djava.io.tmpdir=/opt/bytechef/server/tmp \
5+
-Dloader.path=/opt/bytechef/external_jars"
6+
7+
JAVA_SERVER_OPTS="-Dserver.tomcat.basedir=/opt/bytechef/server \
8+
-Dserver.tomcat.accesslog.directory=/opt/bytechef/server/logs"
9+
10+
SPRING_PROFILES="${SPRING_PROFILES_ACTIVE:-}"
11+
12+
case "$1" in
13+
liquibase)
14+
shift
15+
16+
if [ -n "$SPRING_PROFILES" ]; then
17+
LIQUIBASE_PROFILES="liquibase,${SPRING_PROFILES}"
18+
else
19+
LIQUIBASE_PROFILES="liquibase"
20+
fi
21+
22+
echo "Running Liquibase database migration..."
23+
24+
exec java \
25+
$JAVA_BASE_OPTS \
26+
-jar server/server-app.jar \
27+
--spring.profiles.active="${LIQUIBASE_PROFILES}" \
28+
"$@"
29+
;;
30+
*)
31+
exec java \
32+
$JAVA_BASE_OPTS \
33+
$JAVA_SERVER_OPTS \
34+
-jar server/server-app.jar \
35+
"$@"
36+
;;
37+
esac
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.server;
18+
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
import org.springframework.boot.CommandLineRunner;
22+
import org.springframework.boot.SpringApplication;
23+
import org.springframework.context.ApplicationContext;
24+
import org.springframework.context.annotation.Profile;
25+
import org.springframework.stereotype.Component;
26+
27+
/**
28+
* Shuts down the application after Liquibase migrations complete. Active only with the {@code liquibase} profile so the
29+
* server starts normally in all other profiles.
30+
*
31+
* <p>
32+
* Since {@link liquibase.integration.spring.SpringLiquibase} runs during context initialization, by the time this
33+
* runner executes all migrations have already been applied.
34+
*
35+
* @author Ivica Cardic
36+
*/
37+
@Component
38+
@Profile("liquibase")
39+
class LiquibaseMigrationRunner implements CommandLineRunner {
40+
41+
private static final Logger logger = LoggerFactory.getLogger(LiquibaseMigrationRunner.class);
42+
43+
private final ApplicationContext applicationContext;
44+
45+
LiquibaseMigrationRunner(ApplicationContext applicationContext) {
46+
this.applicationContext = applicationContext;
47+
}
48+
49+
@Override
50+
public void run(String... args) {
51+
logger.info("Liquibase migration completed successfully");
52+
53+
SpringApplication.exit(applicationContext, () -> 0);
54+
}
55+
56+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
logging:
2+
level:
3+
ROOT: WARN
4+
liquibase: INFO
5+
com.bytechef.liquibase: INFO
6+
7+
spring:
8+
autoconfigure:
9+
exclude:
10+
org.springframework.boot.data.redis.autoconfigure.DataRedisAutoConfiguration,
11+
org.springframework.boot.neo4j.autoconfigure.Neo4jAutoConfiguration,
12+
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,
13+
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,
14+
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,
15+
org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration,
16+
org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,
17+
org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,
18+
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,
19+
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,
20+
org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,
21+
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,
22+
org.springframework.ai.autoconfigure.chat.client.ChatClientAutoConfiguration,
23+
org.springframework.ai.model.anthropic.autoconfigure.AnthropicAutoConfiguration,
24+
org.springframework.ai.model.openai.autoconfigure.OpenAiAudioSpeechAutoConfiguration,
25+
org.springframework.ai.model.openai.autoconfigure.OpenAiAudioTranscriptionAutoConfiguration,
26+
org.springframework.ai.model.openai.autoconfigure.OpenAiChatAutoConfiguration,
27+
org.springframework.ai.model.openai.autoconfigure.OpenAiEmbeddingAutoConfiguration,
28+
org.springframework.ai.model.openai.autoconfigure.OpenAiImageAutoConfiguration,
29+
org.springframework.ai.model.openai.autoconfigure.OpenAiModerationAutoConfiguration,
30+
org.springframework.ai.vectorstore.pgvector.autoconfigure.PgVectorStoreAutoConfiguration
31+
main:
32+
web-application-type: none
33+
quartz:
34+
auto-startup: false

0 commit comments

Comments
 (0)