Skip to content

Commit

Permalink
Introduce --buildpack flag
Browse files Browse the repository at this point in the history
[#25]

Signed-off-by: Jacques Chester <[email protected]>
  • Loading branch information
ekcasey authored and jchesterpivotal committed Oct 4, 2018
1 parent 5edff37 commit 06510a9
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 17 deletions.
73 changes: 73 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,79 @@ func testPack(t *testing.T, when spec.G, it spec.S) {
})
}, spec.Parallel(), spec.Report(report.Terminal{}))

when("a custom group is specified by providing multiple '--buildpack' params", func() {
javaBpId := "io.buildpacks.samples.java"
it.Before(func() {
var err error
sourceCodePath, err = ioutil.TempDir("", "pack.build.maven_app.")
if err != nil {
t.Fatal(err)
}
exec.Command("cp", "-r", "testdata/maven_app/.", sourceCodePath).Run()
})

it("builds and exports an image", func() {
cmd := exec.Command(pack, "build", repoName, "--buildpack", javaBpId, "-p", sourceCodePath)
cmd.Env = append(os.Environ(), "HOME="+homeDir)
buildOutput := run(t, cmd)

t.Log(buildOutput)
assertEq(t, strings.Contains(buildOutput, "DETECTING WITH MANUALLY-PROVIDED GROUP:"), true)
if strings.Contains(buildOutput, "Node.js Buildpack") {
t.Fatalf("should have skipped Node.js buildpack because --buildpack flag was provided")
}
assertEq(t, strings.Contains(buildOutput, "Sample Java Buildpack: pass"), true)

run(t, exec.Command("docker", "run", "--name="+containerName, "--rm=true", "-d", "-e", "PORT=8080", "-p", ":8080", repoName))
launchPort := fetchHostPort(t, containerName)

time.Sleep(2 * time.Second)
assertEq(t, fetch(t, "http://localhost:"+launchPort), "Maven buildpack worked!")
})
})

when("a custom group is specified by providing multiple '--buildpack' params", func() {
var (
builderRepoName string
builderTOML string
)
it.Before(func() {
builderRepoName = "some-org/" + randString(10)
builderTOML = filepath.Join("testdata", "mock_buildpacks", "builder.toml")
})

it.After(func() {
docker.Kill(containerName)
docker.RemoveImage(builderRepoName)
})

it("builds and exports an image", func() {
t.Log("create builder image")
cmd := exec.Command(pack, "create-builder", builderRepoName, "-b", builderTOML)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("create-builder command failed: %s: %s", output, err)
}

//cmd := exec.Command(pack, "build", repoName, "--buildpack", javaBpId, "-p", sourceCodePath)
//cmd.Env = append(os.Environ(), "HOME="+homeDir)
//buildOutput := run(t, cmd)
//
//t.Log(buildOutput)
//assertEq(t, strings.Contains(buildOutput, "DETECTING WITH MANUALLY-PROVIDED GROUP:"), true)
//if strings.Contains(buildOutput, "Node.js Buildpack") {
// t.Fatalf("should have skipped Node.js buildpack because --buildpack flag was provided")
//}
//assertEq(t, strings.Contains(buildOutput, "Sample Java Buildpack: pass"), true)
//
//run(t, exec.Command("docker", "run", "--name="+containerName, "--rm=true", "-d", "-e", "PORT=8080", "-p", ":8080", repoName))
//launchPort := fetchHostPort(t, containerName)
//
//time.Sleep(2 * time.Second)
//assertEq(t, fetch(t, "http://localhost:"+launchPort), "Maven buildpack worked!")
})
})

