private ArchiverCustomizer getS2ICustomizer(ImageConfiguration imageConfiguration) throws Fabric8ServiceException { try { if (imageConfiguration.getBuildConfiguration() != null && imageConfiguration.getBuildConfiguration().getEnv() != null) { String fileName = IoUtil.sanitizeFileName("s2i-env-" + imageConfiguration.getName()); final File environmentFile = new File(config.getBuildDirectory(), fileName); try (PrintWriter out = new PrintWriter(new FileWriter(environmentFile))) { for (Map.Entry<String, String> e : imageConfiguration.getBuildConfiguration().getEnv().entrySet()) { out.println(e.getKey() + "=" + e.getValue()); } } return new ArchiverCustomizer() { @Override public TarArchiver customize(TarArchiver tarArchiver) throws IOException { tarArchiver.addFile(environmentFile, ".s2i/environment"); return tarArchiver; } }; } else { return null; } } catch (IOException e) { throw new Fabric8ServiceException("Unable to add environment variables to the S2I build archive", e); } }