Skip to content

Commit

Permalink
Fix #79 about build_images.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
fchauvel committed Sep 30, 2019
1 parent 19c0de7 commit 47dce20
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
10 changes: 6 additions & 4 deletions camp/entities/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,14 @@ class Configuration(Visitee):


def __init__(self, model, instances=None):
self._instances = {each.name:each for each in instances} \
if instances else {}
self._instances = [each for each in instances]


def resolve(self, identifier):
return self._instances[identifier]
for any_instance in self._instances:
if any_instance.name == identifier:
return any_instance
raise KeyError("Unknown instance '{}'!".format(identifier))


@property
Expand All @@ -645,7 +647,7 @@ def instance_count(self):

@property
def instances(self):
return [ each for each in self._instances.values() ]
return self._instances


@property
Expand Down
6 changes: 5 additions & 1 deletion camp/realize.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ def _record_dependency_of(self, instance):
if instance.feature_provider in self._images:
index = self._images.index(instance.feature_provider)
self._images.insert(index+1, instance)
elif instance in self._images:
index = self._images.index(instance)
self._images.insert(index, instance.feature_provider)
else:
self._images.append(instance.feature_provider)
self._images.append(instance)
Expand All @@ -331,7 +334,7 @@ def _generate_build_script(self):
stream.write(content)


BUILD_COMMAND = "docker build -t {tag} {folder}"
BUILD_COMMAND = "docker build --no-cache -t {tag} {folder}"

def _build_script(self):
return join_paths(self._image_directory, "build_images.sh")
Expand All @@ -343,5 +346,6 @@ def _build_script(self):
"#\n"
"# Build all images and set the appropriate tags\n"
"#\n"
"set -e\n"
"{0}\n"
"echo 'All images ready.'\n")
13 changes: 13 additions & 0 deletions docs/pages/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ changes that were made.

* CAMP v0.6

* CAMP v0.6.3 (Sep. 30, 2019)

* Fix [Issue
79](https://github.com/STAMP-project/camp/issues/79) about
invalid build script generated by CAMP realize when
software stacks include more than two components. Force also
scripts to stop on first error.

* Fix [Issue
78](https://github.com/STAMP-project/camp/issues/78) about
CAMP replacing FROM statements all round multistage
Dockerfile.

* CAMP v0.6.2 (Sep. 26, 2019)

* Fix [Issue
Expand Down
30 changes: 23 additions & 7 deletions tests/realize/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def setUp(self):
"FROM camp/runtime\n"
"COPY --from=builder /build/a.out /a.out\n"))

self._input.create_template_file("tomcat",
"Dockerfile",
("FROM camp/runtime\n"
"RUN echo this is nice\n"))

self._input.create_template_file("jdk",
"Dockerfile",
("FROM openjdk:8-jre\n"
Expand Down Expand Up @@ -82,13 +87,17 @@ def assert_no_image_generated(self, config_index):
class BuildImagesIsGenerated(BuilderTest):


def test_when_a_component_is_implemented_by_a_docker_file(self):
def test_when_the_stack_has_more_than_two_components(self):
model = Model(
[
Component("server",
provided_services=[Service("Awesome")],
required_features=[Feature("JDK")],
required_features=[Feature("ServletContainer")],
implementation=DockerFile("server/Dockerfile")),
Component("tomcat",
provided_features=[Feature("ServletContainer")],
required_features=[Feature("JDK")],
implementation=DockerFile("tomcat/Dockerfile")),
Component("jdk",
provided_features=[Feature("JDK")],
implementation=DockerFile("jdk/Dockerfile"))
Expand All @@ -98,19 +107,26 @@ def test_when_a_component_is_implemented_by_a_docker_file(self):
)

server_0 = Instance("server_0", model.resolve("server"))
tomcat_0 = Instance("tomcat_0", model.resolve("tomcat"))
jdk_0 = Instance("jdk_0", model.resolve("jdk"))

server_0.feature_provider = jdk_0
configuration = Configuration(model, [server_0, jdk_0])
server_0.feature_provider = tomcat_0
tomcat_0.feature_provider = jdk_0
configuration = Configuration(model, [server_0, tomcat_0, jdk_0])

self.build(configuration)

expected_command_order = (
"docker build --no-cache -t camp-jdk_0 ./jdk_0\n"
"docker build --no-cache -t camp-tomcat_0 ./tomcat_0\n"
"docker build --no-cache -t camp-server_0 ./server_0\n"
)

self.assert_generated(
"config_0/images/build_images.sh",
with_patterns=[
"docker build -t camp-server_0 ./server",
"docker build -t camp-jdk_0 ./jdk_0"
])
expected_command_order
])



Expand Down

0 comments on commit 47dce20

Please sign in to comment.