-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathlnmp-docker.ps1
executable file
·1304 lines (1021 loc) · 34.6 KB
/
lnmp-docker.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#PSScriptInfo
.AUTHOR [email protected]
.COMPANYNAME khs1994-docker
.COPYRIGHT [email protected]
.TAGS docker lnmp
.LICENSEURI https://github.com/khs1994-docker/lnmp/blob/master/LICENSE
.PROJECTURI https://github.com/khs1994-docker/lnmp
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
#>
<#
.SYNOPSIS
khs1994-docker/lnmp CLI
.DESCRIPTION
khs1994-docker/lnmp CLI
PS C:\> lnmp-docker up
.EXAMPLE
PS C:\> lnmp-docker up
.INPUTS
.OUTPUTS
.NOTES
khs1994-docker/lnmp CLI
#>
$LNMP_CACHE = "$HOME/.khs1994-docker-lnmp"
$env:WSLENV = $null
$env:COMPOSE_FILE = $null
if ($args[0] -eq "install") {
if (get-command git) {
git clone -b 23.11 --depth=1 https://github.com/khs1994-docker/lnmp.git $home\lnmp
exit
}
write-warning "Please download and install git:
Official: https://github.com/git-for-windows/git/releases
CN_Mirror: https://mirrors.huaweicloud.com/git-for-windows/
"
exit 1
}
$outNull = $false
if (${QUITE} -eq $true) {
$outNull = $true
}
if ($args[0] -eq "services") {
$outNull = $true
}
Function printInfo() {
if ($outNull) {
return
}
Write-Host "INFO " -NoNewLine -ForegroundColor Green
Write-Host "$args";
}
Function getEnvFile() {
$LNMP_ENV_FILE = ".env"
$LNMP_ENV_FILE_PS1 = ".env.ps1"
if ($env:LNMP_ENV) {
if (Test-Path("$PSScriptRoot/.env.${env:LNMP_ENV}")) {
$LNMP_ENV_FILE = ".env.${env:LNMP_ENV}"
}
if (Test-Path("$PSScriptRoot/.env.${env:LNMP_ENV}.ps1")) {
$LNMP_ENV_FILE_PS1 = ".env.${env:LNMP_ENV}.ps1"
}
}
return $LNMP_ENV_FILE, $LNMP_ENV_FILE_PS1
}
$LNMP_ENV_FILE, $LNMP_ENV_FILE_PS1 = getEnvFile
if ($args[0] -eq "env-file") {
echo $LNMP_ENV_FILE, $LNMP_ENV_FILE_PS1
exit
}
if (!(Test-Path $PSScriptRoot\scripts\cli\khs1994-robot.enc )) {
Write-Host "lnmp-docker.ps1 not in lnmp ROOT PATH" -ForegroundColor Red
Write-Host "Please remove $((get-command lnmp-docker).Source)" -ForegroundColor Red
exit 1
}
printInfo "Load env file [ $LNMP_ENV_FILE ] and [ $LNMP_ENV_FILE_PS1 ]"
. "$PSScriptRoot/.env.example.ps1"
. "$PSScriptRoot/scripts/cli/.env.ps1"
if (Test-Path "$PSScriptRoot/$LNMP_ENV_FILE_PS1") {
. "$PSScriptRoot/$LNMP_ENV_FILE_PS1"
}
# [environment]::SetEnvironmentvariable("DOCKER_DEFAULT_PLATFORM", "linux", "User");
# $ErrorActionPreference="SilentlyContinue"
# Stop, Continue, Inquire, Ignore, Suspend, Break
$EXEC_CMD_DIR = $PWD
Function Test-Command($command) {
get-command $command -ErrorAction "SilentlyContinue"
return $?
}
Function printError() {
if ($outNull) {
return
}
Write-Host "Error " -NoNewLine -ForegroundColor Red
Write-Host "$args";
}
Function printWarning() {
if ($outNull) {
return
}
Write-Host "Warning " -NoNewLine -ForegroundColor Red
Write-Host "$args";
}
Function _cp_only_not_exists($src, $desc) {
if (!(Test-Path $desc)) {
Copy-Item $src $desc
}
}
Function New-InitFile() {
if (Test-Path docker-lnmp.include.yml) {
Copy-Item docker-lnmp.include.yml docker-lnmp.override.yml
Copy-Item docker-lnmp.include.yml docker-lnmp.include.yml.backup
Remove-Item -r -force docker-lnmp.include.yml
}
_cp_only_not_exists kubernetes/nfs-server/.env.example kubernetes/nfs-server/.env
_cp_only_not_exists config/supervisord/supervisord.ini.example config/supervisord/supervisord.ini
if (!(Test-Path secrets/minio/root-password.txt)) {
Copy-Item secrets/minio/root-password.example.txt secrets/minio/root-password.txt
Copy-Item secrets/minio/root-user.example.txt secrets/minio/root-user.txt
}
if (!(Test-Path config/redis/redis.conf)) {
New-Item -ItemType File config/redis/redis.conf
}
if (!(Test-Path config/mysql/conf.d/my.cnf)) {
New-Item -ItemType File config/mysql/conf.d/my.cnf
}
if (!(Test-Path config/mariadb/conf.d/my.cnf)) {
New-Item -ItemType File config/mariadb/conf.d/my.cnf
}
_cp_only_not_exists docker-lnmp.override.example.yml docker-lnmp.override.yml
_cp_only_not_exists docker-workspace.example.yml docker-workspace.yml
_cp_only_not_exists config/php/docker-php.example.ini config/php/docker-php.ini
_cp_only_not_exists config/php/php.development.ini config/php/php.ini
_cp_only_not_exists config/php/php-cli.example.ini config/php/php-cli.ini
_cp_only_not_exists config/php/zz-docker.example.conf config/php/zz-docker.conf
_cp_only_not_exists config/php8/docker-php.example.ini config/php8/docker-php.ini
_cp_only_not_exists config/php8/php.development.ini config/php8/php.ini
_cp_only_not_exists config/php8/php-cli.example.ini config/php8/php-cli.ini
_cp_only_not_exists config/php8/zz-docker.example.conf config/php8/zz-docker.conf
_cp_only_not_exists config/npm/.npmrc.example config/npm/.npmrc
_cp_only_not_exists config/npm/.env.example config/npm/.env
_cp_only_not_exists config/yarn/.yarnrc.example config/yarn/.yarnrc
_cp_only_not_exists config/yarn/.env.example config/yarn/.env
_cp_only_not_exists config/crontabs/root.example config/crontabs/root
_cp_only_not_exists config/composer/.env.example config/composer/.env
_cp_only_not_exists config/composer/.env.example.ps1 config/composer/.env.ps1
_cp_only_not_exists config/composer/config.example.json config/composer/config.json
_cp_only_not_exists config/registry/config.example.yml config/registry/config.yml
_cp_only_not_exists wsl2/.env.example.ps1 wsl2/.env.ps1
_cp_only_not_exists wsl2/config/coredns/corefile.example wsl2/config/coredns/corefile
}
Function Wait-Docker() {
while ($i -lt (300)) {
$i += 1
get-process docker*
get-service docker*
docker info
if ($? -eq 'True') {
Write-Host "`nDocker peparation finished OK"
break
}
Write-warning "Retrying in 30 seconds..."
sleep 30
}
}
Function New-LogFile() {
if (! (Test-Path log\httpd)) {
New-Item log\httpd -type directory | Out-Null
}
if (! (Test-Path log\mongodb)) {
New-Item log\mongodb -type directory | Out-Null
New-Item log\mongodb\mongo.log -type file | Out-Null
}
if (-not (Test-Path log\mysql)) {
New-Item log\mysql -type directory | Out-Null
New-Item log\mysql\error.log -type file | Out-Null
}
if (-not (Test-Path log\mariadb)) {
New-Item log\mariadb -type directory | Out-Null
New-Item log\mariadb\error.log -type file | Out-Null
}
if (! (Test-Path log\nginx)) {
New-Item log\nginx -type directory | Out-Null
New-Item log\nginx\access.log -type file | Out-Null
New-Item log\nginx\error.log -type file | Out-Null
}
if (! (Test-Path log\nginx-unit)) {
New-Item log\nginx-unit -type directory | Out-Null
}
if (! (Test-Path log\php)) {
New-Item log\php -type directory | Out-Null
New-Item log\php\error.log -type file | Out-Null
New-Item log\php\php-fpm-slow.log -type file | Out-Null
New-Item log\php\php-fpm-error.log -type file | Out-Null
New-Item log\php\php-fpm-access.log -type file | Out-Null
New-Item log\php\xdebug-remote.log -type file | Out-Null
}
if (! (Test-Path log\redis)) {
New-Item log\redis -type directory | Out-Null
New-Item log\redis\redis.log -type file | Out-Null
}
if (! (Test-Path log\supervisord)) {
New-Item log\supervisord -type directory | Out-Null
}
if (! (Test-Path log\supervisord.log)) {
New-Item log\supervisord.log | Out-Null
}
}
Function init() {
New-LogFile
# git submodule update --init --recursive
printInfo 'Init success'
#@custom
__lnmp_custom_init
}
Function help_information() {
"Docker-LNMP CLI ${LNMP_VERSION}
Official WebSite https://lnmp.khs1994.com
Usage: ./docker-lnmp COMMAND
Donate:
zan Donate
Commands:
up Up LNMP (Support x86_64 arm64v8)
down Stop and remove LNMP Docker containers, networks, images, and volumes
backup Backup MySQL databases
build Build or rebuild your LNMP Docker Images (Only Support x86_64)
push Pushes LNMP Docker Images to Docker Registory
pull Pull LNMP Docker Images
cleanup Cleanup log files
config Validate and view the LNMP Compose file
composer Exec composer command on Docker Container
bug Generate Debug information, then copy it to GitHub Issues
daemon-socket Expose Docker daemon on tcp://0.0.0.0:2376 without TLS
env Edit .env/.env.ps1 file
help Display this help message
hosts Open hosts files
pull Pull LNMP Docker Images
restore Restore MySQL databases
restart Restart LNMP services
services List services
update Upgrades LNMP
upgrade Upgrades LNMP
code Open WSL2 app path on vscode wsl remote [ SUB_DIR ] (e.g. ./lnmp-docker code laravel)
code-init Init vsCode remote development env
code-run Run command on vsCode remote workspace (e.g. ./lnmp-docker code-run -w /app/laravel composer install)
code-exec Exec command on vsCode remote workspace (e.g. ./lnmp-docker code-exec -w /app/laravel workspace composer install)
mount Attaches and mounts a physical disk in all WSL2 distributions.(please exec this command before docker desktop running)
lrew(package):
lrew-init Init a new lrew package
lrew-add Add new lrew package
lrew-outdated Shows a list of installed lrew packages that have updates available
lrew-backup Upload composer.json to GitHub Gist
lrew-update Update lrew package
PHP Tools:
new New PHP Project and generate nginx conf and issue SSL certificate
httpd-config Generate Apache2 vhost conf
nginx-config Generate nginx vhost conf
ssl-self Issue Self-signed SSL certificate
Composer:
satis Build Satis
Swarm mode:
swarm-build Build Swarm image (nginx php7)
swarm-config Validate and view the Production Swarm mode Compose file
swarm-push Push Swarm image (nginx php7)
Container Tools:
SERVICE-cli Execute a command in a running LNMP container
Developer Tools:
Read './docs/*.md' for more information about CLI commands.
You can open issue in [ https://github.com/khs1994-docker/lnmp/issues ] when you meet problems.
You must Update .env file when update this project.
Exec '$ lnmp-docker zan' donate
"
cd $EXEC_CMD_DIR
exit
}
Function cleanup() {
New-LogFile
Remove-Item -Recurse -Force log\httpd | Out-Null
Remove-Item -Recurse -Force log\mongodb | Out-Null
Remove-Item -Recurse -Force log\mysql | Out-Null
Remove-Item -Recurse -Force log\mariadb | Out-Null
Remove-Item -Recurse -Force log\nginx | Out-Null
Remove-Item -Recurse -Force log\nginx-unit | Out-Null
Remove-Item -Recurse -Force log\php | Out-Null
Remove-Item -Recurse -Force log\redis | Out-Null
Remove-Item -Recurse -Force log\supervisord | Out-Null
Remove-Item -Recurse -Force log\supervisord | Out-Null
Remove-Item -Recurse -Force log\supervisord.log | Out-Null
New-LogFile
printInfo "Cleanup logs files Success"
}
Function _update() {
if (!(Test-Command git) -or !(Test-Path .git)) {
printError "Git not install or this folder not git project, not support update"
return
}
if (! $(git remote get-url origin)) {
printError "git remote origin not set, setting ..."
# git remote add origin [email protected]:khs1994-docker/lnmp
git remote add origin https://github.com/khs1994-docker/lnmp
}
# git remote rm origin
if (!($(git status).split(" ")[-1] -eq 'clean')) {
printError "Somefile changed, please commit or stash first"
exit 1
}
${BRANCH} = (git rev-parse --abbrev-ref HEAD)
$ErrorActionPreference = "continue"
git fetch origin ${BRANCH}:lnmp-temp/${BRANCH}
git reset --hard lnmp-temp/${BRANCH}
git branch -D lnmp-temp/${BRANCH}
# git submodule update --init --recursive
}
Function Get-ContainerId($service) {
$container_id = docker container ls `
--format "{{.ID}}" `
-f label=com.khs1994.lnmp `
-f label=com.docker.compose.service=$service -n 1
return $container_id
}
Function Invoke-DockerExec($service, $command) {
$container_id = Get-ContainerId $service
if (!$container_id) {
printError "$service" containr not found
exit 1
}
docker exec -it $container_id $command
}
Function satis() {
if (!(Test-Path ${APP_ROOT}/satis)) {
cp -Recurse app/satis-demo ${APP_ROOT}/satis
Write-Warning "Please modify ${APP_ROOT}/satis/satis.json"
}
docker run --rm -it `
-v ${APP_ROOT}/satis:/build `
--mount -v lnmp_composer-cache-data:/composer composer/satis
}
Function Get-ComposeOptions($compose_files) {
$COMPOSE_FILE_ARRAY = @()
Foreach ($compose_file in $compose_files) {
$COMPOSE_FILE_ARRAY += $compose_file
}
Foreach ($item in $LREW_INCLUDE) {
$KEY = "LREW_$($item -Replace ('-','_'))_VENDOR".ToUpper();
$content = $(cat $LNMP_ENV_FILE | Where-Object { $_ -like "${KEY}=lrew-dev" })
# dev
if (Test-Path $PSScriptRoot/vendor/lrew-dev/$item) {
$LREW_INCLUDE_ROOT = "$PSScriptRoot/vendor/lrew-dev/$item"
# set env
if (!($content)) {
"${KEY}=lrew-dev" >> $LNMP_ENV_FILE
}
}
elseif (Test-Path $PSScriptRoot/vendor/lrew/$item) {
$LREW_INCLUDE_ROOT = "$PSScriptRoot/vendor/lrew/$item"
# unset env
if ($content) {
@(Get-Content $LNMP_ENV_FILE) -replace `
"${KEY}=lrew-dev", '' | Set-Content $LNMP_ENV_FILE
}
}
elseif (Test-Path $PSScriptRoot/lrew/$item) {
$LREW_INCLUDE_ROOT = "$PSScriptRoot/lrew/$item"
}
else {
continue
}
if ($env:USE_WSL2_BUT_DOCKER_NOT_RUNNING -eq '1') {
printError "Docker not running"
cd $EXEC_CMD_DIR
exit 1
}
$COMPOSE_FILE_ARRAY += "$LREW_INCLUDE_ROOT/docker-compose.yml"
if (Test-Path "$LREW_INCLUDE_ROOT/docker-compose.override.yml") {
$COMPOSE_FILE_ARRAY += "$LREW_INCLUDE_ROOT/docker-compose.override.yml"
}
}
$options += "--env-file $LNMP_ENV_FILE"
$COMPOSE_FILE_ARRAY += "docker-workspace.yml"
$env:COMPOSE_FILE = $COMPOSE_FILE_ARRAY -join ';'
# write-host $env:COMPOSE_FILE
return $options.split(' ')
}
Function Test-WSL() {
wsl -d $DistributionName -- echo ""
if (!$?) {
printError "wsl [ $DistributionName ] not found, please check [ $LNMP_ENV_FILE_PS1 ] file `$DistributionName value"
exit 1
}
}
function Copy-PCIT() {
# 判断 app/.pcit 是否存在
rm -r -force ${APP_ROOT}/.pcit
# git clone --depth=1 https://github.com/pcit-ce/pcit ${APP_ROOT}/.pcit
docker pull pcit/pcit:frontend
docker run -it --rm -v ${APP_ROOT}/.pcit/public:/var/www/pcit/public pcit/pcit:frontend
}
function Edit-Hosts() {
Start-Process -FilePath "notepad.exe" `
-ArgumentList "C:\Windows\System32\drivers\etc\hosts" `
-Verb RunAs
}
# main
# .env .env.ps1
if (Test-Path $PSScriptRoot/.env) {
printInfo '.env file existing'
}
else {
Write-Warning '.env file NOT existing, maybe first run'
cp $PSScriptRoot/.env.example $PSScriptRoot/.env
}
if (Test-Path $PSScriptRoot/.env.ps1) {
printInfo ".env.ps1 file existing"
}
else {
Write-Warning ".env.ps1 file NOT existing, maybe first run"
cp $PSScriptRoot/.env.example.ps1 $PSScriptRoot/.env.ps1
}
function Get-Env($ENV_NAME, $ENV_FILE, $ENV_DEFAULT) {
$ENV_CONTENT = (cat $PSScriptRoot/${ENV_FILE} | select-string ^$ENV_NAME=)
if ($ENV_CONTENT) {
if ($ENV_CONTENT.Line.GetType().FullName -eq 'System.String') {
return $ENV_CONTENT.Line.split('=')[-1]
}
else {
return $ENV_CONTENT.Line[-1].split('=')[-1]
}
}
return $ENV_DEFAULT
}
# APP_ROOT
$APP_ROOT = Get-Env 'APP_ROOT' $LNMP_ENV_FILE './app'
$env:USE_WSL2_BUT_DOCKER_NOT_RUNNING = '3'
if (($APP_ROOT.length -gt 7) -and ($APP_ROOT.Substring(0, 7) -eq '\\wsl$\')) {
$env:USE_WSL2_BUT_DOCKER_NOT_RUNNING = '0'
$WSL2_DIST = $APP_ROOT.Split('\')[3]
if ($APP_ROOT.length -le (8 + $WSL2_DIST.length)) {
printError "please check APP_ROOT value in .env file"
exit 1
}
$WSL2_DIST_PATH = '/' + $APP_ROOT.Substring(8 + $WSL2_DIST.length)
if ($WSL2_DIST_PATH.Length -eq 1) {
printError "please check APP_ROOT value in .env file"
exit 1
}
if (!(Test-Path \\wsl$\$WSL2_DIST/mnt/wsl/docker-desktop/cli-tools/usr/bin/docker)) {
$env:USE_WSL2_BUT_DOCKER_NOT_RUNNING = '1'
}
}
# APP_ENV
$APP_ENV = Get-Env -ENV_NAME 'APP_ENV' -ENV_FILE $LNMP_ENV_FILE -ENV_DEFAULT 'development'
# cd LNMP_ROOT
if (!(Test-Path scripts/cli/khs1994-robot.enc )) {
# 在项目目录外
printInfo "Use LNMP CLI in $PWD"
cd $PSScriptRoot
if (($APP_ROOT.length -gt 7) -and ($APP_ROOT.Substring(0, 7) -eq '\\wsl$\')) {
printInfo "APP_ROOT is WSL2 [ $WSL2_DIST ] PATH $WSL2_DIST_PATH"
}
else {
# cd $PSScriptRoot
if (!(Test-Path $APP_ROOT)) {
New-Item -ItemType Directory -Force $APP_ROOT | Out-Null
}
cd $APP_ROOT
$APP_ROOT = $PWD
printInfo "APP_ROOT is $APP_ROOT"
}
cd $PSScriptRoot
}
else {
printInfo "Use LNMP CLI in LNMP Root $pwd"
if (($APP_ROOT.length -gt 7) -and ($APP_ROOT.Substring(0, 7) -eq '\\wsl$\')) {
printInfo "APP_ROOT is WSL2 [ $WSL2_DIST ] PATH $WSL2_DIST_PATH"
}
else {
if (!(Test-Path $APP_ROOT)) {
New-Item -ItemType Directory -Force $APP_ROOT | Out-Null
}
cd $APP_ROOT
$APP_ROOT = $PWD
printInfo "APP_ROOT is $APP_ROOT"
}
cd $EXEC_CMD_DIR
}
$env:APP_ROOT = $APP_ROOT
# LNMP_SERVICES
$LNMP_SERVICES_CONTENT = (cat $PSScriptRoot/$LNMP_ENV_FILE | select-string ^LNMP_SERVICES=)
if ($LNMP_SERVICES_CONTENT) {
$LNMP_SERVICES = $LNMP_SERVICES_CONTENT.Line.Split('=')[-1].Trim('"').split(' ')
}
else {
$LNMP_SERVICES = 'nginx', 'mysql', 'php8', 'redis'
}
# LREW_INCLUDE
$LREW_INCLUDE_CONTENT = (cat $PSScriptRoot/$LNMP_ENV_FILE | select-string ^LREW_INCLUDE=)
if ($LREW_INCLUDE_CONTENT) {
$LREW_INCLUDE = $LREW_INCLUDE_CONTENT.Line.Split('=')[-1].Trim('"').split(' ')
}
else {
$LREW_INCLUDE = 'pcit'
}
printInfo "Load lnmp service [ $LNMP_SERVICES ] from [ default $LREW_INCLUDE ]"
if (!(Test-Path lnmp-docker-custom-script.ps1)) {
Copy-Item lnmp-docker-custom-script.example.ps1 lnmp-docker-custom-script.ps1
}
printInfo "Exec custom script"
. ./lnmp-docker-custom-script.example.ps1
. ./lnmp-docker-custom-script.ps1
New-InitFile
New-LogFile
docker compose version | out-null
if (!($?)) {
printError "Docker Compose V2 not found, please install, see https://docs.docker.com/compose/install/compose-plugin/"
exit 1
}
if (!((docker compose version).split( )[-1].trim('v') -ge $REQUIRE_DOCKER_COMPOSE_VERSION)) {
printError "your compose version is not ge v$REQUIRE_DOCKER_COMPOSE_VERSION"
exit 1
}
printInfo $(docker compose version)
if ($args.Count -eq 0) {
help_information
}
else {
$command, $other = $args
}
switch -regex ($command) {
lrew-init {
& $PSScriptRoot/lrew/lrew.ps1 init $other
}
lrew-add {
& $PSScriptRoot/lrew/lrew.ps1 add $other
}
lrew-outdated {
& $PSScriptRoot/lrew/lrew.ps1 outdated $other
}
lrew-backup {
& $PSScriptRoot/lrew/lrew.ps1 backup $other
}
lrew-update {
& $PSScriptRoot/lrew/lrew.ps1 update $other
}
httpd-config {
clear
Test-WSL
wsl -d $DistributionName ./lnmp-docker httpd-config $other
}
backup {
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} exec mysql /backup/backup.sh $other
#@custom
__lnmp_custom_backup $other
}
restore {
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} exec mysql /backup/restore.sh $other
#@custom
__lnmp_custom_restore $other
}
"^build$" {
if ($other) {
$services = $other
}
else {
$services = ${LNMP_SERVICES}
}
$options = Get-ComposeOptions "docker-lnmp.yml", `
"docker-lnmp.override.yml"
Write-Host "Build this service image: $services" -ForegroundColor Green
sleep 3
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} $options build $service
}
push {
if ($other) {
$services = $other
}
else {
$services = ${LNMP_SERVICES}
}
$options = Get-ComposeOptions "docker-lnmp.yml", `
"docker-lnmp.override.yml"
Write-Host "Push this service image: $services" -ForegroundColor Green
sleep 3
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} $options push $service
}
cleanup {
cleanup
#@custom
__lnmp_custom_cleanup
}
"^config$" {
New-LogFile
$options = Get-ComposeOptions "docker-lnmp.yml", `
"docker-lnmp.override.yml"
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} $options config $other
}
checkout {
git fetch origin 23.11:23.11 --depth=1
git checkout 23.11
_update
}
services {
${LNMP_SERVICES}
}
"^up$" {
init
if ($other) {
$services = $other
}
else {
$services = ${LNMP_SERVICES}
}
$options = Get-ComposeOptions "docker-lnmp.yml", `
"docker-lnmp.override.yml"
#@custom
__lnmp_custom_pre_up $services
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} $options config > compose-up.yaml
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} $options up --no-build -d $services
#@custom
__lnmp_custom_post_up $services
}
"^pull$" {
if ($other) {
$services = $other
}
else {
$services = ${LNMP_SERVICES}
if ($services.GetType() -eq [String]) {
$services = $services.split(' ')
}
}
$options = Get-ComposeOptions "docker-lnmp.yml", `
"docker-lnmp.override.yml"
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} $options pull $services
#@custom
__lnmp_custom_post_pull
}
"^down$" {
$options = Get-ComposeOptions "docker-lnmp.yml", `
"docker-lnmp.override.yml"
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} down --remove-orphans
#@custom
__lnmp_custom_post_down
}
env {
if ($other) {
notepad.exe $other
exit
}
notepad.exe $LNMP_ENV_FILE
notepad.exe $LNMP_ENV_FILE_PS1
}
new {
clear
Test-WSL
wsl -d $DistributionName ./lnmp-docker new $other
}
nginx-config {
clear
Test-WSL
wsl -d $DistributionName ./lnmp-docker nginx-config $other
}
swarm-config {
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} -f docker-production.yml config
}
swarm-build {
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} -f docker-production.yml build $other
}
swarm-push {
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} -f docker-production.yml push $other
}
restart {
$options = Get-ComposeOptions "docker-lnmp.yml", `
"docker-lnmp.override.yml"
docker compose ${LNMP_COMPOSE_GLOBAL_OPTIONS} $options restart $other
#@custom
__lnmp_custom_restart $other
}
ssl-self {
docker run --init -it --rm `
-v $pwd/config/nginx/ssl-self:/ssl khs1994/tls $other
printInfo `
'Import ./config/nginx/ssl-self/root-ca.crt to Browsers,then set hosts in C:\Windows\System32\drivers\etc\hosts'
}
satis {
satis
}
"-cli$" {
$service = ($command).split("-cli")
if ($other) {
Invoke-DockerExec $service $other
exit
}
Invoke-DockerExec $service sh
}
{ $_ -in "update", "upgrade" } {
_update
}
{ $_ -in "-h", "--help", "help" } {
help_information
}
bug {
$os_info = $($psversiontable.BuildVersion)
if ($os_info.length -eq 0) {
$os_info = $($psversiontable.os)
}
$docker_version = $(docker --version)
$compose_version = $(docker compose version)
$git_commit = $(git log -1 --pretty=%H)
Write-Output "<details>
%0A
<summary>OS Environment Info</summary>
%0A%0A
<code>OS: $os_info</code>
%0A%0A
<code>Docker: $docker_version</code>
%0A%0A
<code>Docker Compose: $compose_version</code>
%0A%0A
<code>LNMP COMMIT: https://github.com/khs1994-docker/lnmp/commit/$git_commit</code>
%0A%0A
</details>
%0A%0A
<details>
%0A%0A
<summary>Console output</summary>
%0A%0A
<!--Don't Edit it-->
%0A
<!--Do not manually edit the above, pleae paste the terminal output to the following-->
%0A%0A
<pre>
%0A
%0A
%0A
%0A
%0A
%0A
%0A
%0A
</pre>
%0A%0A
</details>
%0A%0A
<h2>My Issue is</h2>
%0A
<!--Describe your problem here-->
%0A%0A
XXX
%0A%0A
XXX
%0A%0A
<!--Be sure to click < Preview > Tab before submitting questions-->
" | Out-File bug.md -encoding utf8
# Start-Process -FilePath https://github.com/khs1994-docker/lnmp/issues
Start-Process -FilePath https://github.com/khs1994-docker/lnmp/issues/new?body=$(cat bug.md)
}
zan {
clear
printInfo "Thank You"
Start-Process -FilePath https://zan.khs1994.com
}
donate {
clear
printInfo "Thank You"
Start-Process -FilePath https://zan.khs1994.com
}
fund {
clear
printInfo "Thank You"
Start-Process -FilePath https://zan.khs1994.com
}
pcit-cp {
Copy-PCIT
}
pcit-up {
Copy-PCIT
# if (!(Test-Path ${APP_ROOT}/pcit/public/.env.produnction)){
# cp ${APP_ROOT}/pcit/public/.env.example ${APP_ROOT}/pcit/public/.env.production
# }
if (!(Test-Path lrew/pcit/.env.development)) {
cp lrew/pcit/.env.example lrew/pcit/.env.development
}