test.js 5.3 KB

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