generated from CodelyTV/java-basic-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c65ab95
commit 64a6d44
Showing
38 changed files
with
853 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
name: CI | ||
|
||
on: [push] | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Start all the environment | ||
run: docker-compose up -d | ||
- name: 🐳 Start all the environment | ||
run: make start | ||
|
||
- name: Wait for the environment to get up | ||
- name: 🔦 Lint | ||
run: make lint | ||
|
||
- name: 🦭 Wait for the environment to get up | ||
run: | | ||
while ! make ping-mysql &>/dev/null; do | ||
echo "Waiting for database connection..." | ||
sleep 2 | ||
done | ||
- name: Run the tests | ||
- name: ✅ Run the tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
FROM openjdk:21-slim-buster | ||
WORKDIR /app | ||
|
||
RUN apt update && apt install -y curl git | ||
|
||
ENV NVM_DIR /usr/local/nvm | ||
ENV NODE_VERSION 18.0.0 | ||
|
||
RUN mkdir -p $NVM_DIR | ||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash | ||
|
||
RUN . $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use default | ||
|
||
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules | ||
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
.PHONY: all | ||
all: build | ||
|
||
.PHONY: up | ||
up: | ||
@docker-compose up -d | ||
start: | ||
@docker compose up -d | ||
|
||
.PHONY: build | ||
build: | ||
@./gradlew build --warning-mode all | ||
|
||
.PHONY: run-tests | ||
lint: | ||
@docker exec codelytv-ddd_example-java ./gradlew spotlessCheck | ||
|
||
run-tests: | ||
@./gradlew test --warning-mode all | ||
|
||
.PHONY: test | ||
test: | ||
@docker exec codelytv-ddd_example-java ./gradlew test --warning-mode all | ||
|
||
.PHONY: run | ||
run: | ||
@./gradlew :run | ||
|
||
.PHONY: ping-mysql | ||
ping-mysql: | ||
@docker exec codelytv-java_ddd_example-mysql mysqladmin --user=root --password= --host "127.0.0.1" ping --silent | ||
|
||
# Start the app | ||
.PHONY: start-mooc_backend | ||
start-mooc_backend: | ||
@./gradlew bootRun --args='mooc_backend server' | ||
|
||
.PHONY: start-backoffice_frontend | ||
start-backoffice_frontend: | ||
@./gradlew bootRun --args='backoffice_frontend server' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,96 @@ | ||
package tv.codely.apps; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.WebApplicationType; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import tv.codely.apps.backoffice.backend.BackofficeBackendApplication; | ||
import tv.codely.apps.backoffice.frontend.BackofficeFrontendApplication; | ||
import tv.codely.apps.mooc.backend.MoocBackendApplication; | ||
import tv.codely.shared.infrastructure.cli.ConsoleCommand; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
||
public class Starter { | ||
public static void main(String[] args) { | ||
if (args.length < 2) { | ||
throw new RuntimeException("There are not enough arguments"); | ||
} | ||
|
||
String applicationName = args[0]; | ||
String commandName = args[1]; | ||
boolean isServerCommand = commandName.equals("server"); | ||
|
||
ensureApplicationExist(applicationName); | ||
ensureCommandExist(applicationName, commandName); | ||
|
||
Class<?> applicationClass = applications().get(applicationName); | ||
|
||
SpringApplication app = new SpringApplication(applicationClass); | ||
|
||
if (!isServerCommand) { | ||
app.setWebApplicationType(WebApplicationType.NONE); | ||
} | ||
|
||
ConfigurableApplicationContext context = app.run(args); | ||
|
||
if (!isServerCommand) { | ||
ConsoleCommand command = (ConsoleCommand) context.getBean( | ||
commands().get(applicationName).get(commandName) | ||
); | ||
|
||
command.execute(Arrays.copyOfRange(args, 2, args.length)); | ||
} | ||
} | ||
|
||
private static void ensureApplicationExist(String applicationName) { | ||
if (!applications().containsKey(applicationName)) { | ||
throw new RuntimeException(String.format( | ||
"The application <%s> doesn't exist. Valids:\n- %s", | ||
applicationName, | ||
String.join("\n- ", applications().keySet()) | ||
)); | ||
} | ||
} | ||
|
||
private static void ensureCommandExist(String applicationName, String commandName) { | ||
if (!"server".equals(commandName) && !existCommand(applicationName, commandName)) { | ||
throw new RuntimeException(String.format( | ||
"The command <%s> for application <%s> doesn't exist. Valids (application.command):\n- api\n- %s", | ||
commandName, | ||
applicationName, | ||
String.join("\n- ", commands().get(applicationName).keySet()) | ||
)); | ||
} | ||
} | ||
|
||
private static HashMap<String, Class<?>> applications() { | ||
HashMap<String, Class<?>> applications = new HashMap<>(); | ||
|
||
applications.put("mooc_backend", MoocBackendApplication.class); | ||
applications.put("backoffice_backend", BackofficeBackendApplication.class); | ||
applications.put("backoffice_frontend", BackofficeFrontendApplication.class); | ||
|
||
return applications; | ||
} | ||
|
||
private static HashMap<String, HashMap<String, Class<?>>> commands() { | ||
HashMap<String, HashMap<String, Class<?>>> commands = new HashMap<>(); | ||
|
||
commands.put("mooc_backend", MoocBackendApplication.commands()); | ||
commands.put("backoffice_backend", BackofficeBackendApplication.commands()); | ||
commands.put("backoffice_frontend", BackofficeFrontendApplication.commands()); | ||
|
||
return commands; | ||
} | ||
|
||
private static Boolean existCommand(String applicationName, String commandName) { | ||
HashMap<String, HashMap<String, Class<?>>> commands = commands(); | ||
|
||
return commands.containsKey(applicationName) && commands.get(applicationName).containsKey(commandName); | ||
} | ||
|
||
public static void main(String[] args) { | ||
if (args.length < 2) { | ||
throw new RuntimeException("There are not enough arguments"); | ||
} | ||
|
||
String applicationName = args[0]; | ||
String commandName = args[1]; | ||
boolean isServerCommand = commandName.equals("server"); | ||
|
||
ensureApplicationExist(applicationName); | ||
ensureCommandExist(applicationName, commandName); | ||
|
||
Class<?> applicationClass = applications().get(applicationName); | ||
|
||
SpringApplication app = new SpringApplication(applicationClass); | ||
|
||
if (!isServerCommand) { | ||
app.setWebApplicationType(WebApplicationType.NONE); | ||
} | ||
|
||
ConfigurableApplicationContext context = app.run(args); | ||
|
||
if (!isServerCommand) { | ||
ConsoleCommand command = (ConsoleCommand) context.getBean(commands().get(applicationName).get(commandName)); | ||
|
||
command.execute(Arrays.copyOfRange(args, 2, args.length)); | ||
} | ||
} | ||
|
||
private static void ensureApplicationExist(String applicationName) { | ||
if (!applications().containsKey(applicationName)) { | ||
throw new RuntimeException( | ||
String.format( | ||
"The application <%s> doesn't exist. Valids:\n- %s", | ||
applicationName, | ||
String.join("\n- ", applications().keySet()) | ||
) | ||
); | ||
} | ||
} | ||
|
||
private static void ensureCommandExist(String applicationName, String commandName) { | ||
if (!"server".equals(commandName) && !existCommand(applicationName, commandName)) { | ||
throw new RuntimeException( | ||
String.format( | ||
"The command <%s> for application <%s> doesn't exist. Valids (application.command):\n- api\n- %s", | ||
commandName, | ||
applicationName, | ||
String.join("\n- ", commands().get(applicationName).keySet()) | ||
) | ||
); | ||
} | ||
} | ||
|
||
private static HashMap<String, Class<?>> applications() { | ||
HashMap<String, Class<?>> applications = new HashMap<>(); | ||
|
||
applications.put("mooc_backend", MoocBackendApplication.class); | ||
applications.put("backoffice_backend", BackofficeBackendApplication.class); | ||
applications.put("backoffice_frontend", BackofficeFrontendApplication.class); | ||
|
||
return applications; | ||
} | ||
|
||
private static HashMap<String, HashMap<String, Class<?>>> commands() { | ||
HashMap<String, HashMap<String, Class<?>>> commands = new HashMap<>(); | ||
|
||
commands.put("mooc_backend", MoocBackendApplication.commands()); | ||
commands.put("backoffice_backend", BackofficeBackendApplication.commands()); | ||
commands.put("backoffice_frontend", BackofficeFrontendApplication.commands()); | ||
|
||
return commands; | ||
} | ||
|
||
private static Boolean existCommand(String applicationName, String commandName) { | ||
HashMap<String, HashMap<String, Class<?>>> commands = commands(); | ||
|
||
return commands.containsKey(applicationName) && commands.get(applicationName).containsKey(commandName); | ||
} | ||
} |
19 changes: 11 additions & 8 deletions
19
apps/main/tv/codely/apps/backoffice/backend/BackofficeBackendApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
package tv.codely.apps.backoffice.backend; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.FilterType; | ||
import tv.codely.shared.domain.Service; | ||
|
||
import java.util.HashMap; | ||
import tv.codely.shared.domain.Service; | ||
|
||
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class) | ||
@ComponentScan( | ||
includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Service.class), | ||
value = {"tv.codely.shared", "tv.codely.backoffice", "tv.codely.apps.backoffice.backend"} | ||
includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Service.class), | ||
value = { "tv.codely.shared", "tv.codely.backoffice", "tv.codely.apps.backoffice.backend" } | ||
) | ||
public class BackofficeBackendApplication { | ||
public static HashMap<String, Class<?>> commands() { | ||
return new HashMap<String, Class<?>>() {{ | ||
}}; | ||
} | ||
|
||
public static HashMap<String, Class<?>> commands() { | ||
return new HashMap<String, Class<?>>() { | ||
{} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.