Skip to content

Commit

Permalink
fix php provider (railwayapp#820)
Browse files Browse the repository at this point in the history
* fix php provider

* php vanilla docker run test

* fix snapshot tests
  • Loading branch information
coffee-cup committed Mar 4, 2023
1 parent 308f9e3 commit 60b1238
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/providers/php/transform-config.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sub if_stmt {
}

sub get_nix_path {
my ($exe) = $_;
my ($exe) = $_[0];

my $path = `which $exe`;
$path =~ s/\n//;
Expand Down
7 changes: 7 additions & 0 deletions tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,13 @@ async fn test_java_maven() {
assert!(output.contains("Built with Spring Boot"));
}

#[tokio::test]
async fn test_php_vanilla() {
let name = simple_build("./examples/php-vanilla").await;
let output = run_image(&name, None).await;
assert!(output.contains("Server starting on port 80"));
}

#[tokio::test]
async fn test_scala_sbt() {
let name = simple_build("./examples/scala-sbt").await;
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/generate_plan_tests__php_laravel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ expression: plan
"staticAssets": {
"nginx.template.conf": "worker_processes 5;\ndaemon off;\n\nworker_rlimit_nofile 8192;\n\nevents {\n worker_connections 4096; # Default: 1024\n}\n\nhttp {\n include $!{nginx}/conf/mime.types;\n index index.html index.htm index.php;\n\n default_type application/octet-stream;\n log_format main '$remote_addr - $remote_user [$time_local] $status '\n '\"$request\" $body_bytes_sent \"$http_referer\" '\n '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n access_log /dev/stdout;\n error_log /dev/stdout;\n sendfile on;\n tcp_nopush on;\n server_names_hash_bucket_size 128; # this seems to be required for some vhosts\n\n server {\n listen ${PORT};\n listen [::]:${PORT};\n server_name localhost;\n\n $if(IS_LARAVEL) (\n root /app/public;\n ) else (\n root /app;\n )\n \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options \"nosniff\";\n \n index index.php;\n \n charset utf-8;\n \n $if(IS_LARAVEL) (\n location / {\n try_files $uri $uri/ /index.php?$query_string;\n }\n ) else ()\n \n location = /favicon.ico { access_log off; log_not_found off; }\n location = /robots.txt { access_log off; log_not_found off; }\n \n $if(IS_LARAVEL) (\n error_page 404 /index.php;\n ) else ()\n \n location ~ \\.php$ {\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\n include $!{nginx}/conf/fastcgi_params;\n include $!{nginx}/conf/fastcgi.conf;\n }\n \n location ~ /\\.(?!well-known).* {\n deny all;\n }\n }\n}",
"php-fpm.conf": "[www]\nlisten = 127.0.0.1:9000\nuser = nobody\npm = dynamic\npm.max_children = 50\npm.min_spare_servers = 4\npm.max_spare_servers = 32\npm.start_servers = 18\nclear_env = no\n",
"transform-config.pl": "#!/usr/bin/env perl\n\nundef $/;\n\nsub if_stmt {\n my ($condition, $value, $else) = $_;\n\n if($ENV{$condition} eq \"yes\") {\n return $value;\n } else {\n return $else;\n }\n}\n\nsub get_nix_path {\n my ($exe) = $_;\n \n my $path = `which $exe`;\n $path =~ s/\\n//;\n my $storePath = `nix-store -q $path`;\n $storePath =~ s/\\n//;\n return $storePath;\n}\n\nif ($#ARGV != 1) {\n print STDERR \"Usage: $0 <config-file> <output-file>\\n\";\n exit 1;\n}\nmy $infile = $ARGV[0];\nmy $outfile = $ARGV[1];\nopen(FH, '<', $infile) or die \"Could not open configuration file '$infile' $!\";\nmy $out = '';\nwhile (<FH>) {\n\n # If statements\n s{\n \\$if\\s*\\((\\w+)\\)\\s*\\(\n ([\\s\\S]*?)\n \\)\\s*else\\s*\\(\n ([\\s\\S]*?)\n \\)\n }{if_stmt($1, $2, $3)}egx;\n\n # Variables\n s/\\$\\{(\\w+)\\}/$ENV{$1}/eg;\n \n # Nix paths\n s/\\$\\!\\{(\\w+)\\}/get_nix_path($1)/eg;\n\n $out .= $_;\n}\nclose(FH);\nopen(FH, '>', $outfile) or die \"Could not write configuration file '$outfile' $!\";\nprint FH $out;\nclose(FH);\n"
"transform-config.pl": "#!/usr/bin/env perl\n\nundef $/;\n\nsub if_stmt {\n my ($condition, $value, $else) = $_;\n\n if($ENV{$condition} eq \"yes\") {\n return $value;\n } else {\n return $else;\n }\n}\n\nsub get_nix_path {\n my ($exe) = $_[0];\n \n my $path = `which $exe`;\n $path =~ s/\\n//;\n my $storePath = `nix-store -q $path`;\n $storePath =~ s/\\n//;\n return $storePath;\n}\n\nif ($#ARGV != 1) {\n print STDERR \"Usage: $0 <config-file> <output-file>\\n\";\n exit 1;\n}\nmy $infile = $ARGV[0];\nmy $outfile = $ARGV[1];\nopen(FH, '<', $infile) or die \"Could not open configuration file '$infile' $!\";\nmy $out = '';\nwhile (<FH>) {\n\n # If statements\n s{\n \\$if\\s*\\((\\w+)\\)\\s*\\(\n ([\\s\\S]*?)\n \\)\\s*else\\s*\\(\n ([\\s\\S]*?)\n \\)\n }{if_stmt($1, $2, $3)}egx;\n\n # Variables\n s/\\$\\{(\\w+)\\}/$ENV{$1}/eg;\n \n # Nix paths\n s/\\$\\!\\{(\\w+)\\}/get_nix_path($1)/eg;\n\n $out .= $_;\n}\nclose(FH);\nopen(FH, '>', $outfile) or die \"Could not write configuration file '$outfile' $!\";\nprint FH $out;\nclose(FH);\n"
},
"phases": {
"build": {
Expand Down Expand Up @@ -55,4 +55,4 @@ expression: plan
"start": {
"cmd": "([ -e /app/storage ] && chmod -R ugo+w /app/storage); perl /assets/transform-config.pl /assets/nginx.template.conf /nginx.conf && echo \"Server starting on port $PORT\" && (php-fpm -y /assets/php-fpm.conf & nginx -c /nginx.conf)"
}
}
}
4 changes: 2 additions & 2 deletions tests/snapshots/generate_plan_tests__php_vanilla.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ expression: plan
"staticAssets": {
"nginx.template.conf": "worker_processes 5;\ndaemon off;\n\nworker_rlimit_nofile 8192;\n\nevents {\n worker_connections 4096; # Default: 1024\n}\n\nhttp {\n include $!{nginx}/conf/mime.types;\n index index.html index.htm index.php;\n\n default_type application/octet-stream;\n log_format main '$remote_addr - $remote_user [$time_local] $status '\n '\"$request\" $body_bytes_sent \"$http_referer\" '\n '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n access_log /dev/stdout;\n error_log /dev/stdout;\n sendfile on;\n tcp_nopush on;\n server_names_hash_bucket_size 128; # this seems to be required for some vhosts\n\n server {\n listen ${PORT};\n listen [::]:${PORT};\n server_name localhost;\n\n $if(IS_LARAVEL) (\n root /app/public;\n ) else (\n root /app;\n )\n \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options \"nosniff\";\n \n index index.php;\n \n charset utf-8;\n \n $if(IS_LARAVEL) (\n location / {\n try_files $uri $uri/ /index.php?$query_string;\n }\n ) else ()\n \n location = /favicon.ico { access_log off; log_not_found off; }\n location = /robots.txt { access_log off; log_not_found off; }\n \n $if(IS_LARAVEL) (\n error_page 404 /index.php;\n ) else ()\n \n location ~ \\.php$ {\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\n include $!{nginx}/conf/fastcgi_params;\n include $!{nginx}/conf/fastcgi.conf;\n }\n \n location ~ /\\.(?!well-known).* {\n deny all;\n }\n }\n}",
"php-fpm.conf": "[www]\nlisten = 127.0.0.1:9000\nuser = nobody\npm = dynamic\npm.max_children = 50\npm.min_spare_servers = 4\npm.max_spare_servers = 32\npm.start_servers = 18\nclear_env = no\n",
"transform-config.pl": "#!/usr/bin/env perl\n\nundef $/;\n\nsub if_stmt {\n my ($condition, $value, $else) = $_;\n\n if($ENV{$condition} eq \"yes\") {\n return $value;\n } else {\n return $else;\n }\n}\n\nsub get_nix_path {\n my ($exe) = $_;\n \n my $path = `which $exe`;\n $path =~ s/\\n//;\n my $storePath = `nix-store -q $path`;\n $storePath =~ s/\\n//;\n return $storePath;\n}\n\nif ($#ARGV != 1) {\n print STDERR \"Usage: $0 <config-file> <output-file>\\n\";\n exit 1;\n}\nmy $infile = $ARGV[0];\nmy $outfile = $ARGV[1];\nopen(FH, '<', $infile) or die \"Could not open configuration file '$infile' $!\";\nmy $out = '';\nwhile (<FH>) {\n\n # If statements\n s{\n \\$if\\s*\\((\\w+)\\)\\s*\\(\n ([\\s\\S]*?)\n \\)\\s*else\\s*\\(\n ([\\s\\S]*?)\n \\)\n }{if_stmt($1, $2, $3)}egx;\n\n # Variables\n s/\\$\\{(\\w+)\\}/$ENV{$1}/eg;\n \n # Nix paths\n s/\\$\\!\\{(\\w+)\\}/get_nix_path($1)/eg;\n\n $out .= $_;\n}\nclose(FH);\nopen(FH, '>', $outfile) or die \"Could not write configuration file '$outfile' $!\";\nprint FH $out;\nclose(FH);\n"
"transform-config.pl": "#!/usr/bin/env perl\n\nundef $/;\n\nsub if_stmt {\n my ($condition, $value, $else) = $_;\n\n if($ENV{$condition} eq \"yes\") {\n return $value;\n } else {\n return $else;\n }\n}\n\nsub get_nix_path {\n my ($exe) = $_[0];\n \n my $path = `which $exe`;\n $path =~ s/\\n//;\n my $storePath = `nix-store -q $path`;\n $storePath =~ s/\\n//;\n return $storePath;\n}\n\nif ($#ARGV != 1) {\n print STDERR \"Usage: $0 <config-file> <output-file>\\n\";\n exit 1;\n}\nmy $infile = $ARGV[0];\nmy $outfile = $ARGV[1];\nopen(FH, '<', $infile) or die \"Could not open configuration file '$infile' $!\";\nmy $out = '';\nwhile (<FH>) {\n\n # If statements\n s{\n \\$if\\s*\\((\\w+)\\)\\s*\\(\n ([\\s\\S]*?)\n \\)\\s*else\\s*\\(\n ([\\s\\S]*?)\n \\)\n }{if_stmt($1, $2, $3)}egx;\n\n # Variables\n s/\\$\\{(\\w+)\\}/$ENV{$1}/eg;\n \n # Nix paths\n s/\\$\\!\\{(\\w+)\\}/get_nix_path($1)/eg;\n\n $out .= $_;\n}\nclose(FH);\nopen(FH, '>', $outfile) or die \"Could not write configuration file '$outfile' $!\";\nprint FH $out;\nclose(FH);\n"
},
"phases": {
"install": {
Expand All @@ -39,4 +39,4 @@ expression: plan
"start": {
"cmd": "([ -e /app/storage ] && chmod -R ugo+w /app/storage); perl /assets/transform-config.pl /assets/nginx.template.conf /nginx.conf && echo \"Server starting on port $PORT\" && (php-fpm -y /assets/php-fpm.conf & nginx -c /nginx.conf)"
}
}
}

0 comments on commit 60b1238

Please sign in to comment.