fix(docker): clean up tmp directory on plugin download

This commit is contained in:
Ludovic DEHON
2022-04-21 21:55:00 +02:00
parent 972181cf96
commit ea41b44432
2 changed files with 14 additions and 4 deletions

View File

@@ -6,8 +6,8 @@ ARG APT_PACKAGES=""
WORKDIR /app
COPY docker /
RUN if [ -n "${APT_PACKAGES}" ]; then apt-get update -y; apt-get install -y --no-install-recommends ${APT_PACKAGES}; apt-get clean && rm -rf /var/lib/apt/lists/* /var/tmp/*; fi && \
if [ -n "${KESTRA_PLUGINS}" ]; then /app/kestra plugins install ${KESTRA_PLUGINS}; fi
RUN if [ -n "${APT_PACKAGES}" ]; then apt-get update -y; apt-get install -y --no-install-recommends ${APT_PACKAGES}; apt-get clean; rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/*; fi && \
if [ -n "${KESTRA_PLUGINS}" ]; then /app/kestra plugins install ${KESTRA_PLUGINS}; rm -rf /tmp/*; fi
ENTRYPOINT ["docker-entrypoint.sh"]

View File

@@ -3,6 +3,7 @@ package io.kestra.cli.plugins;
import com.google.common.collect.ImmutableList;
import io.micronaut.context.annotation.Value;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
@@ -103,10 +104,19 @@ public class PluginDownloader {
if (localRepositoryPath == null) {
try {
localRepositoryPath = Files.createTempDirectory(this.getClass().getSimpleName().toLowerCase())
final String tempDirectory = Files.createTempDirectory(this.getClass().getSimpleName().toLowerCase())
.toAbsolutePath()
.toString();
new File(localRepositoryPath).deleteOnExit();
localRepositoryPath = tempDirectory;
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
FileUtils.deleteDirectory(new File(tempDirectory));
} catch (IOException e) {
throw new RuntimeException(e);
}
}));
} catch (IOException e) {
throw new RuntimeException(e);
}