when("'--publish' flag is specified", func() {
it("builds and exports an image", func() {
runPackBuild := func() string {
Expand Down
10 changes: 10 additions & 0 deletions acceptance/testdata/maven_app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
51 changes: 51 additions & 0 deletions acceptance/testdata/maven_app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<modelVersion>4.0.0</modelVersion>
<groupId>pack.buildpacks.io</groupId>
<artifactId>testdata-sample-app</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.nanohttpd</groupId>
<artifactId>nanohttpd</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>

<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>io.buildpacks.pack.testdata.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.buildpacks.pack.testdata;

import java.io.IOException;
import java.util.Map;
import fi.iki.elonen.NanoHTTPD;

public class App extends NanoHTTPD {
public App() throws IOException {
super(8080);
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
System.out.println("\nRunning at http://localhost:8080/ \n");
}

public static void main(String[] args) {
try {
new App();
} catch (IOException ioe) {
System.err.println("Couldn't start server:\n" + ioe);
}
}

@Override
public Response serve(IHTTPSession session) {
return newFixedLengthResponse("Maven buildpack worked!");
}
}
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions acceptance/testdata/mock_app/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

echo Here are the deps:

cat *-dep

echo "I hope they're what you wanted"
14 changes: 14 additions & 0 deletions acceptance/testdata/mock_buildpacks/builder.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[buildpacks]]
id = "mock.bp.first"
uri = "file://first"

[[buildpacks]]
id = "mock.bp.second"
uri = "file://second"

[[buildpacks]]
id = "mock.bp.third"
uri = "file://third"

[[groups]]
buildpacks = [{ id = "mock.bp.first", version = "1.2.3" }]
17 changes: 17 additions & 0 deletions acceptance/testdata/mock_buildpacks/first/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

echo "---> First mock buildpack"

set -o errexit
set -o nounset
set -o pipefail

launch_dir=$3

mkdir "$launch_dir/first-layer"
echo "First Dep Contents" > "$launch_dir/first-layer/first-dep"
ln -snf "$launch_dir/first-layer/first-dep" first-dep

echo 'processes = [{ type = "web", command = "run"}]' > "$launch_dir/launch.toml"

echo "---> Done"
10 changes: 10 additions & 0 deletions acceptance/testdata/mock_buildpacks/first/bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail


if [[ ! -f detect_first ]]; then
exit 100
fi
7 changes: 7 additions & 0 deletions acceptance/testdata/mock_buildpacks/first/buildpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[buildpack]
id = "mock.bp.first"
version = "0.0.1-mock"
name = "First Mock Buildpack"

[[stacks]]
id = "io.buildpacks.stacks.bionic"
16 changes: 16 additions & 0 deletions acceptance/testdata/mock_buildpacks/second/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
echo "---> Second mock buildpack"

set -o errexit
set -o nounset
set -o pipefail

launch_dir=$3

mkdir "$launch_dir/second-layer"
echo "Second Dep Contents" > "$launch_dir/second-layer/second-dep"
ln -snf "$launch_dir/second-layer/second-dep" second-dep

echo 'processes = [{ type = "web", command = "run"}]' > "$launch_dir/launch.toml"

echo "---> Done"
9 changes: 9 additions & 0 deletions acceptance/testdata/mock_buildpacks/second/bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

if [[ ! -f detect_second ]]; then
exit 100
fi
7 changes: 7 additions & 0 deletions acceptance/testdata/mock_buildpacks/second/buildpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[buildpack]
id = "mock.bp.second"
version = "0.0.1-mock"
name = "Second Mock Buildpack"

[[stacks]]
id = "io.buildpacks.stacks.bionic"
16 changes: 16 additions & 0 deletions acceptance/testdata/mock_buildpacks/third/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
echo "---> Third mock buildpack"

set -o errexit
set -o nounset
set -o pipefail

launch_dir=$3

mkdir "$launch_dir/third-layer"
echo "Third Dep Contents" > "$launch_dir/third-layer/third-dep"
ln -snf "$launch_dir/third-layer/third-dep" third-dep

echo 'processes = [{ type = "web", command = "run"}]' > "$launch_dir/launch.toml"

echo "---> Done"
9 changes: 9 additions & 0 deletions acceptance/testdata/mock_buildpacks/third/bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

if [[ ! -f detect_third ]]; then
exit 100
fi
7 changes: 7 additions & 0 deletions acceptance/testdata/mock_buildpacks/third/buildpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[buildpack]
id = "mock.bp.third"
version = "0.0.1-mock"
name = "Third Mock Buildpack"

[[stacks]]
id = "io.buildpacks.stacks.bionic"
Loading

0 comments on commit 06510a9

Please sign in to comment.