Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■
    Dockerfile.linux
    1 1  # do not use alpine image here to avoid the issue that git can not be configured to trust specified certificate when connecting to a https url
    2 2  FROM openjdk:8u212-jre-slim
    3  -RUN apt-get update && apt-get install -y git
     3 +RUN apt-get update && apt-get install -y git git-lfs
    4 4  COPY target/*.jar /k8s-helper/
    5 5  COPY target/lib/*.jar /k8s-helper/
    6 6   
  • ■ ■ ■ ■ ■
    Dockerfile.windows
    skipped 1 lines
    2 2  FROM mcr.microsoft.com/windows/servercore:$osVersion
    3 3  RUN cmd /c @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
    4 4  RUN choco install git --version 2.22.0 -y
     5 +RUN choco install git-lfs --version 2.13.3 -y
    5 6  RUN choco install openjdk --version 11.0.2.01 -y
    6 7  RUN cmd /c rmdir /q /s %USERPROFILE%\AppData\Local\Temp\chocolatey
    7 8  COPY target/*.jar C:/k8s-helper/
    skipped 2 lines
  • ■ ■ ■ ■
    pom.xml
    skipped 9 lines
    10 10   <version>1.0.5</version>
    11 11   </parent>
    12 12   <artifactId>k8s-helper</artifactId>
    13  - <version>2.1.10</version>
     13 + <version>2.2.10</version>
    14 14   <build>
    15 15   <plugins>
    16 16   <plugin>
    skipped 74 lines
  • ■ ■ ■ ■ ■ ■
    src/main/java/io/onedev/k8shelper/CheckoutCode.java
    skipped 18 lines
    19 19   if (jobToken == null)
    20 20   throw new RuntimeException("Environment '" + KubernetesHelper.ENV_JOB_TOKEN + "' is not defined");
    21 21   
    22  - KubernetesHelper.checkoutCode(serverUrl, jobToken, args[0],
    23  - Integer.parseInt(args[1]), CloneInfo.fromString(args[2]));
     22 + KubernetesHelper.checkoutCode(serverUrl, jobToken, args[0], Boolean.parseBoolean(args[2]),
     23 + Boolean.parseBoolean(args[3]), Integer.parseInt(args[1]), CloneInfo.fromString(args[4]));
    24 24   } catch (Exception e) {
    25 25   logger.error("Error executing step", e);
    26 26   exitCode = 1;
    skipped 8 lines
  • ■ ■ ■ ■ ■ ■
    src/main/java/io/onedev/k8shelper/CheckoutExecutable.java
    skipped 5 lines
    6 6   
    7 7   private final int cloneDepth;
    8 8  
     9 + private final boolean withLfs;
     10 +
     11 + private final boolean withSubmodules;
     12 +
    9 13   private final CloneInfo cloneInfo;
    10 14  
    11  - public CheckoutExecutable(int cloneDepth, CloneInfo cloneInfo) {
     15 + public CheckoutExecutable(int cloneDepth, boolean withLfs, boolean withSubmodules, CloneInfo cloneInfo) {
    12 16   this.cloneDepth = cloneDepth;
     17 + this.withLfs = withLfs;
     18 + this.withSubmodules = withSubmodules;
    13 19   this.cloneInfo = cloneInfo;
     20 + }
     21 + 
     22 + public boolean isWithLfs() {
     23 + return withLfs;
     24 + }
     25 + 
     26 + public boolean isWithSubmodules() {
     27 + return withSubmodules;
    14 28   }
    15 29   
    16 30   public int getCloneDepth() {
    skipped 9 lines
  • ■ ■ ■ ■ ■
    src/main/java/io/onedev/k8shelper/KubernetesHelper.java
    skipped 497 lines
    498 498   CheckoutExecutable checkoutExecutable = (CheckoutExecutable) executable;
    499 499   checkoutExecutable.getCloneInfo();
    500 500   command = String.format("java -classpath \"%s\" io.onedev.k8shelper.CheckoutCode %s %d %s",
    501  - classPath, positionStr, checkoutExecutable.getCloneDepth(),
    502  - checkoutExecutable.getCloneInfo().toString());
     501 + classPath, positionStr, checkoutExecutable.isWithLfs(), checkoutExecutable.isWithSubmodules(),
     502 + checkoutExecutable.getCloneDepth(), checkoutExecutable.getCloneInfo().toString());
    503 503   } else {
    504 504   ServerExecutable serverExecutable = (ServerExecutable) executable;
    505 505  
    skipped 62 lines
    568 568   }
    569 569   }
    570 570   
    571  - public static void checkoutRepository(Commandline git, String commitHash,
    572  - LineConsumer infoLogger, LineConsumer errorLogger) {
    573  - git.clearArgs();
    574  - git.addArgs("checkout", "--quiet", commitHash);
    575  - git.execute(infoLogger, errorLogger).checkReturnCode();
    576  - }
    577  -
    578 571   public static void cloneRepository(Commandline git, String cloneUrl, String remoteUrl,
    579  - String commitHash, int cloneDepth, LineConsumer infoLogger, LineConsumer errorLogger) {
     572 + String commitHash, boolean withLfs, boolean withSubmodules, int cloneDepth,
     573 + LineConsumer infoLogger, LineConsumer errorLogger) {
    580 574   git.clearArgs();
    581 575   if (!new File(git.workingDir(), ".git").exists()) {
    582 576   git.addArgs("init", ".");
    skipped 23 lines
    606 600   git.addArgs(commitHash);
    607 601   git.execute(infoLogger, errorLogger).checkReturnCode();
    608 602   
    609  - checkoutRepository(git, commitHash, infoLogger, errorLogger);
    610  -
    611 603   AtomicBoolean originExists = new AtomicBoolean(false);
    612 604   git.clearArgs();
    613 605   git.addArgs("remote", "add", "origin", remoteUrl);
    skipped 11 lines
    625 617   if (!originExists.get())
    626 618   result.checkReturnCode();
    627 619  
    628  - if (new File(git.workingDir(), ".gitmodules").exists()) {
     620 + if (withLfs) {
     621 + if (SystemUtils.IS_OS_MAC_OSX) {
     622 + String path = System.getenv("PATH") + ":/usr/local/bin";
     623 + git.environments().put("PATH", path);
     624 + }
     625 +
     626 + git.clearArgs();
     627 + git.addArgs("lfs", "install");
     628 + git.execute(infoLogger, errorLogger).checkReturnCode();
     629 + }
     630 +
     631 + git.clearArgs();
     632 + git.addArgs("checkout", "--quiet", commitHash);
     633 + git.execute(infoLogger, errorLogger).checkReturnCode();
     634 +
     635 + if (withSubmodules && new File(git.workingDir(), ".gitmodules").exists()) {
    629 636   // deinit submodules in case submodule url is changed
    630 637   git.clearArgs();
    631 638   git.addArgs("submodule", "deinit", "--all", "--force", "--quiet");
    skipped 42 lines
    674 681   return SerializationUtils.deserialize(jobDataBytes);
    675 682   }
    676 683  
     684 + public static void testGitLfsAvailability(Commandline git, TaskLogger jobLogger) {
     685 + File userHome = FileUtils.createTempDir("user");
     686 + try {
     687 + jobLogger.log("Checking if git-lfs exists...");
     688 + git.clearArgs();
     689 + git.environments().put("HOME", userHome.getAbsolutePath());
     690 + if (SystemUtils.IS_OS_MAC_OSX) {
     691 + String path = System.getenv("PATH") + ":/usr/local/bin";
     692 + git.environments().put("PATH", path);
     693 + }
     694 +
     695 + git.addArgs("lfs", "version");
     696 + 
     697 + AtomicBoolean lfsExists = new AtomicBoolean(true);
     698 + ExecutionResult result = git.execute(new LineConsumer() {
     699 + 
     700 + @Override
     701 + public void consume(String line) {
     702 + }
     703 +
     704 + }, new LineConsumer() {
     705 + 
     706 + @Override
     707 + public void consume(String line) {
     708 + if (line.startsWith("git: 'lfs' is not a git command"))
     709 + lfsExists.set(false);
     710 + if (lfsExists.get())
     711 + jobLogger.error(line);
     712 + }
     713 +
     714 + });
     715 + if (lfsExists.get()) {
     716 + result.checkReturnCode();
     717 + jobLogger.log("git-lfs found");
     718 + } else {
     719 + jobLogger.warning("WARNING: Executable 'git-lfs' not found. You will not be able to retrieve LFS files");
     720 + }
     721 + } finally {
     722 + FileUtils.deleteDir(userHome, 3);
     723 + }
     724 + }
     725 + 
    677 726   public static void sidecar(String serverUrl, String jobToken, boolean test) {
    678 727   LeafHandler commandHandler = new LeafHandler() {
    679 728   
    skipped 139 lines
    819 868   }
    820 869  
    821 870   public static void checkoutCode(String serverUrl, String jobToken, String positionStr,
    822  - int cloneDepth, CloneInfo cloneInfo) throws IOException {
     871 + boolean withLfs, boolean withSubmodules, int cloneDepth, CloneInfo cloneInfo) throws IOException {
    823 872   JobData jobData = readJobData();
    824 873  
    825 874   logger.info("Checking out code from {}...", cloneInfo.getCloneUrl());
    skipped 33 lines
    859 908   }
    860 909  
    861 910   cloneRepository(git, cloneInfo.getCloneUrl(), cloneInfo.getCloneUrl(),
    862  - jobData.getCommitHash(), cloneDepth, infoLogger, errorLogger);
     911 + jobData.getCommitHash(), withLfs, withSubmodules, cloneDepth,
     912 + infoLogger, errorLogger);
    863 913   }
    864 914  
    865 915   public static void runServerStep(String serverUrl, String jobToken, String positionStr,
    skipped 172 lines
Please wait...
Page is in error, reload to recover