Skip to content

Commit

Permalink
Merge pull request #135 from prosanteconnect/production
Browse files Browse the repository at this point in the history
production
  • Loading branch information
bou3108 authored Nov 2, 2022
2 parents 8edfa5a + 6ab7aa4 commit dc0ace0
Show file tree
Hide file tree
Showing 18 changed files with 459 additions and 381 deletions.
11 changes: 1 addition & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@ COPY pom.xml /usr/src/app
RUN mvn -f /usr/src/app/pom.xml -gs /usr/share/maven/ref/settings-docker.xml -Dextract.test.name=Extraction_Pro_sante_connect_cartes_de_test_bascule -DskipTests clean package

FROM openjdk:11-slim-buster
RUN echo "deb [trusted=yes] http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/debian.org buster main" > /etc/apt/sources.list \
&& echo "deb [trusted=yes] http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/debian.org buster-updates main" >> /etc/apt/sources.list \
&& apt update \
&& apt install -y --allow-downgrades wget gnupg=2.2.12-1+deb10u1 gpgv=2.2.12-1+deb10u1 dos2unix \
&& wget -qO - http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/www.mongodb.org/static/pgp/server-5.0.asc | apt-key add - \
&& echo "deb [trusted=yes] http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/debian-repo.mongodb.org buster/mongodb-org/5.0 main" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
RUN apt update
RUN apt install -y mongodb-database-tools mongodb-mongosh=1.5.0
COPY --from=build /usr/src/app/target/pscextract-*.jar /usr/app/pscextract.jar
RUN mkdir -p /app/extract-repo && mkdir -p /app/resources
COPY --from=build /usr/src/app/src/main/resources/aggregate.mongo /app/resources/
RUN usermod -d /app daemon && chown -R daemon: /app
USER daemon
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/app/pscextract.jar"]
ENTRYPOINT ["sh", "-c", "exec java -jar /usr/app/pscextract.jar"]
11 changes: 2 additions & 9 deletions Dockerfile.ext
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
FROM maven:3-jdk-11 AS build
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app
RUN mvn -f /usr/src/app/pom.xml -Dextract.test.name=Extraction_Pro_sante_connect_cartes_de_test_bascule clean package
RUN mvn -f /usr/src/app/pom.xml clean package -DskipTests=true

FROM openjdk:11-slim-buster
RUN apt update \
&& apt install -y wget gnupg dos2unix \
&& wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add - \
&& echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
RUN apt update
RUN apt install -y mongodb-database-tools mongodb-mongosh
COPY --from=build /usr/src/app/target/pscextract-*.jar /usr/app/pscextract.jar
RUN mkdir -p /app/extract-repo && mkdir -p /app/resources
COPY --from=build /usr/src/app/src/main/resources/aggregate.mongo /app/resources/
RUN chown -R daemon: /app
USER daemon
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/app/pscextract.jar"]
ENTRYPOINT ["sh", "-c", "exec java -jar /usr/app/pscextract.jar"]

