all repos — NoPaste @ 3e3c433f026c49e04d0efa0f0f39fc688ed32bb1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/dockerfile/test.js (view raw)

  1// CodeMirror, copyright (c) by Marijn Haverbeke and others
  2// Distributed under an MIT license: https://codemirror.net/LICENSE
  3
  4(function() {
  5  var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-dockerfile");
  6  function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  7
  8  MT("simple_nodejs_dockerfile",
  9     "[keyword FROM] node:carbon",
 10     "[comment # Create app directory]",
 11     "[keyword WORKDIR] /usr/src/app",
 12     "[comment # Install app dependencies]",
 13     "[comment # A wildcard is used to ensure both package.json AND package-lock.json are copied]",
 14     "[comment # where available (npm@5+)]",
 15     "[keyword COPY] package*.json ./",
 16     "[keyword RUN] npm install",
 17     "[keyword COPY] . .",
 18     "[keyword EXPOSE] [number 8080] [number 3000]",
 19     "[keyword ENV] NODE_ENV development",
 20     "[keyword CMD] [[ [string \"npm\"], [string \"start\"] ]]");
 21
 22  // Ideally the last space should not be highlighted.
 23  MT("instruction_without_args_1",
 24     "[keyword CMD] ");
 25
 26  MT("instruction_without_args_2",
 27     "[comment # An instruction without args...]",
 28     "[keyword ARG] [error #...is an error]");
 29
 30  MT("multiline",
 31     "[keyword RUN] apt-get update && apt-get install -y \\",
 32     "  mercurial \\",
 33     "  subversion \\",
 34     "  && apt-get clean \\",
 35     "  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*");
 36
 37  MT("from_comment",
 38     "  [keyword FROM] debian:stretch # I tend to use stable as that is more stable",
 39     "  [keyword FROM] debian:stretch [keyword AS] stable # I am even more stable",
 40     " [keyword FROM] [error # this is an error]");
 41
 42  MT("from_as",
 43     "[keyword FROM] golang:1.9.2-alpine3.6 [keyword AS] build",
 44     "[keyword COPY] --from=build /bin/project /bin/project",
 45     "[keyword ENTRYPOINT] [[ [string \"/bin/project\"] ]]",
 46     "[keyword CMD] [[ [string \"--help\"] ]]");
 47
 48  MT("arg",
 49     "[keyword ARG] VERSION=latest",
 50     "[keyword FROM] busybox:$VERSION",
 51     "[keyword ARG] VERSION",
 52     "[keyword RUN] echo $VERSION > image_version");
 53
 54  MT("label",
 55     "[keyword LABEL] com.example.label-with-value=[string \"foo\"]");
 56
 57  MT("label_multiline",
 58     "[keyword LABEL] description=[string \"This text illustrates ]\\",
 59     "[string that label-values can span multiple lines.\"]");
 60
 61  MT("maintainer",
 62     "[keyword MAINTAINER] Foo Bar [string \"foo@bar.com\"] ",
 63     "[keyword MAINTAINER] Bar Baz <bar@baz.com>");
 64
 65  MT("env",
 66     "[keyword ENV] BUNDLE_PATH=[string \"$GEM_HOME\"] \\",
 67     "  BUNDLE_APP_CONFIG=[string \"$GEM_HOME\"]");
 68
 69  MT("verify_keyword",
 70     "[keyword RUN] add-apt-repository ppa:chris-lea/node.js");
 71
 72  MT("scripts",
 73     "[comment # Set an entrypoint, to automatically install node modules]",
 74     "[keyword ENTRYPOINT] [[ [string \"/bin/bash\"], [string \"-c\"], [string \"if [[ ! -d node_modules ]]; then npm install; fi; exec \\\"${@:0}\\\";\"] ]]",
 75     "[keyword CMD] npm start",
 76     "[keyword RUN] npm run build && \\",
 77     "[comment # a comment between the shell commands]",
 78     "  npm run test");
 79
 80  MT("strings_single",
 81     "[keyword FROM] buildpack-deps:stretch",
 82     "[keyword RUN] { \\",
 83     "        echo [string 'install: --no-document']; \\",
 84     "        echo [string 'update: --no-document']; \\",
 85     "    } >> /usr/local/etc/gemrc");
 86
 87  MT("strings_single_multiline",
 88     "[keyword RUN] set -ex \\",
 89     "    \\",
 90     "    && buildDeps=[string ' ]\\",
 91     "[string        bison ]\\",
 92     "[string        dpkg-dev ]\\",
 93     "[string        libgdbm-dev ]\\",
 94     "[string        ruby ]\\",
 95     "[string    '] \\",
 96     "    && apt-get update");
 97
 98  MT("strings_single_multiline_2",
 99     "[keyword RUN] echo [string 'say \\' ]\\",
100     "[string   it works'] ");
101
102  MT("strings_double",
103     "[keyword RUN] apt-get install -y --no-install-recommends $buildDeps \\",
104     " \\",
105     " && wget -O ruby.tar.xz [string \"https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.xz\"] \\",
106     " && echo [string \"$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz\"] | sha256sum -c - ");
107
108  MT("strings_double_multiline",
109     "[keyword RUN] echo [string \"say \\\" ]\\",
110     "[string   it works\"] ");
111
112  MT("escape",
113     "[comment # escape=`]",
114     "[keyword FROM] microsoft/windowsservercore",
115     "[keyword RUN] powershell.exe -Command `",
116     "    $ErrorActionPreference = [string 'Stop']; `",
117     "    wget https://www.python.org/ftp/python/3.5.1/python-3.5.1.exe -OutFile c:\python-3.5.1.exe ; `",
118     "    Start-Process c:\python-3.5.1.exe -ArgumentList [string '/quiet InstallAllUsers=1 PrependPath=1'] -Wait ; `",
119     "    Remove-Item c:\python-3.5.1.exe -Force)");
120
121  MT("escape_strings",
122     "[comment # escape=`]",
123     "[keyword FROM] python:3.6-windowsservercore [keyword AS] python",
124     "[keyword RUN] $env:PATH = [string 'C:\\Python;C:\\Python\\Scripts;{0}'] -f $env:PATH ; `",
125     // It should not consider \' as escaped.
126     // "  Set-ItemProperty -Path [string 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\'] -Name Path -Value $env:PATH ;");
127     "  Set-ItemProperty -Path [string 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\' -Name Path -Value $env:PATH ;]");
128})();