summaryrefslogtreecommitdiff
path: root/lib/spack/spack/container/writers/docker.py
blob: 557d22c803960d108069af47a2b4749366d4b57e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import spack.tengine as tengine

from . import writer, PathContext


@writer('docker')
class DockerContext(PathContext):
    """Context used to instantiate a Dockerfile"""
    #: Name of the template used for Dockerfiles
    template_name = 'container/Dockerfile'

    @tengine.context_property
    def manifest(self):
        manifest_str = super(DockerContext, self).manifest
        # Docker doesn't support HEREDOC so we need to resort to
        # a horrible echo trick to have the manifest in the Dockerfile
        echoed_lines = []
        for idx, line in enumerate(manifest_str.split('\n')):
            if idx == 0:
                echoed_lines.append('&&  (echo "' + line + '" \\')
                continue
            echoed_lines.append('&&   echo "' + line + '" \\')

        echoed_lines[-1] = echoed_lines[-1].replace(' \\', ')')

        return '\n'.join(echoed_lines)