Skip to content

Commit

Permalink
fix: docker image build and run with app.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
fdelbrayelle committed May 25, 2020
1 parent 6ca77a2 commit 049516a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
47 changes: 35 additions & 12 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ module.exports = class extends BaseGenerator {
}

writing() {
// function to use directly template
this.template = function(source, destination) {
this.fs.copyTpl(this.templatePath(source), this.destinationPath(destination), this);
};

// function generate kafka application properties
this.generateKafkaProperties = function() {
let generatedKafkaProperties = '';
Expand Down Expand Up @@ -296,11 +291,16 @@ module.exports = class extends BaseGenerator {
this.removeFile(`${testDir}web/rest/${this.upperFirstCamelCase(this.baseName)}KafkaResourceIT.java`);

if (this.components.includes('consumer') && this.entities.length > 0) {
this.template('src/main/java/package/service/kafka/GenericConsumer.java.ejs', `${javaDir}service/kafka/GenericConsumer.java`);
this.template(
'src/main/java/package/service/kafka/GenericConsumer.java.ejs',
`${javaDir}service/kafka/GenericConsumer.java`,
null,
null
);
}

if (this.components.includes('consumer') || this.components.includes('producer')) {
this.template('src/main/java/package/config/KafkaProperties.java.ejs', `${javaDir}config/KafkaProperties.java`);
this.template('src/main/java/package/config/KafkaProperties.java.ejs', `${javaDir}config/KafkaProperties.java`, null, null);
}

this.entities.forEach(entity => {
Expand All @@ -310,11 +310,15 @@ module.exports = class extends BaseGenerator {
if (this.components.includes('consumer')) {
this.template(
'src/main/java/package/service/kafka/consumer/EntityConsumer.java.ejs',
`${javaDir}service/kafka/consumer/${entity}Consumer.java`
`${javaDir}service/kafka/consumer/${entity}Consumer.java`,
null,
null
);
this.template(
'src/main/java/package/service/kafka/deserializer/EntityDeserializer.java.ejs',
`${javaDir}service/kafka/deserializer/${entity}Deserializer.java`
`${javaDir}service/kafka/deserializer/${entity}Deserializer.java`,
null,
null
);
}
});
Expand All @@ -326,11 +330,15 @@ module.exports = class extends BaseGenerator {
if (this.components.includes('producer')) {
this.template(
'src/main/java/package/service/kafka/producer/EntityProducer.java.ejs',
`${javaDir}service/kafka/producer/${entity}Producer.java`
`${javaDir}service/kafka/producer/${entity}Producer.java`,
null,
null
);
this.template(
'src/main/java/package/service/kafka/serializer/EntitySerializer.java.ejs',
`${javaDir}service/kafka/serializer/${entity}Serializer.java`
`${javaDir}service/kafka/serializer/${entity}Serializer.java`,
null,
null
);
}
});
Expand All @@ -342,7 +350,22 @@ module.exports = class extends BaseGenerator {
this.replaceContent(`${resourceDir}config/application.yml`, kafkaBlockPattern, kafkaProperties);
this.replaceContent(`${testResourceDir}config/application.yml`, kafkaBlockPattern, kafkaProperties);

this.template('src/main/docker/kafka.yml.ejs', `${jhipsterConstants.MAIN_DIR}docker/kafka.yml`);
this.template('src/main/docker/kafka.yml.ejs', `${jhipsterConstants.MAIN_DIR}docker/kafka.yml`, this, null, null);

// Related to: https://github.com/jhipster/generator-jhipster/issues/11846
this.overrideMainGeneratorAppYml();
}

overrideMainGeneratorAppYml() {
const appYmlPath = `${jhipsterConstants.MAIN_DIR}docker/app.yml`;

const kafkaBootstrapServersPattern = /^\s.*KAFKA_BOOTSTRAPSERVERS.*$/gm;
const kafkaBootstrapServers = ' - KAFKA_BOOTSTRAP_SERVERS=kafka:29092';
this.replaceContent(appYmlPath, kafkaBootstrapServersPattern, kafkaBootstrapServers);

const kafkaAdvertisedListenersPattern = /^\s.*KAFKA_ADVERTISED_LISTENERS.*$/gm;
const kafkaAdvertisedListeners = ' - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092';
this.replaceContent(appYmlPath, kafkaAdvertisedListenersPattern, kafkaAdvertisedListeners);
}

install() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


kafka:
bootstrap.servers: localhost:9092
bootstrap.servers: ${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
<%_ if (pollingTimeout) { _%>
polling.timeout: <%= pollingTimeout %>
<%_ } _%>
Expand Down

0 comments on commit 049516a

Please sign in to comment.