
    G                         d dl Z d dlZd dlmZ e j                  j                  e j                  j                  e            ZdZ G d dej                        Z
edk(  r ej                          yy)    N)testutila  # 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 gem
FROM gcr.io/google-appengine/ruby:{base_image_tag}

# If your application requires a specific ruby version (compatible with rbenv),
# set it here. Leave blank to use the currently recommended default.
ARG REQUESTED_RUBY_VERSION="{ruby_version}"

# Install any requested ruby if not already preinstalled by the base image.
# Tries installing a prebuilt package first, then falls back to a source build.
RUN if test -n "$REQUESTED_RUBY_VERSION" -a \
        ! -x /rbenv/versions/$REQUESTED_RUBY_VERSION/bin/ruby; then \
      (apt-get update -y \
        && apt-get install -y -q gcp-ruby-$REQUESTED_RUBY_VERSION) \
      || (cd /rbenv/plugins/ruby-build \
        && git pull \
        && rbenv install -s $REQUESTED_RUBY_VERSION) \
      && rbenv global $REQUESTED_RUBY_VERSION \
      && gem install -q --no-rdoc --no-ri bundler --version $BUNDLER_VERSION \
      && apt-get clean \
      && rm -f /var/lib/apt/lists/*_*; \
    fi
ENV RBENV_VERSION=${{REQUESTED_RUBY_VERSION:-$RBENV_VERSION}}

# Copy the application files.
COPY . /app/

# Install required gems if Gemfile.lock is present.
RUN if test -f Gemfile.lock; then \
      bundle install --deployment --without="development test" \
      && rbenv rehash; \
    fi

# Temporary. Will be moved to base image later.
ENV RACK_ENV=production \
    RAILS_ENV=production \
    RAILS_SERVE_STATIC_FILES=true

# Run asset pipeline if we're in a Rails app.
RUN if test -d app/assets -a -f config/application.rb; then \
      bundle exec rake assets:precompile || true; \
    fi

# BUG: Reset entrypoint to override base image.
ENTRYPOINT []

# Start application on port $PORT.
CMD {entrypoint}
c                        e Zd ZdZd Zd Z fdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )RuntimeTestCasez2Tests for the Ruby external runtime fingerprinter.c                     t        | j                  |            5 }|j                         cddd       S # 1 sw Y   yxY w)zReads the contents of the file from the tempdir.

        Args:
            filename: (str) filename to be joined with tempdir prefix.

        Returns:
            File contents.
        N)open	full_pathread)selffilenamefs      .platform/ext-runtime/ruby/test/runtime_test.pyfile_contentszRuntimeTestCase.file_contentsU   s,     $..*+q668 ,++s   5>c                       j                   j                   j                   j                   fd}d  j                   _        fd j                   _        |S )zStubs the console response from the user.

        Args:
            response: (str) stubbed response.

        Returns:
            A function to reset the stubbed functions to their original
            implementations.
        c                  J     j                   _        j                   _        y Nexec_env	CanPromptPromptResponse)
can_promptprompt_responser
   s   r   unstubz-RuntimeTestCase.stub_response.<locals>.unstubn   s    &0DMM#+:DMM(    c                       y)NT r   r   r   <lambda>z/RuntimeTestCase.stub_response.<locals>.<lambda>r   s    $r   c                     S r   r   )promptresponses    r   r   z/RuntimeTestCase.stub_response.<locals>.<lambda>s   s    hr   r   )r
   r   r   r   r   s   `` @@r   stub_responsezRuntimeTestCase.stub_responsea   sG     ]],,
--66	; #/'>$r   c                 @    t         | _        t        t        |           y r   )RUNTIME_DEF_ROOTruntime_def_rootsuperr   setUp)r
   	__class__s    r   r%   zRuntimeTestCase.setUpw   s     0ot*,r   c                    | j                  dd       | j                          | j                  t        j                  j                  | j                  d                   | j                  t        j                  j                  | j                  d                   | j                  t        j                  j                  | j                  d                   y )N
index.htmlindexapp.yaml
Dockerfile.dockerignore)
write_filegenerate_configsassertFalseospathexistsr   r
   s    r    test_generate_without_ruby_filesz0RuntimeTestCase.test_generate_without_ruby_files{   s    g.z(BCD|(DEF(GHIr   c                     | j                  dd       | j                  | j                                | j                  t        j
                  j                  | j                  d                   y)z9Tests generate_config_data does nothing if no ruby files.r(   r)   r*   N)r-   assertIsNonegenerate_config_datar/   r0   r1   r2   r   r3   s    r   )test_generate_without_ruby_files_no_writez9RuntimeTestCase.test_generate_without_ruby_files_no_write   sK    g.$3356z(BCDr   c                 B   | j                  dd       | j                  dd       | j                  dd       | j                  d      }| j                           |        | j                  d      }| j	                  d	|       | j	                  d
|       | j	                  d|       | j                  t        j                  j                  | j                  d                   | j                  t        j                  j                  | j                  d                   y )Nindex.rbclass Index; endGemfilesource "https://rubygems.org"	config.rurun Index.app)bundle exec rackup -p $PORT -E deploymentr*   runtime: ruby

env: flex
6entrypoint: bundle exec rackup -p $PORT -E deployment
r+   r,   )
r-   r    r.   r   assertInr/   r0   r1   r2   r   )r
   r   app_yamls      r   test_generate_with_ruby_filesz-RuntimeTestCase.test_generate_with_ruby_files   s    
$67	#BC_5##$OP%%j1'2mX.O	  	|(DEF(GHIr   c                 
   | j                  dd       | j                  dd       | j                  dd       | j                  d      }| j                         } |        | j                  d      }| j	                  d	|       | j	                  d
|       | j	                  d|       | j                  d|D cg c]  }|j                   c}       | j                  d|D cg c]  }|j                   c}       yc c}w c c}w )zTests generate_config_data with basic Ruby files.

        Tests that app.yaml is written with correct contents given entrypoint
        response, and that Dockerfile and .dockerignore not written to disk.
        r:   r;   r<   r=   r>   r?   r@   r*   rA   rB   rC   r+   r,   N)r-   r    r7   r   rD   assertNotInr   )r
   r   	cfg_filesrE   r   s        r   &test_generate_with_ruby_files_no_writez6RuntimeTestCase.test_generate_with_ruby_files_no_write   s     	
$67	#BC_5##$OP--/	%%j1'2mX.O	  	I'FIq

I'FGy*Iy!1::y*IJ (G*Is   6C;
 D 
c                 .   | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  d	      }| j                  d
        |        | j                  d      }| j	                  |t
        j                  dd	             | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y )Nr:   r;   r<   r=   r>   r?   .ruby-versionrbx-3.9r@   Tdeployr+   ruby_version
entrypointr,   .dockerignore
Dockerfile
.git
.hg
.svn
r-   r    r.   r   assertEqualDOCKERFILE_TEXTformatrD   r
   r   
dockerfiledockerignores       r   test_generate_with_deployz)RuntimeTestCase.test_generate_with_deploy   s    
$67	#BC_53##$OPT*''5
&&%.#N ' P	Q ))/:'6nl3h-g|,h-r   c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  d	      }| j                  d
      } |        | j                  |dt        j                  dd	             | j                  d|D cg c]  }|j                   c}       |D cg c]  }|j                  dk(  r|j                   c}d   }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       yc c}w c c}w )zTests generate_config_data with deploy=True.

        Tests that .dockerignore and Dockerfile contents are correct
        based on contents of app.
        r:   r;   r<   r=   r>   r?   rL   rM   r@   TrN   r+   rP   r,   r   rS   rT   rU   rV   rW   N	r-   r    r7   #assert_genfile_exists_with_contentsrZ   r[   rD   r   contentsr
   r   rI   r   r^   s        r   "test_generate_with_deploy_no_writez2RuntimeTestCase.test_generate_with_deploy_no_write   s>    	
$67	#BC_53##$OP--T-:	00&&%.#N ' P	Q 	oI'FIq

I'FG,5 7Iq

o5 

I 778:'6nl3h-g|,h- (G7s   +E
	"Ec                    | j                  dd       | j                  dd       | j                  dd       | j                  d      }| j                  d	        |        | j                  d
      }| j	                  d|       | j	                  d|       | j	                  d|       | j                  d      }| j                  |t        j                  dd             | j                  d      }| j	                  d|       | j	                  d|       | j	                  d|       | j	                  d|       | j	                  d|       y )Nr:   r;   r<   r=   r>   r?   r@   Tcustomr*   runtime: custom
rB   rC   r+    rP   r,   rS   rT   rU   rV   rW   )r-   r    r.   r   rD   rY   rZ   r[   )r
   r   rE   r]   r^   s        r   test_generate_with_customz)RuntimeTestCase.test_generate_with_custom   s+   
$67	#BC_5##$OPT*%%j1)84mX.O	  ''5
&&%'#N ' P	Q ))/:'6nl3h-g|,h-r   c                    | j                  dd       | j                  dd       | j                  dd       | j                  d      }| j                  d	      } |        | j                  d
      }| j	                  d|       | j	                  d|       | j	                  d|       | j                  |dt        j                  dd             | j	                  d|D cg c]  }|j                   c}       |D cg c]  }|j                  dk(  r|j                   c}d   }| j	                  d|       | j	                  d|       | j	                  d|       | j	                  d|       | j	                  d|       yc c}w c c}w )zTests generate_config_data with custom=True.

        Tests that app.yaml is written with correct parameters and
        Dockerfile, .dockerignore contents are correctly returned by method.
        r:   r;   r<   r=   r>   r?   r@   Trg   r*   ri   rB   rC   r+   rj   rP   r,   r   rS   rT   rU   rV   rW   N)
r-   r    r7   r   rD   rb   rZ   r[   r   rc   )r
   r   rI   rE   r   r^   s         r   "test_generate_with_custom_no_writez2RuntimeTestCase.test_generate_with_custom_no_write	  sq    	
$67	#BC_5##$OP--T-:	%%j1)84mX.O	  	00&&%'#N ' P	Q 	oI'FIq

I'FG,5 7Iq

o5 

I 778:'6nl3h-g|,h- (G7s    F
>"Fc                    | j                  dd       | j                  dd       | j                  dd       t        j                  ddd	
      }| j                  |d	       | j	                  t
        j                  j                  | j                  d                   | j                  d      }| j                  |t        j                  dd             | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y )Nr:   r;   r<   r=   r>   r?   bundle exec ruby index.rb $PORTrubyTrR   runtimevmappinforO   r*   r+   rj   rP   r,   rS   rT   rU   rV   rW   r-   r   AppInfoFaker.   r/   r0   r1   r2   r   r   rY   rZ   r[   rD   r
   ru   r]   r^   s       r   #test_generate_with_existing_appinfoz3RuntimeTestCase.test_generate_with_existing_appinfo-  s   
$67	#BC_5&&< 	gd;z(BCD''5
&&%'#D ' F	G ))/:'6nl3h-g|,h-r   c                    | j                  dd       | j                  dd       | j                  dd       t        j                  ddd	
      }| j                  |d	      }| j	                  t
        j                  j                  | j                  d                   | j                  |dt        j                  dd             | j                  d|D cg c]  }|j                   c}       |D cg c]  }|j                  dk(  r|j                   c}d   }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       yc c}w c c}w )z/Tests generate_config_data with passed appinfo.r:   r;   r<   r=   r>   r?   ro   rp   Trq   rt   r*   r+   rj   rP   r,   r   rS   rT   rU   rV   rW   Nr-   r   rw   r7   r/   r0   r1   r2   r   rb   rZ   r[   rD   r   rc   r
   ru   rI   r   r^   s        r   ,test_generate_with_existing_appinfo_no_writez<RuntimeTestCase.test_generate_with_existing_appinfo_no_writeG  sY   
$67	#BC_5&&< --gd-K	z(BCD00&&%'#D ' F	G 	oI'FIq

I'FG,5 7Iq

o5 

I 778:'6nl3h-g|,h- (G7s   E8
5"E=c                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       t        j                  d	d
d      }| j                  |d       | j	                  t
        j                  j                  | j                  d                   | j                  d      }| j                  |t        j                  dd	             | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y )Nr:   r;   r<   r=   r>   r?   rL   2.3.1
ro   rp   Trq   rt   r*   r+   2.3.1rP   r,   rS   rT   rU   rV   rW   rv   rx   s       r   test_generate_with_ruby_versionz/RuntimeTestCase.test_generate_with_ruby_versiond  s#   
$67	#BC_53&&< 	gd;z(BCD''5
&&%,#D ' F	G ))/:'6nl3h-g|,h-r   c                 (   | j                  dd       | j                  dd       | j                  dd       | j                  dd       t        j                  d	d
d      }| j                  |d      }| j	                  t
        j                  j                  | j                  d                   | j                  |dt        j                  dd	             | j                  d|D cg c]  }|j                   c}       |D cg c]  }|j                  dk(  r|j                   c}d   }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       yc c}w c c}w )z3Tests generate_config_data with .ruby-version file.r:   r;   r<   r=   r>   r?   rL   r   ro   rp   Trq   rt   r*   r+   r   rP   r,   r   rS   rT   rU   rV   rW   Nr{   r|   s        r   (test_generate_with_ruby_version_no_writez8RuntimeTestCase.test_generate_with_ruby_version_no_write  sg   
$67	#BC_53&&< --gd-K	z(BCD00&&%,#D ' F	G 	oI'FIq

I'FG,5 7Iq

o5 

I 778:'6nl3h-g|,h- (G7s   )F

"Fc                    | j                  dd       | j                  dd       | j                  d      }| j                  d        |        | j                  d      }| j	                  |t
        j                  d	d
             | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y )Nr:   r;   r<   r=   ro   TrN   r+   rj   rP   r,   rS   rT   rU   rV   rW   rX   r\   s       r   test_generate_with_promptz)RuntimeTestCase.test_generate_with_prompt  s    
$67	#BC##$EFT*''5
&&%'#D ' F	G ))/:'6nl3h-g|,h-r   c                 d   | j                  dd       | j                  dd       | j                  d      }| j                  d      } |        | j                  |dt        j                  d	d
             | j                  d|D cg c]  }|j                   c}       |D cg c]  }|j                  dk(  r|j                   c}d   }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       yc c}w c c}w )z;Tests generate_config_data with entrypoint given by prompt.r:   r;   r<   r=   ro   TrN   r+   rj   rP   r,   r   rS   rT   rU   rV   rW   Nra   rd   s        r   "test_generate_with_prompt_no_writez2RuntimeTestCase.test_generate_with_prompt_no_write  s    
$67	#BC##$EF--T-:	00&&%'#D ' F	G 	oI'FIq

I'FG,5 7Iq

o5 

I 778:'6nl3h-g|,h- (G7s   D(
%"D-)__name__
__module____qualname____doc__r   r    r%   r4   r8   rF   rJ   r_   re   rk   rm   ry   r}   r   r   r   r   __classcell__)r&   s   @r   r   r   R   s`    <
,-JEJ$K..2.>.:".H.4.:.6.<.,.r   r   __main__)r0   unittestgae_ext_runtimer   r1   dirname__file__r"   rZ   TestBaser   r   mainr   r   r   <module>r      sg     
  $77??277??8#<= 7tx.h'' x.t zhmmo r   