Light, fluffy, and always free - The AWS Local Emulator alternative
fix(codebuild): create build working directory before running phases (#1577)
Alex Bannabd75d4428f7b
diff --git a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.java b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.javaindex f7a94cd3dd..e75072ffdc 100644--- a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.java+++ b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.java@@ -190,12 +190,10 @@ public class CodeBuildRunner {List<String> envList = buildEnvList(region, build, project, buildspec, logStream);- // Create the working directory inside the container as part of startup,- // then keep the container alive. No bind mount needed — source and- // artifacts are transferred with docker cp.+ // Keep the container alive so each phase can be run with docker exec.+ // No bind mount needed — source and artifacts are transferred with docker cp.ContainerSpec spec = containerBuilder.newContainer(image)- .withCmd(List.of("sh", "-c",- "mkdir -p /codebuild/output/src/src && tail -f /dev/null"))+ .withCmd(List.of("sh", "-c", "tail -f /dev/null")).withEnv(envList).withDockerNetwork(config.services().codebuild().dockerNetwork()).withEmbeddedDns()@@ -210,13 +208,26 @@ public class CodeBuildRunner {logHandle = logStreamer.attach(containerId, logGroup, logStream, region, "codebuild:" + buildId);- // Copy downloaded source files into the container (no-op for NO_SOURCE builds)- copySourceToContainer(containerId, workspace, "/codebuild/output/src/src");-String containerSrcDir = "/codebuild/output/src/src";int timeoutMinutes = build.getTimeoutInMinutes() != null ? build.getTimeoutInMinutes() : 60;boolean buildFailed = false;+ // createAndStart returns as soon as the container's entrypoint process is+ // running, which can be before any startup command would finish. Create the+ // working directory with an explicit, awaited exec (run from "/", which always+ // exists) so the source copy, the phase execs that chdir into it, and the final+ // artifact copy can never race against container startup.+ PhaseResult workDirResult = runPhase(containerId, "/", envList,+ List.of("mkdir -p " + containerSrcDir), timeoutMinutes, stopFlag);+ if (workDirResult.stopped()) { finishStopped(build); return; }+ if (workDirResult.failed()) {+ throw new IllegalStateException("Could not create build working directory "+ + containerSrcDir + ": " + workDirResult.errorMessage());+ }++ // Copy downloaded source files into the container (no-op for NO_SOURCE builds)+ copySourceToContainer(containerId, workspace, containerSrcDir);+// INSTALLif (stopFlag.get()) { finishStopped(build); return; }beginPhase(build, "INSTALL");