This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post install commands for php and xdebug
Signed-off-by: Jason McCallister <jason@craftcms.com>
- Loading branch information
1 parent
7f4e6e2
commit 1b4b1a6
Showing
3 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package action | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/craftcms/nitro/validate" | ||
) | ||
|
||
func ConfigurePHPMemoryLimit(name, php, limit string) (*Action, error) { | ||
if err := validate.MachineName(name); err != nil { | ||
return nil, err | ||
} | ||
if err := validate.PHPVersion(php); err != nil { | ||
return nil, err | ||
} | ||
|
||
cmd := fmt.Sprintf("s|memory_limit = 128M|memory_limit = %s|g", limit) | ||
|
||
return &Action{ | ||
Type: "exec", | ||
UseSyscall: false, | ||
Args: []string{"exec", name, "--", "sudo", "sed", "-i", cmd, "/etc/php/" + php + "/fpm/php.ini"}, | ||
}, nil | ||
} | ||
|
||
func ConfigurePHPExecutionTimeLimit(name, php, limit string) (*Action, error) { | ||
if err := validate.MachineName(name); err != nil { | ||
return nil, err | ||
} | ||
if err := validate.PHPVersion(php); err != nil { | ||
return nil, err | ||
} | ||
|
||
cmd := fmt.Sprintf("s|max_execution_time = 30|max_execution_time = %s|g", limit) | ||
|
||
return &Action{ | ||
Type: "exec", | ||
UseSyscall: false, | ||
Args: []string{"exec", name, "--", "sudo", "sed", "-i", cmd, "/etc/php/" + php + "/fpm/php.ini"}, | ||
}, nil | ||
} | ||
|
||
func ConfigureXdebug(name, php string) (*Action, error) { | ||
if err := validate.MachineName(name); err != nil { | ||
return nil, err | ||
} | ||
if err := validate.PHPVersion(php); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Action{ | ||
Type: "exec", | ||
UseSyscall: false, | ||
Args: []string{"exec", name, "--", "sudo", "sed", "-i", "-e", `\$axdebug.remote_enable=1\nxdebug.remote_connect_back=0\nxdebug.remote_host=localhost\nxdebug.remote_port=9000\nxdebug.remote_log=/var/log/nginx/xdebug.log`, "/etc/php/" + php + "/mods-available/xdebug.ini"}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package action | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestConfigurePHPMemoryLimit(t *testing.T) { | ||
type args struct { | ||
name string | ||
php string | ||
limit string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Action | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "run the sed command for a specific version", | ||
args: args{ | ||
name: "somename", | ||
php: "7.4", | ||
limit: "256M", | ||
}, | ||
want: &Action{ | ||
Type: "exec", | ||
UseSyscall: false, | ||
Args: []string{"exec", "somename", "--", "sudo", "sed", "-i", "s|memory_limit = 128M|memory_limit = 256M|g", "/etc/php/7.4/fpm/php.ini"}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "wrong php returns error", | ||
args: args{ | ||
name: "somename", | ||
php: "7.9", | ||
limit: "256M", | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "bad name returns error", | ||
args: args{ | ||
name: "", | ||
php: "7.9", | ||
limit: "256M", | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ConfigurePHPMemoryLimit(tt.args.name, tt.args.php, tt.args.limit) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ConfigurePHPMemoryLimit() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ConfigurePHPMemoryLimit() got = \n%v, \nwant \n%v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestConfigurePHPExecutionTimeLimit(t *testing.T) { | ||
type args struct { | ||
name string | ||
php string | ||
limit string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Action | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "run the sed command for a specific version", | ||
args: args{ | ||
name: "somename", | ||
php: "7.4", | ||
limit: "240", | ||
}, | ||
want: &Action{ | ||
Type: "exec", | ||
UseSyscall: false, | ||
Args: []string{"exec", "somename", "--", "sudo", "sed", "-i", "s|max_execution_time = 30|max_execution_time = 240|g", "/etc/php/7.4/fpm/php.ini"}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "wrong php returns error", | ||
args: args{ | ||
name: "somename", | ||
php: "7.9", | ||
limit: "240", | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "bad name returns error", | ||
args: args{ | ||
name: "", | ||
php: "7.9", | ||
limit: "240", | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ConfigurePHPExecutionTimeLimit(tt.args.name, tt.args.php, tt.args.limit) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ConfigurePHPExecutionTimeLimit() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ConfigurePHPExecutionTimeLimit() got = \n%v, \nwant \n%v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestConfigureXdebug(t *testing.T) { | ||
type args struct { | ||
name string | ||
php string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Action | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "returns the sed command", | ||
args: args{ | ||
name: "somename", | ||
php: "7.4", | ||
}, | ||
want: &Action{ | ||
Type: "exec", | ||
UseSyscall: false, | ||
Args: []string{"exec", "somename", "--", "sed", "-i", "-e", `\$axdebug.remote_enable=1\nxdebug.remote_connect_back=0\nxdebug.remote_host=localhost\nxdebug.remote_port=9000\nxdebug.remote_log=/var/log/nginx/xdebug.log`, "/etc/php/7.4/mods-available/xdebug.ini"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ConfigureXdebug(tt.args.name, tt.args.php) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ConfigureXdebug() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ConfigureXdebug() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters