des trucs a droite a gauche
This commit is contained in:
parent
180ed9f054
commit
53a49f9bef
@ -20,7 +20,7 @@ pkgs.mkShell {
|
|||||||
echo "Quarkus dev environment ready!"
|
echo "Quarkus dev environment ready!"
|
||||||
echo "Java: $(java -version 2>&1 | head -n 1)"
|
echo "Java: $(java -version 2>&1 | head -n 1)"
|
||||||
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
|
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
|
||||||
dockerd-rootless
|
dockerd-rootless &
|
||||||
# Fix Docker socket
|
# Fix Docker socket
|
||||||
if [ ! -S /var/run/docker.sock ]; then
|
if [ ! -S /var/run/docker.sock ]; then
|
||||||
echo "⚠️ Docker not started. Run:"
|
echo "⚠️ Docker not started. Run:"
|
||||||
|
36
src/main/java/fr/la_banquise/backend/data/model/Ji.java
Normal file
36
src/main/java/fr/la_banquise/backend/data/model/Ji.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package fr.la_banquise.backend.data.model;
|
||||||
|
|
||||||
|
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.SequenceGenerator;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tp
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "ji")
|
||||||
|
public class Ji {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@SequenceGenerator(name = "JiSeq", sequenceName = "ji_id_seq", allocationSize = 1, initialValue = 1)
|
||||||
|
public Long id;
|
||||||
|
public String name;
|
||||||
|
public String description;
|
||||||
|
public String respo;
|
||||||
|
public String date;
|
||||||
|
|
||||||
|
public Tp(String name, String description, String respo, String date) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.respo = respo;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/fr/la_banquise/backend/data/model/Site.java
Normal file
31
src/main/java/fr/la_banquise/backend/data/model/Site.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package fr.la_banquise.backend.data.model;
|
||||||
|
|
||||||
|
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.SequenceGenerator;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "site")
|
||||||
|
public class Site {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@SequenceGenerator(name = "SiteSeq", sequenceName = "site_id_seq", allocationSize = 1, initialValue = 1)
|
||||||
|
public Long id;
|
||||||
|
public String name;
|
||||||
|
public String description;
|
||||||
|
public String address;
|
||||||
|
|
||||||
|
public Site(String name, String description, String address) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/fr/la_banquise/backend/data/model/Sites.java
Normal file
31
src/main/java/fr/la_banquise/backend/data/model/Sites.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package fr.la_banquise.backend.data.model;
|
||||||
|
|
||||||
|
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.SequenceGenerator;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "Sites")
|
||||||
|
public class Sites {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@SequenceGenerator(name = "SitesSeq", sequenceName = "sites_id_seq", allocationSize = 1, initialValue = 1)
|
||||||
|
public Long id;
|
||||||
|
public List<Site> sites;
|
||||||
|
|
||||||
|
public Sites(List<Site> sites) {
|
||||||
|
this.sites = sites;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
|||||||
|
package fr.la_banquise.backend.data.repository;
|
||||||
|
|
||||||
|
import fr.la_banquise.backend.data.model.Sites;
|
||||||
|
import io.quarkus.hibernate.orm.panache.PanacheRepository;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class SitesRepository implements PanacheRepository<Sites> {
|
||||||
|
}
|
@ -27,14 +27,57 @@ public class ContainerResource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@POST
|
||||||
@Path("/{id}")
|
@Path("/create")
|
||||||
public Response remove(@PathParam("id") String id) {
|
public Response createContainer(@QueryParam("name") String name, @QueryParam("port") int port) {
|
||||||
try {
|
try {
|
||||||
dockerService.stopAndRemove(id);
|
String id = dockerService.createContainer(name, port);
|
||||||
|
return Response.ok(Map.of("containerId", id)).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/all")
|
||||||
|
public Response listContainers() {
|
||||||
|
try {
|
||||||
|
String id = dockerService.listAllContainers();
|
||||||
|
return Response.ok(id).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/start")
|
||||||
|
public Response start(@QueryParam("id") String id) {
|
||||||
|
try {
|
||||||
|
dockerService.start(id);
|
||||||
|
return Response.ok(Map.of("containerId", id, "status", "Running")).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/stop")
|
||||||
|
public Response stop(@QueryParam("id") String id) {
|
||||||
|
try {
|
||||||
|
dockerService.stop(id);
|
||||||
return Response.ok(Map.of("containerId", id, "status", "removed")).build();
|
return Response.ok(Map.of("containerId", id, "status", "removed")).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
return Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
@DELETE
|
||||||
|
@Path("/remove")
|
||||||
|
public Response remove(@QueryParam("id") String id) {
|
||||||
|
try {
|
||||||
|
dockerService.remove(id);
|
||||||
|
return Response.ok(Map.of("containerId", id, "status", "removed")).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.status(500).entity(Map.of("error", e.getMessage())).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,6 +8,12 @@ import com.github.dockerjava.api.model.PortBinding;
|
|||||||
import com.github.dockerjava.api.model.Ports;
|
import com.github.dockerjava.api.model.Ports;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import com.github.dockerjava.api.model.Container;
|
||||||
|
import com.github.dockerjava.api.model.ContainerPort;
|
||||||
|
import com.github.dockerjava.api.command.InspectContainerResponse;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class DockerService {
|
public class DockerService {
|
||||||
@ -23,9 +29,15 @@ public class DockerService {
|
|||||||
|
|
||||||
HostConfig hostConfig = HostConfig.newHostConfig()
|
HostConfig hostConfig = HostConfig.newHostConfig()
|
||||||
.withPortBindings(portBindings);
|
.withPortBindings(portBindings);
|
||||||
|
Map<String, String> labels = new HashMap<>();
|
||||||
|
labels.put("test", "banquise");
|
||||||
|
labels.put("environment", "development");
|
||||||
|
labels.put("version", "1.0");
|
||||||
|
labels.put("created-by", "java-docker-api");
|
||||||
|
|
||||||
CreateContainerResponse container = dockerClient.createContainerCmd("nginx:latest")
|
CreateContainerResponse container = dockerClient.createContainerCmd("nginx:latest")
|
||||||
.withName("my-nginx")
|
.withName("my-nginx")
|
||||||
|
.withLabels(labels)
|
||||||
.withExposedPorts(tcp80)
|
.withExposedPorts(tcp80)
|
||||||
.withHostConfig(hostConfig)
|
.withHostConfig(hostConfig)
|
||||||
.exec();
|
.exec();
|
||||||
@ -34,8 +46,144 @@ public class DockerService {
|
|||||||
return container.getId();
|
return container.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopAndRemove(String containerId) {
|
public String createContainer(String containerName, int port) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
ExposedPort tcpSsh = ExposedPort.tcp(80);
|
||||||
|
|
||||||
|
Ports portBindings = new Ports();
|
||||||
|
portBindings.bind(tcpSsh, Ports.Binding.bindPort(port));
|
||||||
|
|
||||||
|
HostConfig hostConfig = HostConfig.newHostConfig()
|
||||||
|
.withPortBindings(portBindings);
|
||||||
|
|
||||||
|
CreateContainerResponse container = dockerClient.createContainerCmd("nginx:latest")
|
||||||
|
.withName(containerName)
|
||||||
|
.withExposedPorts(tcpSsh)
|
||||||
|
.withHostConfig(hostConfig)
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
//dockerClient.startContainerCmd(container.getId()).exec();
|
||||||
|
return container.getId();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public String listAllContainers() {
|
||||||
|
StringBuilder json = new StringBuilder();
|
||||||
|
List<Container> containers = dockerClient.listContainersCmd()
|
||||||
|
.withShowAll(true)
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
json.append("[");
|
||||||
|
|
||||||
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
|
Container container = containers.get(i);
|
||||||
|
|
||||||
|
json.append("{");
|
||||||
|
json.append("\"name\":\"").append(container.getNames()[0].substring(1)).append("\",");
|
||||||
|
json.append("\"id\":\"").append(container.getId()).append("\",");
|
||||||
|
json.append("\"image\":\"").append(container.getImage()).append("\",");
|
||||||
|
json.append("\"status\":\"").append(container.getStatus()).append("\",");
|
||||||
|
|
||||||
|
// Ports
|
||||||
|
InspectContainerResponse inspectResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
|
||||||
|
json.append("\"ports\":[");
|
||||||
|
if (container.getPorts() != null && container.getPorts().length > 0) {
|
||||||
|
for (int j = 0; j < .length; j+=2) {
|
||||||
|
ContainerPort port = container.getPorts()[j];
|
||||||
|
json.append("[\"");
|
||||||
|
json.append(port.getPrivatePort()).append("->").append(port.getPublicPort()).append("/"+port.getType()+"\",\"");
|
||||||
|
json.append(port.getIp()).append(",").append((container.getPorts()[j+1]).getIp());
|
||||||
|
if (port.getType() != null) {
|
||||||
|
json.append("/").append(port.getType());
|
||||||
|
}
|
||||||
|
if (port.getPublicPort() != null) {
|
||||||
|
json.append("->").append(port.getPublicPort());
|
||||||
|
}*
|
||||||
|
json.append("\"]");
|
||||||
|
if (j < container.getPorts().length - 2) {
|
||||||
|
json.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json.append("]");
|
||||||
|
|
||||||
|
// Ports
|
||||||
|
String ports = "[]";
|
||||||
|
try {
|
||||||
|
InspectContainerResponse inspectResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
|
||||||
|
if (inspectResponse.getConfig().getExposedPorts() != null) {
|
||||||
|
ports = inspectResponse.getConfig().getExposedPorts().toString();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Fallback vers les ports runtime si inspect échoue
|
||||||
|
if (container.getPorts() != null && container.getPorts().length > 0) {
|
||||||
|
ports = java.util.Arrays.toString(container.getPorts());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json.append("\"ports\":\"").append(ports).append("\"");
|
||||||
|
json.append("}");
|
||||||
|
if (i < containers.size() - 1) {
|
||||||
|
json.append(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
json.append("}");
|
||||||
|
|
||||||
|
if (i < containers.size() - 1) {
|
||||||
|
json.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
json.append("]");
|
||||||
|
return json.toString();
|
||||||
|
} */
|
||||||
|
public String listAllContainers() {
|
||||||
|
StringBuilder json = new StringBuilder();
|
||||||
|
List<Container> containers = dockerClient.listContainersCmd()
|
||||||
|
.withShowAll(true)
|
||||||
|
.exec();
|
||||||
|
json.append("[");
|
||||||
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
|
Container container = containers.get(i);
|
||||||
|
// Ports
|
||||||
|
List<String> portsList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
var inspectResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
|
||||||
|
if (inspectResponse.getConfig().getExposedPorts() != null) {
|
||||||
|
var exposedPorts = inspectResponse.getConfig().getExposedPorts();
|
||||||
|
int count = 0;
|
||||||
|
for (var port : exposedPorts) {
|
||||||
|
if (count > 0) portsList.append(",");
|
||||||
|
portsList.append(String.format("\"%s\"", port.toString()));
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
|
portsList.append("]");
|
||||||
|
ports = portsList.toString();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Fallback vers les ports runtime si inspect échoue
|
||||||
|
if (container.getPorts() != null && container.getPorts().length > 0) {
|
||||||
|
ports = java.util.Arrays.toString(container.getPorts());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//json.append(containerJson);
|
||||||
|
|
||||||
|
if (i < containers.size() - 1) {
|
||||||
|
json.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json.append("]");
|
||||||
|
return json.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(String containerId) {
|
||||||
|
dockerClient.startContainerCmd(containerId).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop(String containerId) {
|
||||||
dockerClient.stopContainerCmd(containerId).exec();
|
dockerClient.stopContainerCmd(containerId).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(String containerId) {
|
||||||
dockerClient.removeContainerCmd(containerId).exec();
|
dockerClient.removeContainerCmd(containerId).exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,8 +64,7 @@ public class TpService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Tp createTp(TpRequest requestTp) {
|
public Tp createTp(TpRequest requestTp) {
|
||||||
Tp tp = new Tp(requestTp.title, requestTp.description, requestTp.pdf, security.getUserPrincipal().getName(),
|
Tp tp = new Tp(requestTp.title, requestTp.description, requestTp.pdf, security.getUserPrincipal().getName(), requestTp.date);
|
||||||
requestTp.date);
|
|
||||||
tpRepository.persist(tp);
|
tpRepository.persist(tp);
|
||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ quarkus.datasource.password = secret
|
|||||||
|
|
||||||
# drop and create the database at startup (use `update` to only update the schema)drop-and-create
|
# drop and create the database at startup (use `update` to only update the schema)drop-and-create
|
||||||
quarkus.hibernate-orm.database.generation=update
|
quarkus.hibernate-orm.database.generation=update
|
||||||
# quarkus.hibernate-orm.database.generation=drop-and-create
|
#quarkus.hibernate-orm.database.generation=drop-and-create
|
||||||
|
|
||||||
quarkus.quinoa.dev-server.port=5173
|
quarkus.quinoa.dev-server.port=5173
|
||||||
quarkus.quinoa.enable-spa-routing=true
|
quarkus.quinoa.enable-spa-routing=true
|
||||||
|
|
||||||
quarkus.docker.docker-host=unix:///var/run/docker.sock
|
quarkus.docker.docker-host=unix:///run/user/1000/docker.sock
|
||||||
|
Loading…
x
Reference in New Issue
Block a user