Skip to content

Commit

Permalink
integrate docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 24, 2024
1 parent 61f58f5 commit e13ec0f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
15 changes: 14 additions & 1 deletion generators/docker/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export default class DockerGenerator extends BaseApplicationGenerator {
this.mergeDestinationYaml(`${application.dockerServicesDir}services.yml`, extendedServices);
};

source.addDockerExtendedServiceToApplication = (...services) => {
const extendedServices = createDockerExtendedServices(...services);
this.mergeDestinationYaml(`${application.dockerServicesDir}app.yml`, extendedServices);
};

source.addDockerDependencyToApplication = (...services) => {
this.mergeDestinationYaml(`${application.dockerServicesDir}app.yml`, {
services: {
Expand Down Expand Up @@ -178,8 +183,16 @@ export default class DockerGenerator extends BaseApplicationGenerator {
);
}

for (const serviceName of intersection(['postgresql', 'mysql', 'mariadb', 'mssql'], application.dockerServices)) {
// Blank profile services starts if no profile is passed.
const profiles = application.prodDatabaseType === application.devDatabaseType ? undefined : ['', 'prod'];
source.addDockerExtendedServiceToApplication({ serviceName });
source.addDockerExtendedServiceToServices({ serviceName, additionalConfig: { profiles } });
source.addDockerDependencyToApplication({ serviceName, condition: SERVICE_HEALTHY });
}

for (const serviceName of intersection(
['couchbase', 'mongodb', 'neo4j', 'postgresql', 'mysql', 'mariadb', 'mssql', 'elasticsearch', 'keycloak'],
['couchbase', 'mongodb', 'neo4j', 'elasticsearch', 'keycloak'],
application.dockerServices,
)) {
source.addDockerExtendedServiceToApplicationAndServices({ serviceName });
Expand Down
1 change: 1 addition & 0 deletions generators/maven/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type MavenDependency = MavenArtifact & {
type?: string;
scope?: string;
classifier?: string;
optional?: boolean;
additionalContent?: string;
};

Expand Down
20 changes: 20 additions & 0 deletions generators/spring-boot/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,26 @@ public void set${javaBeanCase(propertyName)}(${propertyType} ${propertyName}) {
]);
}
},
addSpringBootCompose({ application, source }) {
const dockerComposeArtifact = { groupId: 'org.springframework.boot', artifactId: 'spring-boot-docker-compose' };
if (application.buildToolGradle) {
source.addGradleDependency!({ ...dockerComposeArtifact, scope: 'developmentOnly' });
} else if (application.buildToolMaven) {
// Add dependency to profile due to jib issue https://github.com/GoogleContainerTools/jib-extensions/issues/158
source.addMavenDefinition!({
profiles: [
{
id: 'docker-compose',
content: `
<activation>
<activeByDefault>true</activeByDefault>
</activation>`,
},
],
});
source.addMavenDependency!({ inProfile: 'docker-compose', ...dockerComposeArtifact, optional: true });
}
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ spring:
additional-exclude: static/**<% if (devDatabaseTypeH2Any) { %>,.h2.server.properties<% } %>
livereload:
enabled: false # we use Webpack dev server + BrowserSync for livereload
<%_ if (devDatabaseTypeH2Any) { _%>
docker:
compose:
profiles:
active: dev
<%_ } _%>
jackson:
serialization:
indent-output: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ spring:
group: <%= dasherizedBaseName %>
<%_ } _%>
<%_ } _%>
docker:
compose:
lifecycle-management: start-only
file: ./<%- dockerServicesDir %>services.yml
profiles:
# The commented value for `active` can be replaced with valid Spring profiles to load.
# Otherwise, it will be filled in by <%= buildTool %> when building the JAR file
Expand Down

0 comments on commit e13ec0f

Please sign in to comment.