Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ The all-in-one phase that combines all the phases is:
The `configure` phase pushes all the settings in the YAML file to PNC, and the `build` phase tells PNC to build everything.

```bash
bacon pig <phase> -c ...
bacon pig <phase> ...
```
## Configuration

The application is configured via the `build-config.yaml` file. The file path is passed to the application with `-c` option.
The application is configured via the `build-config.yaml` file.

A PiG `build-config.yaml` looks like this: https://github.com/project-ncl/bacon/blob/master/example-pig-config.yaml

Expand All @@ -109,14 +109,14 @@ TODO: add a command that allows users to specify variables via cli

Usage:
```bash
bacon pig configure -c <location of build-config.yaml>
bacon pig configure <directrory containing build-config.yaml>
```

## build

Usage:
```bash
bacon pig configure -c <location of build-config.yaml>
bacon pig configure <directrory containing build-config.yaml>
```

You can specify if you want temporary builds or not with the `-t` flag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.jboss.pnc.bacon.common.cli;

import com.fasterxml.jackson.core.JsonProcessingException;
import ch.qos.logback.classic.Level;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.aesh.command.Command;
import org.aesh.command.CommandException;
Expand All @@ -27,10 +27,10 @@
import org.aesh.command.invocation.CommandInvocation;
import org.aesh.command.option.Option;
import org.aesh.command.shell.Shell;
import org.jboss.pnc.bacon.common.ObjectHelper;
import org.jboss.pnc.bacon.common.Constant;
import org.jboss.pnc.bacon.config.Config;
import org.jboss.pnc.bacon.common.ObjectHelper;
import org.jboss.pnc.bacon.common.exception.FatalException;
import org.jboss.pnc.bacon.config.Config;
import org.jboss.pnc.client.ClientException;

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ public CommandResult executeHelper(CommandInvocation commandInvocation, SubComma
} catch (FatalException e) {
throw e;
} catch (Exception e) {
log.error("Something wrong happened: {}", e.getMessage());
log.error("Something wrong happened: ", e); // TODO rollback to print message only?
log.debug("Stacktrace", e);
throw new FatalException();
// Aesh doesnt take care of exit codes, thrown FatalException will be caught in App class and app will exit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ConfigProfile {
private PncConfig pnc;
private DaConfig da;
private IndyConfig indy;
private PigConfig pig;
private KeycloakConfig keycloak;

private Map<String, Map<String, ?>> addOns;
Expand Down
13 changes: 13 additions & 0 deletions config/src/main/java/org/jboss/pnc/bacon/config/PigConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jboss.pnc.bacon.config;

import lombok.Data;

/**
* @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com 2020-06-05
*/
@Data
public class PigConfig {
private String kojiHubUrl;
private String licenseServiceUrl;
private String indyUrl;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jboss.pnc.bacon.test;

import org.jboss.pnc.bacon.common.Constant;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -12,15 +14,14 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.jboss.pnc.bacon.common.Constant;

/**
*
* @author jbrazdil
*/
public class CLIExecutor {
private static final Path BACON_JAR = Paths.get("../cli/target/bacon.jar").toAbsolutePath().normalize();
public static final String CONFIG_LOCATION = "target/test-config";
public static final Path CONFIG_LOCATION = Paths.get("target", "test-config");

public ExecutionResult runCommand(String... args) {
try {
Expand All @@ -34,7 +35,7 @@ public ExecutionResult runCommand(String... args) {
cmdarray[i + 3] = args[i];
}
String[] env = new String[1];
env[0] = Constant.CONFIG_ENV + "=" + CONFIG_LOCATION;
env[0] = Constant.CONFIG_ENV + "=" + CONFIG_LOCATION.toString();

System.out.println(
"Running command: " + Arrays.stream(cmdarray).collect(Collectors.joining("' '", "'", "'")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
package org.jboss.pnc.bacon.test.pig;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.jboss.pnc.bacon.test.AbstractTest;
import org.jboss.pnc.bacon.test.ExecutionResult;
import org.jboss.pnc.dto.BuildConfiguration;
import org.jboss.pnc.dto.Environment;
import org.jboss.pnc.dto.GroupConfiguration;
import org.jboss.pnc.dto.Product;
import org.jboss.pnc.dto.ProductMilestone;
import org.jboss.pnc.dto.ProductVersion;
import org.jboss.pnc.dto.Project;
import org.jboss.pnc.dto.SCMRepository;
import org.jboss.pnc.dto.response.Page;
import org.jboss.pnc.dto.response.RepositoryCreationResponse;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import org.jboss.pnc.bacon.test.AbstractTest;
import static org.jboss.pnc.bacon.test.CLIExecutor.CONFIG_LOCATION;
import static org.jboss.pnc.bacon.test.Endpoints.BUILD_CONFIG;
import static org.jboss.pnc.bacon.test.Endpoints.BUILD_CONFIG_DEPENDENCIES;
Expand All @@ -24,22 +40,6 @@
import static org.jboss.pnc.bacon.test.Endpoints.PROJECT;
import static org.jboss.pnc.bacon.test.Endpoints.SCM_REPOSITORY;
import static org.jboss.pnc.bacon.test.Endpoints.SCM_REPOSITORY_CREATE;
import org.jboss.pnc.bacon.test.ExecutionResult;
import org.jboss.pnc.dto.BuildConfiguration;
import org.jboss.pnc.dto.Environment;
import org.jboss.pnc.dto.GroupConfiguration;
import org.jboss.pnc.dto.Product;
import org.jboss.pnc.dto.ProductMilestone;
import org.jboss.pnc.dto.ProductVersion;
import org.jboss.pnc.dto.Project;
import org.jboss.pnc.dto.SCMRepository;
import org.jboss.pnc.dto.response.Page;
import org.jboss.pnc.dto.response.RepositoryCreationResponse;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;

/**
*
Expand All @@ -64,9 +64,9 @@ public class PigTest extends AbstractTest {

@Test
@Order(1)
public void shouldCreateProduct() throws JsonProcessingException, IOException {
final String configFile = CONFIG_LOCATION + "/pig.yaml";
replaceSuffixInConfigFile(configFile);
public void shouldCreateProduct() throws IOException {
final Path configFile = CONFIG_LOCATION;
replaceSuffixInConfigFile(configFile.resolve("build-config.yaml"));

final Product product = Product.builder()
.id(UNIVERSAL_ID)
Expand Down Expand Up @@ -139,12 +139,11 @@ public void shouldCreateProduct() throws JsonProcessingException, IOException {
.post(GROUP_CONFIG_BUILD_CONFIGS.apply(UNIVERSAL_ID))
.then()
.getEntity(GROUP_CONFIG, groupConfigWithBuildConfig);
ExecutionResult output = executeAndGetResult("pig", "configure", "-c", configFile);
ExecutionResult output = executeAndGetResult("pig", "configure", configFile.toString());
assertThat(output.getOutput()).contains("name: \"Product Foobar " + SUFFIX + "\"");
}

private void replaceSuffixInConfigFile(String configFile) throws IOException {
final Path configPath = Paths.get(configFile);
private void replaceSuffixInConfigFile(Path configPath) throws IOException {
List<String> fileContent = Files.lines(configPath)
.map(l -> l.contains("#!suffix=") ? "#!suffix=" + SUFFIX : l)
.collect(Collectors.toList());
Expand Down
Loading