пофиксил создание образа
This commit is contained in:
parent
0fae695941
commit
5c3bc9060c
105
pom.xml
105
pom.xml
|
|
@ -14,6 +14,111 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${maven.compiler.source}</source>
|
||||||
|
<target>${maven.compiler.target}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>module-info.class</exclude>
|
||||||
|
<exclude>JDOMAbout*class</exclude>
|
||||||
|
<exclude>META-INF/*.SF</exclude>
|
||||||
|
<exclude>META-INF/*.DSA</exclude>
|
||||||
|
<exclude>META-INF/*.RSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
<transformers>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Main-Class>ru.kirillius.mktbk.App</Main-Class>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<shadedArtifactAttached>true
|
||||||
|
</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
|
||||||
|
<shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<!-- This calls launch4j to create the program EXE -->
|
||||||
|
<groupId>com.akathist.maven.plugins.launch4j</groupId>
|
||||||
|
<artifactId>launch4j-maven-plugin</artifactId>
|
||||||
|
<version>2.1.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>l4j-wrapper</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>launch4j</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<headerType>console</headerType>
|
||||||
|
<downloadUrl>https://aws.amazon.com/ru/corretto/</downloadUrl>
|
||||||
|
<outfile>target/mktbk.exe</outfile>
|
||||||
|
<jar>
|
||||||
|
${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar
|
||||||
|
</jar>
|
||||||
|
<errTitle/>
|
||||||
|
<classPath>
|
||||||
|
<mainClass>ru.kirillius.mktbk.App</mainClass>
|
||||||
|
<addDependencies>false</addDependencies>
|
||||||
|
<preCp>anything</preCp>
|
||||||
|
</classPath>
|
||||||
|
<!-- <icon>src/main/resources/icon.ico</icon>-->
|
||||||
|
<jre>
|
||||||
|
<path>./data</path>
|
||||||
|
<minVersion>${maven.compiler.source}</minVersion>
|
||||||
|
<maxVersion/>
|
||||||
|
</jre>
|
||||||
|
|
||||||
|
<versionInfo>
|
||||||
|
<fileVersion>${project.version}</fileVersion>
|
||||||
|
<txtFileVersion>${project.version}</txtFileVersion>
|
||||||
|
<fileDescription>mktbk</fileDescription>
|
||||||
|
<copyright>copy left</copyright>
|
||||||
|
<productVersion>${project.version}</productVersion>
|
||||||
|
<txtProductVersion>${project.version}</txtProductVersion>
|
||||||
|
<productName>mktbk</productName>
|
||||||
|
<companyName>Y U SO SRS?</companyName>
|
||||||
|
<internalName>mktbk</internalName>
|
||||||
|
<originalFilename>mktbk.exe</originalFilename>
|
||||||
|
<language>ENGLISH_US</language>
|
||||||
|
</versionInfo>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>kirillius</id>
|
<id>kirillius</id>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
package ru.kirillius.mktbk;
|
package ru.kirillius.mktbk;
|
||||||
|
|
||||||
import me.legrange.mikrotik.MikrotikApiException;
|
import me.legrange.mikrotik.MikrotikApiException;
|
||||||
import net.schmizz.sshj.sftp.SFTPException;
|
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||||
import org.apache.commons.compress.archivers.tar.TarConstants;
|
import org.apache.commons.compress.archivers.tar.TarConstants;
|
||||||
import ru.kirillius.utils.logging.SystemLogger;
|
import ru.kirillius.utils.logging.SystemLogger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
@ -115,10 +113,10 @@ public class App {
|
||||||
var layerFile = new File(container.getGuid());
|
var layerFile = new File(container.getGuid());
|
||||||
var outputFile = new File("backup_of_" + container.getComment() + ".tar");
|
var outputFile = new File("backup_of_" + container.getComment() + ".tar");
|
||||||
|
|
||||||
if (!layerFile.exists()) {
|
|
||||||
var files = findFiles(container);
|
var files = findFiles(container);
|
||||||
downloadFiles(container, files, layerFile);
|
downloadFiles(container, files, layerFile);
|
||||||
}
|
|
||||||
|
|
||||||
SystemLogger.message("Building docker image " + outputFile.getName(), LOG_CONTEXT);
|
SystemLogger.message("Building docker image " + outputFile.getName(), LOG_CONTEXT);
|
||||||
var builder = new DockerImageBuilder(container);
|
var builder = new DockerImageBuilder(container);
|
||||||
|
|
@ -141,10 +139,11 @@ public class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadFiles(ContainerMetadata container, List<FileMetadata> files, File outputFile) throws IOException {
|
private void downloadFiles(ContainerMetadata container, List<FileMetadata> files, File outputFile) throws IOException {
|
||||||
|
SystemLogger.message("Building image layer from remote files", LOG_CONTEXT);
|
||||||
var sftp = deviceContext.getSftpClient();
|
var sftp = deviceContext.getSftpClient();
|
||||||
try (var outputStream = new FileOutputStream(outputFile)) {
|
try (var outputStream = new FileOutputStream(outputFile)) {
|
||||||
try (var tar = new TarArchiveOutputStream(outputStream)) {
|
try (var tar = new TarArchiveOutputStream(outputStream)) {
|
||||||
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
|
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
|
||||||
var status = new DownloadStatus("Downloading", files.size());
|
var status = new DownloadStatus("Downloading", files.size());
|
||||||
for (var file : files) {
|
for (var file : files) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -190,26 +189,14 @@ public class App {
|
||||||
|
|
||||||
private List<FileMetadata> findFiles(ContainerMetadata container) throws IOException, InterruptedException {
|
private List<FileMetadata> findFiles(ContainerMetadata container) throws IOException, InterruptedException {
|
||||||
SystemLogger.message("Reading container filesystem metadata...", LOG_CONTEXT);
|
SystemLogger.message("Reading container filesystem metadata...", LOG_CONTEXT);
|
||||||
var filterContents = List.of("/sys/", "/proc/", "/dev/", "/mnt/", "/run/", "/tmp/");
|
var systemDirs = List.of("/sys/", "/proc/", "/dev/", "/mnt/", "/run/", "/tmp/");
|
||||||
var files = deviceContext.listFilesystem(container).stream().filter(f -> filterContents.contains(f.getPath()) || filterContents.stream().noneMatch(s -> f.getPath().startsWith(s))).toList();
|
var filterFiles = List.of("/.type");
|
||||||
|
var files = deviceContext.listFilesystem(container).stream().filter(fileMetadata -> !filterFiles.contains(fileMetadata.getPath())).filter(f -> systemDirs.contains(f.getPath()) || systemDirs.stream().noneMatch(s -> f.getPath().startsWith(s))).toList();
|
||||||
SystemLogger.message("Found " + files.size() + " files", LOG_CONTEXT);
|
SystemLogger.message("Found " + files.size() + " files", LOG_CONTEXT);
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private void openSSH() throws TransportException, ConnectionException {
|
|
||||||
// session = client.startSession();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// private void openSFTP() throws IOException {
|
|
||||||
// sftpClient = client.newSFTPClient();
|
|
||||||
// for (var info : sftpClient.ls("/")) {
|
|
||||||
// System.out.println(info.getPath());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
private DeviceContext deviceContext;
|
private DeviceContext deviceContext;
|
||||||
|
|
||||||
private void auth() {
|
private void auth() {
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,10 @@ import net.schmizz.sshj.sftp.SFTPClient;
|
||||||
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
|
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
|
||||||
import ru.kirillius.utils.logging.SystemLogger;
|
import ru.kirillius.utils.logging.SystemLogger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringJoiner;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DeviceContext implements Closeable {
|
public class DeviceContext implements Closeable {
|
||||||
|
|
@ -94,7 +93,10 @@ public class DeviceContext implements Closeable {
|
||||||
String line;
|
String line;
|
||||||
String directory = null;
|
String directory = null;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
if (line.startsWith(LIST_COMMAND)) {
|
if (line.trim().endsWith(LIST_COMMAND)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.contains(BEGIN_PATTERN)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (line.endsWith(END_PATTERN)) {
|
if (line.endsWith(END_PATTERN)) {
|
||||||
|
|
|
||||||
|
|
@ -41,18 +41,18 @@ public class DownloadStatus {
|
||||||
if (bytes < 1024) {
|
if (bytes < 1024) {
|
||||||
return bytes + " B";
|
return bytes + " B";
|
||||||
} else if (bytes < 1048576L) {
|
} else if (bytes < 1048576L) {
|
||||||
return Math.floor((float) bytes / 1024L) + " KB";
|
return Math.floor((float) bytes / 102.4f) / 10f + " KB";
|
||||||
} else if (bytes < 1073741824L) {
|
} else if (bytes < 1073741824L) {
|
||||||
return Math.floor((float) bytes / 1048576L) + " MB";
|
return Math.floor((float) bytes / 104857.6f) / 10f + " MB";
|
||||||
} else if (bytes < 1099511627776L) {
|
} else if (bytes < 1099511627776L) {
|
||||||
return Math.floor((float) bytes / 1073741824L) + " GB";
|
return Math.floor((float) bytes / 107374182.4f) / 10f + " GB";
|
||||||
} else {
|
} else {
|
||||||
return Math.floor((float) bytes / 1099511627776L) + " TB";
|
return Math.floor((float) bytes / 109951162777.6f) / 10f + " TB";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
if (System.currentTimeMillis() - lastUpdate < 1000) {
|
if (System.currentTimeMillis() - lastUpdate < 250) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
|
|
@ -69,7 +69,7 @@ public class DownloadStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(){
|
public void finish() {
|
||||||
lastUpdate = 0;
|
lastUpdate = 0;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue