@Test public void should_run_cmd_from_ci_yml() { ShellCommands commands = getRunCommands(); Assert.assertEquals( "docker-compose -f docker-compose.yml -p unitgroupondotci8 run -T unit sh -xc 'command'", commands.get(2)); }
@Test public void should_cleanup_after_test_run() { ShellCommands commands = getRunCommands(); Assert.assertEquals( "trap \"docker-compose -f docker-compose.yml -p unitgroupondotci8 kill; docker-compose -f docker-compose.yml -p unitgroupondotci8 rm -v --force; exit\" PIPE QUIT INT HUP EXIT TERM", commands.get(0)); }
@Test public void should_pull_latest_image_from_registry() { ShellCommands commands = getRunCommands(); Assert.assertEquals( "docker-compose -f docker-compose.yml -p unitgroupondotci8 pull", commands.get(1)); }
public ShellCommands getCheckoutCommands(Map<String, Object> dotCiEnvVars) { GitUrl gitRepoUrl = new GitUrl((String) dotCiEnvVars.get("GIT_URL")); boolean isPrivateRepo = Boolean.parseBoolean((String) dotCiEnvVars.get("DOTCI_IS_PRIVATE_REPO")); String gitUrl = gitRepoUrl.getGitUrl(); ShellCommands shellCommands = new ShellCommands(); shellCommands.add("chmod -R u+w . ; find . ! -path \"./deploykey_rsa.pub\" ! -path \"./deploykey_rsa\" -delete"); shellCommands.add("git init"); shellCommands.add(format("git remote add origin %s",gitUrl)); if(dotCiEnvVars.get("DOTCI_PULL_REQUEST") != null){ if(isPrivateRepo){ shellCommands.add(format("ssh-agent bash -c \"ssh-add -D && ssh-add \\%s/deploykey_rsa && git fetch origin '+refs/pull/%s/merge:' \"",dotCiEnvVars.get("WORKSPACE"), dotCiEnvVars.get("DOTCI_PULL_REQUEST"))); }else { shellCommands.add(format("git fetch origin \"+refs/pull/%s/merge:\"", dotCiEnvVars.get("DOTCI_PULL_REQUEST"))); } shellCommands.add("git reset --hard FETCH_HEAD"); }else { if(isPrivateRepo){ shellCommands.add(format("ssh-agent bash -c \"ssh-add -D && ssh-add \\%s/deploykey_rsa && git fetch origin %s \"",dotCiEnvVars.get("WORKSPACE"), dotCiEnvVars.get("DOTCI_BRANCH"))); }else{ shellCommands.add(format("git fetch origin %s",dotCiEnvVars.get("DOTCI_BRANCH"))); } shellCommands.add(format("git reset --hard %s", dotCiEnvVars.get("SHA"))); shellCommands.add("( for dockerfile in $(find . -name '*Dockerfile*'); do dockerfileName=$(basename $dockerfile) ; dockerfilePath=$(dirname $dockerfile); pushd $dockerfilePath >/dev/null ; for filename in $(grep ADD $dockerfileName | sed -e 's/^\\s*ADD\\s*//g' ; grep COPY $dockerfileName | sed -e 's/^\\s*COPY\\s*//g' ); do test -d $filename && continue ; test -f $filename || continue ; sha=$(git rev-list -n 1 HEAD $filename) ; touch -d \"$(git show -s --format=%ai $sha)\" $filename ; popd >/dev/null ; done ; done ) || true # Set modified time of files added in Dockerfiles to allow for build caching"); } return shellCommands; }