Skip to content

Commit

Permalink
Fix database calls during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Jul 4, 2024
1 parent 19b0d38 commit 598fbe0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ FROM eclipse-temurin:21-jdk-alpine as builder
WORKDIR /application
ARG JAR_FILE=build/libs/faf-java-api-*.jar
COPY ${JAR_FILE} application.jar
COPY test-pki-private.key pki/secret.key
COPY test-pki-public.key pki/public.key
COPY test-pki-private.key /pki/secret.key
COPY test-pki-public.key /pki/public.key
COPY test-account-activation.html /config/mail/account-activation.html
COPY test-password-reset.html /config/mail/password-reset.html
COPY test-welcome-to-faf.html /config/mail/welcome-to-faf.html
ENV FAF_DOMAIN=faforever.com
RUN java -Djarmode=tools -jar application.jar extract
RUN java -Dspring.context.exit=onRefresh -XX:ArchiveClassesAtExit=application.jsa -jar application/application.jar
RUN java -Dspring.context.exit=onRefresh -Dspring.profiles.active=training -XX:ArchiveClassesAtExit=application.jsa -jar application/application.jar

FROM eclipse-temurin:21-jdk-alpine
VOLUME /tmp
Expand All @@ -15,6 +18,6 @@ COPY --from=builder /application/application/lib ./
RUN true
COPY --from=builder /application/application/application.jar ./
RUN true
COPY --from=builder /application/application/application.jsa ./
COPY --from=builder /application/application.jsa ./
RUN true
ENTRYPOINT ["java", "-XX:SharedArchiveFile=application.jsa", "-Djava.security.egd=file:/dev/./urandom", "-jar", "application.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public final class ApplicationProfile {
public static final String PRODUCTION = "prod";
public static final String DEVELOPMENT = "dev";
public static final String INTEGRATION_TEST = "int";
public static final String TRAINING = "training";

private ApplicationProfile() {
// Utility class
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/faforever/api/config/CacheConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.faforever.api.data.domain.MapVersion;
import com.faforever.api.data.domain.Mod;
import com.faforever.api.data.domain.ModVersion;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCache;
Expand All @@ -28,7 +29,6 @@
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.HandlerMapping;

import jakarta.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -40,7 +40,7 @@

@EnableCaching(proxyTargetClass = true)
@Configuration
@Profile(ApplicationProfile.PRODUCTION)
@Profile({ApplicationProfile.PRODUCTION, ApplicationProfile.TRAINING})
public class CacheConfig {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Objects;

@Component
@Profile("!" + ApplicationProfile.INTEGRATION_TEST)
@Profile(ApplicationProfile.PRODUCTION)
public class SchemaVersionVerifier implements PriorityOrdered, InitializingBean {

private final SchemaVersionRepository schemaVersionRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.faforever.api.i18n;

import com.faforever.api.config.ApplicationProfile;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.support.AbstractResourceBasedMessageSource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

@Component
@RequiredArgsConstructor
Expand All @@ -18,6 +21,7 @@ public class RepositoryMessageSource extends AbstractResourceBasedMessageSource
private static final Locale FALLBACK_LOCALE = Locale.US;

private final MessageRepository messageRepository;
private final Environment environment;

/**
* Language -> Region -> Key -> Value.
Expand Down Expand Up @@ -76,6 +80,6 @@ private String getText(String key, Locale locale) {

@Override
public void afterPropertiesSet() {
messagesByLanguage = loadMessages();
messagesByLanguage = Set.of(environment.getActiveProfiles()).contains(ApplicationProfile.TRAINING) ? Map.of() : loadMessages();
}
}
1 change: 1 addition & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ spring:
properties:
hibernate:
current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
dialect: org.hibernate.dialect.MariaDBDialect
jackson:
serialization:
WRITE_DATES_AS_TIMESTAMPS: false
Expand Down

0 comments on commit 598fbe0

Please sign in to comment.