44 changes: 25 additions & 19 deletions pscextract.nomad.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
job "pscextract" {
datacenters = ["${datacenter}"]
type = "service"
namespace = "${nomad_namespace}"
vault {
policies = ["psc-ecosystem"]
Expand Down Expand Up @@ -28,7 +29,7 @@ job "pscextract" {
mount {
type = "volume"
target = "/app/extract-repo"
source = "pscextract-data"
source = "${nomad_namespace}-pscextract-data"
readonly = false
volume_options {
no_copy = false
Expand Down Expand Up @@ -70,7 +71,7 @@ job "pscextract" {
extra_hosts = [ "psc-api-maj.internal:$\u007BNOMAD_IP_http\u007D" ]
image = "${artifact.image}:${artifact.tag}"
volumes = [
"name=pscextract-data,io_priority=high,size=10,repl=3:/app/extract-repo"
"name=${nomad_namespace}-pscextract-data,io_priority=high,size=10,repl=3:/app/extract-repo"
]
volume_driver = "pxd"
ports = ["http"]
Expand All @@ -79,34 +80,39 @@ job "pscextract" {
destination = "local/file.env"
env = true
data = <<EOF
PUBLIC_HOSTNAME={{ with secret "psc-ecosystem/pscextract" }}{{ .Data.data.public_hostname }}{{ end }}
PUBLIC_HOSTNAME={{ with secret "psc-ecosystem/${nomad_namespace}/pscextract" }}{{ .Data.data.public_hostname }}{{ end }}
EOF
}
template {
data = <<EOF
server.servlet.context-path=/pscextract/v1
mongodb.host={{ range service "psc-mongodb" }}{{ .Address }}{{ end }}
mongodb.port={{ range service "psc-mongodb" }}{{ .Port }}{{ end }}
mongodb.host={{ range service "${nomad_namespace}-psc-mongodb" }}{{ .Address }}{{ end }}
mongodb.port={{ range service "${nomad_namespace}-psc-mongodb" }}{{ .Port }}{{ end }}
mongodb.name=mongodb
mongodb.username={{ with secret "psc-ecosystem/mongodb" }}{{ .Data.data.root_user}}{{ end }}
mongodb.password={{ with secret "psc-ecosystem/mongodb" }}{{ .Data.data.root_pass}}{{ end }}
mongodb.username={{ with secret "psc-ecosystem/${nomad_namespace}/mongodb" }}{{ .Data.data.root_user}}{{ end }}
mongodb.password={{ with secret "psc-ecosystem/${nomad_namespace}/mongodb" }}{{ .Data.data.root_pass}}{{ end }}
mongodb.admin.database=admin

files.directory=/app/extract-repo
working.directory=/app/extract-repo/working-directory
api.base.url=http://psc-api-maj.internal:9999/psc-api-maj/api
api.base.url={{ range service "${nomad_namespace}-psc-api-maj-v2" }}http://{{ .Address }}:{{ .Port }}/psc-api-maj/api{{ end }}

extract.name=Extraction_Pro_sante_connect
extract.test.name=Extraction_Pro_sante_connect_cartes_de_test_bascule.zip
extract.test.name={{ with secret "psc-ecosystem/${nomad_namespace}/pscextract" }}{{ .Data.data.test_file_name }}{{ end }}
page.size=50000
first.name.count=3
server.servlet.context-path=/pscextract/v1
spring.mail.host={{ with secret "psc-ecosystem/admin" }}{{ .Data.data.mail_server_host }}{{ end }}
spring.mail.port={{ with secret "psc-ecosystem/admin" }}{{ .Data.data.mail_server_port }}{{ end }}
spring.mail.username={{ with secret "psc-ecosystem/admin" }}{{ .Data.data.mail_username }}{{ end }}
spring.mail.password={{ with secret "psc-ecosystem/admin" }}{{ .Data.data.mail_password }}{{ end }}
spring.mail.properties.mail.smtp.auth={{ with secret "psc-ecosystem/admin" }}{{ .Data.data.mail_smtp_auth }}{{ end }}
spring.mail.properties.mail.smtp.starttls.enable={{ with secret "psc-ecosystem/admin" }}{{ .Data.data.mail_enable_tls }}{{ end }}
pscextract.mail.receiver={{ with secret "psc-ecosystem/admin" }}{{ .Data.data.mail_receiver }}{{ end }}

spring.mail.host={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.mail_server_host }}{{ end }}
spring.mail.port={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.mail_server_port }}{{ end }}
spring.mail.username={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.mail_username }}{{ end }}
spring.mail.password={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.mail_password }}{{ end }}
spring.mail.properties.mail.smtp.auth={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.mail_smtp_auth }}{{ end }}
spring.mail.properties.mail.smtp.starttls.enable={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.mail_enable_tls }}{{ end }}
pscextract.mail.receiver={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.mail_receiver }}{{ end }}
secpsc.environment={{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}{{ .Data.data.platform }}{{ end }}

{{ with secret "psc-ecosystem/${nomad_namespace}/admin" }}logging.level.fr.ans.psc={{ .Data.data.log_level }}{{ end }}
EOF
destination = "secrets/application.properties"
}
Expand All @@ -115,7 +121,7 @@ EOF
memory = 2560
}
service {
name = "$\u007BNOMAD_JOB_NAME\u007D"
name = "$\u007BNOMAD_NAMESPACE\u007D-$\u007BNOMAD_JOB_NAME\u007D"
tags = ["urlprefix-$\u007BPUBLIC_HOSTNAME\u007D/pscextract/v1/"]
port = "http"
check {
Expand All @@ -141,14 +147,14 @@ EOF
}
template {
data = <<EOH
LOGSTASH_HOST = {{ range service "logstash" }}{{ .Address }}:{{ .Port }}{{ end }}
LOGSTASH_HOST = {{ range service "${nomad_namespace}-logstash" }}{{ .Address }}:{{ .Port }}{{ end }}
ENVIRONMENT = "${datacenter}"
EOH
destination = "local/file.env"
env = true
}
config {
image = "${registry_path}/filebeat:7.14.2"
image = "${registry_username}/filebeat:7.14.2"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,35 @@ public ResponseEntity<FileSystemResource> getDemoExtractFile() {

@PostMapping(value = "/generate-extract")
public ResponseEntity<?> generateExtract(@RequestParam(required = false) Integer pageSize) {
if(!busy) {
if (!busy) {
ForkJoinPool.commonPool().submit(() -> {
try {
busy = true;
if (pageSize != null)
if (pageSize != null) {
this.pageSize = pageSize;
if (this.psApi == null)
}
if (this.psApi == null) {
instantiateApi();
}

File latestExtract = transformationService.extractToCsv(this);
FileNamesUtil.cleanup(filesDirectory, extractTestName);

if (latestExtract != null)
if (latestExtract != null) {
emailService.sendSimpleMessage("PSCEXTRACT - sécurisation effectuée", latestExtract);
else
}
else {
emailService.sendSimpleMessage("PSCEXTRACT - sécurisation échouée", null);
}
} catch (IOException e) {
log.error("Exception raised :", e);
} finally {
busy = false;
}
});
}else
} else {
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
return new ResponseEntity<>(HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public class EmailService {
@Value("${pscextract.mail.receiver}")
private String receiver;

@Value("${secpsc.environment}")
private String platform;

public void sendSimpleMessage(String subject, File latestExtract) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(sender);
String[] allReceivers = receiver.split(",");
message.setTo(allReceivers);
message.setSubject(subject);
message.setSubject(platform + " - " + subject);
message.setText(getEmailMessage(latestExtract));

emailSender.send(message);
Expand Down
Loading

0 comments on commit dc0ace0

Please sign in to comment.