You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.1 KiB

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