
    H                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SrSrSrSrSrSSSSSSS.rSSS/0r\R:                  " S5      r\R:                  " S5      r\R:                  " S5      r \R:                  " S5      r!\R:                  " S RE                  \\5      5      r#\R:                  " S!5      r$\R:                  " S"5      r%\R:                  " S#5      r&\R:                  " S$5      r'S%r(S&r)S'r*S(r+ " S) S*\RX                  5      r- " S+ S,\-5      r. " S- S.\-5      r/ " S/ S0\
R`                  5      r1S1 r2S2 r3S3 r4S4 r5S5 r6S6 r7S7 r8S8 r9S9 r:S: r;S<S; jr<g)=z)Fingerprinting code for the Ruby runtime.    )absolute_import)division)unicode_literalsN)ext_runtime)ext_runtime_adapter)config)
exceptions)log)
console_io)filesRuby)rubycustomz2.3.0z1.11.2z0.78.0z
1.8.6-p420z
1.8.7-p375z
1.9.1-p430z
1.9.2-p330z
1.9.3-p551z
2.0.0-p648)z1.8.6z1.8.7z1.9.1z1.9.2z1.9.3z2.0.0rgeozlibgeos-devzlibproj-devzF    env: flex
    runtime: {runtime}
    entrypoint: {entrypoint}
    z?    .dockerignore
    Dockerfile
    .git
    .hg
    .svn
    a      # This Dockerfile for a Ruby application was generated by gcloud.

    # The base Dockerfile installs:
    # * A number of packages needed by the Ruby runtime and by gems
    #   commonly used in Ruby web apps (such as libsqlite3)
    # * A recent version of NodeJS
    # * A recent version of the standard Ruby runtime to use by default
    # * The bundler and foreman gems
    FROM gcr.io/google_appengine/ruby
    a%      # This Dockerfile uses the default Ruby interpreter installed and
    # specified by the base image.
    # If you want to use a specific ruby interpreter, provide a
    # .ruby-version file, then delete this Dockerfile and re-run
    # "gcloud app gen-config --custom" to recreate it.
    an      # Install ruby {{0}} if not already preinstalled by the base image
    RUN cd /rbenv/plugins/ruby-build && \
        git pull && \
        rbenv install -s {{0}} && \
        rbenv global {{0}} && \
        gem install -q --no-rdoc --no-ri bundler --version {0} && \
        gem install -q --no-rdoc --no-ri foreman --version {1}
    ENV RBENV_VERSION {{0}}
    a       # Install additional package dependencies needed by installed gems.
    # Feel free to add any more needed by your gems.
    RUN apt-get update -y && \
        apt-get install -y -q --no-install-recommends \
            {0} \
        && apt-get clean && rm /var/lib/apt/lists/*_*
    z    # To install additional packages needed by your gems, uncomment
    # the "RUN apt-get update" and "RUN apt-get install" lines below
    # and specify your packages.
    # RUN apt-get update
    # RUN apt-get install -y -q (your packages here)
    zy    # Install required gems.
    COPY Gemfile Gemfile.lock /app/
    RUN bundle install --deployment && rbenv rehash
    zN    # Start application on port 8080.
    COPY . /app/
    ENTRYPOINT {0}
    zforeman start web -p 8080z&bundle exec puma -p 8080 -e deploymentz)bundle exec unicorn -p 8080 -E deploymentz2bundle exec rackup -p 8080 -E deployment config.ruc                       \ rS rSrSrSrg)RubyConfigError   z,Error during Ruby application configuration. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       /lib/googlecloudsdk/api_lib/app/runtimes/ruby.pyr   r      s    4r   r   c                       \ rS rSrSrSrg)MissingGemfileError   zGemfile is missing.r   Nr   r   r   r   r   r      s    r   r   c                       \ rS rSrSrSrg)StaleBundleError   z+Bundle is stale and needs a bundle install.r   Nr   r   r   r   r"   r"      s    3r   r"   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)RubyConfigurator   z'Generates configuration for a Ruby app.c                     Xl         X l        X0l        X@l        XPl        UR
                  (       a  [        R                  U l        g[        R                  R                  U l        g)a0  Constructor.

Args:
  path: (str) Root path of the source tree.
  params: (ext_runtime.Params) Parameters passed through to the
    fingerprinters.
  ruby_version: (str) The ruby interpreter in rbenv format
  entrypoint: (str) The entrypoint command
  packages: ([str, ...]) A set of packages to install
N)rootparamsruby_version
entrypointpackagesdeployr
   infonotifystatusPrint)selfpathr)   r*   r+   r,   s         r   __init__RubyConfigurator.__init__   sC     IK$ OM }}HHdkJJ$$dkr   c                 0   / nU R                   R                  (       d  UR                  U R                  5       5        U R                   R                  (       d  U R                   R
                  (       a>  UR                  U R                  5       5        UR                  U R                  5       5        U Vs/ s H)  nUR                  U R                  U R                  5      PM+     nn[        U5      (       d  U R                  S5        [        U5      $ s  snf )zZGenerates all config files for the module.

Returns:
  (bool) True if files were written.
z3All config files already exist. No files generated.)r)   appinfoappend_GenerateAppYamlr   r-   _GenerateDockerfile_GenerateDockerignoreWriteTor(   r/   any)r2   all_config_filesconfig_filecreateds       r   GenerateConfigs RubyConfigurator.GenerateConfigs   s     ;;d3356{{T[[//d6689d88:; #34"2; ""499dkk:"2  4w<<
kkGHw<4s   50Dc           	      p   U R                   R                  (       d6  U R                  5       nUR                  U R                  U R
                  5        / nU R                   R                  (       d  U R                   R                  (       a>  UR                  U R                  5       5        UR                  U R                  5       5        U Vs/ s H]  n[        R                  R                  [        R                  R                  U R                  UR                  5      5      (       a  M[  UPM_     sn$ s  snf )zpGenerates all config files for the module.

Returns:
  list(ext_runtime.GeneratedFile):
    The generated files
)r)   r7   r9   r<   r(   r/   r   r-   r8   r:   r;   osr3   existsjoinfilename)r2   app_yamlr>   fs       r   GenerateConfigData#RubyConfigurator.GenerateConfigData   s     ;;&&(htyy$++.{{T[[//d6689d88:;' H'!77>>"'',,tyy!**"EF ' H H Hs   AD3*D3c                    [         R                  R                  U R                  S5      nU R                  R
                  (       a  SOSn[        R                  UU R                  S9n[        R                  " SU5      nU$ )zGenerates an app.yaml file appropriate to this application.

Returns:
  (ext_runtime.GeneratedFile) A file wrapper for app.yaml
zapp.yamlr   r   )runtimer+   )rD   r3   rF   r(   r)   r   APP_YAML_CONTENTSformatr+   r   GeneratedFile)r2   rH   rM   app_yaml_contentss       r   r9   !RubyConfigurator._GenerateAppYaml   sg     ww||DIIz2H++,,h&G)00<@OO 1 M((5FGHOr   c                 t   [         /nU R                  (       a/  UR                  [        R	                  U R                  5      5        OUR                  [
        5        U R                  (       a>  UR                  [        R	                  SR                  U R                  5      5      5        OUR                  [        5        UR                  [        5        UR                  [        R	                  U R                  5      5        [        R                  " [        R                   SR                  U5      5      nU$ )zGenerates a Dockerfile appropriate to this application.

Returns:
  (ext_runtime.GeneratedFile) A file wrapper for Dockerignore
 
)DOCKERFILE_HEADERr*   r8   DOCKERFILE_CUSTOM_INTERPRETERrO   DOCKERFILE_DEFAULT_INTERPRETERr,   DOCKERFILE_MORE_PACKAGESrF   DOCKERFILE_NO_MORE_PACKAGESDOCKERFILE_GEM_INSTALLDOCKERFILE_ENTRYPOINTr+   r   rP   r   
DOCKERFILE)r2   dockerfile_content
dockerfiles      r   r:   $RubyConfigurator._GenerateDockerfile   s     ,,
'
.
.t/@/@
AC  >?}}
"
)
)#((4==*A
BD  ;<45$$T__57 **6+<+<+/995G+HJJr   c                     [         R                  R                  U R                  S5      n[        R
                  " S[        5      nU$ )z?Generates a .dockerignore file appropriate to this application.z.dockerignore)rD   r3   rF   r(   r   rP   DOCKERIGNORE_CONTENTS)r2   dockerignores     r   r;   &RubyConfigurator._GenerateDockerignore  s6    77<<		?;L,,_-BDLr   )r+   r/   r,   r)   r(   r*   N)r   r   r   r   r   r4   rA   rJ   r9   r:   r;   r   r   r   r   r%   r%      s$    /%0(H&2r   r%   c                 $   UR                   n[        X5      (       d  g[        U 5      n[        U5      n[	        X5      n[        U5      nU(       a  UR                  (       a  UR                  nO[        X5      n[        X5      n[        XXWU5      $ )a  Check for a Ruby app.

Args:
  path: (str) Application path.
  params: (ext_runtime.Params) Parameters passed through to the
    fingerprinters.

Returns:
  (RubyConfigurator or None) Returns a configurator if the path contains a
  Ruby app, or None if not.
N)
r7   _CheckForRubyRuntime_CheckEnvironment_DetectGems_DetectRubyInterpreter_DetectNeededPackagesr+   _DetectDefaultEntrypoint_ChooseEntrypointr%   )	r3   r)   r7   bundler_availablegemsr*   r,   r+   default_entrypoints	            r   Fingerprintrp     s     NN'	d	,	,'-	&	'$'@,"4((####J1$="#5?J	$(	KKr   c                    U(       a  UR                  5       S:X  a  g[        R                  " S5        [        R                  R                  U S5      n[        R                  R                  U5      (       d  gSn[        R                  " 5       (       a  [        R                  " USS9$ [        R                  " U5        g)	a  Determines whether to treat this application as runtime:ruby.

Honors the appinfo runtime setting; otherwise looks at the contents of the
current directory and confirms with the user.

Args:
  path: (str) Application path.
  appinfo: (apphosting.api.appinfo.AppInfoExternal or None) The parsed
    app.yaml file for the module if it exists.

Returns:
  (bool) Whether this app should be treated as runtime:ruby.
r   TzChecking for Ruby.GemfileFz#This looks like a Ruby application.z)Proceed to configure deployment for Ruby?)messageprompt_string)
GetEffectiveRuntimer
   r.   rD   r3   rF   isfiler   	CanPromptPromptContinue)r3   r7   gemfile_pathgot_ruby_messages       r   rf   rf   .  s     ,,.&8(( dI.,		%	%:$$ AC C HHr   c                 
   [         R                  R                  [         R                  R                  U S5      5      (       d  [	        S5      e[         R                  R                  [         R                  R                  U S5      5      n[        S5      nU(       aE  [        S5      (       d  [        S5      eU(       d!  Sn[        R                  R                  U5        U$ Sn[        R                  R                  U5        U$ )	a  Gathers information about the local environment, and performs some checks.

Args:
  path: (str) Application path.

Returns:
  (bool) Whether bundler is available in the environment.

Raises:
  RubyConfigError: The application is recognized as a Ruby app but
  malformed in some way.
rr   z%Gemfile is required for Ruby runtime.zGemfile.lockzbundle versionzbundle checkzJYour bundle is not up-to-date. Install missing gems with 'bundle install'.as  
NOTICE: We could not find a Gemfile.lock, which suggests this application has not been tested locally, or the Gemfile.lock has not been committed to source control. We have created a Gemfile.lock for you, but it is recommended that you verify it yourself (by installing your bundle and testing locally) to ensure that the gems we deploy are the same as those you tested.aQ  
NOTICE: gcloud could not run bundler in your local environment, and so its ability to determine your application's requirements will be limited. We will still attempt to deploy your application, but if your application has trouble starting up due to missing requirements, we recommend installing bundler by running [gem install bundler])
rD   r3   rv   rF   r   _SubprocessSucceedsr"   r
   r0   r1   )r3   gemfile_lock_presentrm   msgs       r   rg   rg   O  s     
T95	6	6
E
FFT>(JK)*:;~.. K L LPc 
jjs 
#C JJS	r   c                    U(       a  [        S5      n[        R                  " SU5      (       d  [        R                  " SU5      nU(       aX  UR                  S5      n[        R                  XD5      nSR                  U5      n[        R                  R                  U5        U$ SR                  U5      n[        R                  R                  U5        [        U S5      nU(       aB  UR                  5       nSR                  U5      n[        R                  R                  U5        U$ S	R                  [        5      n[        R                  R                  U5        g
)a:  Determines the ruby interpreter and version expected by this application.

Args:
  path: (str) Application path.
  bundler_available: (bool) Whether bundler is available in the environment.

Returns:
  (str or None) The interpreter version in rbenv (.ruby-version) format, or
  None to use the base image default.
zbundle platform --rubyz^No z^ruby (\d+\.\d+(\.\d+)?)   z,
Using Ruby {0} as requested in the Gemfile.z'Unrecognized platform in Gemfile: [{0}]z.ruby-versionz6
Using Ruby {0} as requested in the .ruby-version filea	  
NOTICE: We will deploy your application using a recent version of the standard "MRI" Ruby runtime by default. If you want to use a specific Ruby runtime, you can create a ".ruby-version" file in this directory. (For best performance, we recommend MRI version {0}.)N)_RunSubprocessrematchgroupRUBY_VERSION_MAPgetrO   r
   r0   r1   	_ReadFilestripPREFERRED_RUBY_VERSION)r3   rm   	ruby_infor   r*   r~   s         r   ri   ri   z  s    78I88FI&&hh2I>e	{{1~'++LG>vl# 	

5<<YGc	jjs41,%%'LD6, JJS
L 
&	'	 
 **3	r   c                     / nU (       a`  [        S5      R                  5        HC  n[        R                  " SU5      nU(       d  M#  UR	                  UR                  S5      5        ME     U$ )zReturns a list of gems requested by this application.

Args:
  bundler_available: (bool) Whether bundler is available in the environment.

Returns:
  ([str, ...]) A list of gem names.
zbundle listz\s*\*\s+(\S+)\s+\(r   )r   
splitlinesr   r   r8   r   )rm   rn   liner   s       r   rh   rh     sU     
$}-88:hh,d3e	EKKN# ; 
+r   c                 \   [         R                  R                  U S5      n[         R                  R                  U5      (       a  [        $ SU;   a  [
        $ SU;   a  [        $ [         R                  R                  U S5      n[         R                  R                  U5      (       a  [        $ g)zReturns the app server expected by this application.

Args:
  path: (str) Application path.
  gems: ([str, ...]) A list of gems used by this application.

Returns:
  (str) The default entrypoint command, or the empty string if unknown.
Procfilepumaunicornz	config.ru )rD   r3   rF   rv   ENTRYPOINT_FOREMANENTRYPOINT_PUMAENTRYPOINT_UNICORNENTRYPOINT_RACKUP)r3   rn   procfile_pathconfigru_paths       r   rk   rk     s|     '',,tZ0-WW^^M""t^D'',,t[1-WW^^M""	r   c                    [         R                  " 5       (       a  U (       a(  Sn[         R                  " UR                  U 5      5      nO[         R                  " S5      nUR	                  5       nU(       d  U (       d  [        S5      eU nU(       a0  SR                  U5      n[        R                  R                  U5        U$ SR                  [        R                  " 5       5      n[        U5      e)a\  Prompt the user for an entrypoint.

Args:
  default_entrypoint: (str) Default entrypoint determined from the app.
  appinfo: (apphosting.api.appinfo.AppInfoExternal or None) The parsed
    app.yaml file for the module if it exists.

Returns:
  (str) The actual entrypoint to use.

Raises:
  RubyConfigError: Unable to get entrypoint from the user.
zj
Please enter the command to run this Ruby app in production, or leave blank to accept the default:
[{0}] z>
Please enter the command to run this Ruby app in production: zEntrypoint command is required.zm
To avoid being asked for an entrypoint in the future, please add it to your app.yaml. e.g.
  entrypoint: {0}a  This appears to be a Ruby app. You'll need to provide the full command to run the app in production, but gcloud is not running interactively and cannot ask for the entrypoint{0}. Please either run gcloud interactively, or create an app.yaml with "runtime:ruby" and an "entrypoint" field.)r   rw   PromptResponserO   r   r   r
   r0   r1   r   GetNonInteractiveErrorMessage)ro   r7   promptr+   r~   s        r   rl   rl     s     Lf,,V]];M-NOj,,
KMj!!#J?@@%j@VJ 
 
jjs7
 6%CCEF  #
r   c                     [        5       nU  H'  nU[        ;   d  M  UR                  [        U   5        M)     [        U5      nUR	                  5         U$ )zDetermines additional apt-get packages required by the given gems.

Args:
  gems: ([str, ...]) A list of gems used by this application.

Returns:
  ([str, ...]) A sorted list of strings indicating packages to install
)setGEM_PACKAGESupdatelistsort)rn   package_setgemr,   s       r   rj   rj     sJ     +c
lc*+  +(
--/	/r   c                     [         R                  " U S[         R                  S9nUR                  5       S:w  a  [	        SR                  U 5      5      eUR                  R                  5       $ )NTshellstdoutr   zUnable to run script: [{0}])
subprocessPopenPIPEwaitr   rO   r   readcmdps     r   r   r     sN    s$z?!VVX]
7>>sC
DD	
r   c                 p    [         R                  " U S[         R                  S9nUR                  5       S:H  $ )NTr   r   )r   r   r   r   r   s     r   r|   r|     s*    s$z?!	
Qr   c                     [         R                  R                  X5      n[         R                  R                  U5      (       d"  U(       a  [	        SR                  U5      5      eg [        R                  " U5      $ )Nz#Could not find required file: [{0}])rD   r3   rF   rv   r   rO   r   ReadFileContents)r(   rG   requiredr3   s       r   r   r     s[    	d	%$			
/
6
6x
@B B				%%r   )F)=r   
__future__r   r   r   rD   r   r   textwrapgae_ext_runtimer   googlecloudsdk.api_lib.appr   !googlecloudsdk.api_lib.app.imagesr   googlecloudsdk.corer	   r
   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   NAMEALLOWED_RUNTIME_NAMESr   BUNDLER_VERSIONFOREMAN_VERSIONr   r   dedentrN   rb   rV   rX   rO   rW   rY   rZ   r[   r\   r   r   r   r   Errorr   r   r"   Configuratorr%   rp   rf   rg   ri   rh   rk   rl   rj   r   r|   r   r   r   r   <module>r      s    0 &  ' 	 	   ' : 4 * # 2 * *  !     ]M* OO % 	 
 ! ) 	  OO 
% 
	  "* 2 "	  !) 	1 	0	!2  $?? , 	  'oo / 	  " * 	 
 ! ) 	  1 :@ H 5j&& 5/ 4 4m{// m`L>B(V(V$4(V$
&r   