23
23
(this does nothing, but most likely will be used in the future)
24
24
#>
25
25
using namespace ' mcr.microsoft.com/powershell AS powerShell'
26
- using namespace ' ruby:3.3.5-slim-bullseye AS jekyllrb'
27
26
28
27
param (
29
28
# The name of the module to be installed.
@@ -37,60 +36,76 @@ param(
37
36
}
38
37
),
39
38
# The packages to be installed.
40
- [string []]$InstallPackages = @ (
41
- if ($env: InstallPackages ) { $env: InstallPackages -split ' ,' }
42
- ),
39
+ [string []]$InstallAptGet = @ ($env: InstallAptGet -split ' ,' ),
43
40
# The modules to be installed.
44
- [string []]$InstallModules = @ (
45
- if ($env: InstallModules ) { $env: InstallModules -split ' ,' }
46
- else { }
47
- )
48
- )
41
+ [string []]$InstallModule = @ ($env: InstallModule -split ' ,' ),
42
+ # The Ruby gems to be installed.
43
+ [string []]$InstallRubyGem = @ ($env: InstallRubyGem -split ' ,' ),
49
44
50
-
51
- # Get the root module directory
52
- $rootModuleDirectory = @ ($env: PSModulePath -split ' [;:]' )[0 ]
53
-
54
- # Determine the path to the module destination.
55
- $moduleDestination = " $rootModuleDirectory /$ModuleName "
56
- # Copy the module to the destination
57
- # (this is being used instead of the COPY statement in Docker, to avoid additional layers).
58
- Copy-Item - Path " $psScriptRoot " - Destination $moduleDestination - Recurse - Force
45
+ # If set, will keep the .git directories.
46
+ [switch ]$KeepGit = $ ($env: KeepGit -match $true )
47
+ )
59
48
60
49
# Copy all container-related scripts to the root of the container.
61
50
Get-ChildItem - Path $PSScriptRoot |
62
51
Where-Object Name -Match ' ^Container\..+?\.ps1$' |
63
52
Copy-Item - Destination /
64
53
65
- # If we have packages to install
66
- if ($InstallPackages ) {
67
- # install the packages
68
- apt- get update && apt- get install - y @InstallPackages ' --no-install-recommends' && apt- get clean | Out-Host
69
- }
54
+ # Create a profile
55
+ New-Item - Path $Profile - ItemType File - Force | Out-Null
56
+
57
+ if ($ModuleName ) {
58
+ # Get the root module directory
59
+ $rootModuleDirectory = @ ($env: PSModulePath -split ' [;:]' )[0 ]
60
+
61
+ # Determine the path to the module destination.
62
+ $moduleDestination = " $rootModuleDirectory /$ModuleName "
63
+ # Copy the module to the destination
64
+ # (this is being used instead of the COPY statement in Docker, to avoid additional layers).
65
+ Copy-Item - Path " $psScriptRoot " - Destination $moduleDestination - Recurse - Force
70
66
71
- # Create a new profile
72
- New-Item - Path $Profile - ItemType File - Force |
73
67
# and import this module in the profile
74
- Add-Content - Value " Import-Module $ModuleName " - Force
68
+ Add-Content - Path $profile - Value " Import-Module $ModuleName " - Force
69
+ }
70
+
75
71
# If we have modules to install
76
- if ($InstallModules ) {
72
+ if ($InstallModule ) {
77
73
# Install the modules
78
- Install-Module - Name $InstallModules - Force - AcceptLicense - Scope CurrentUser
74
+ Install-Module - Name $InstallModule - Force - AcceptLicense - Scope CurrentUser
79
75
# and import them in the profile
80
- Add-Content - Path $Profile - Value " Import-Module '$ ( $InstallModules -join " ','" ) '" - Force
76
+ Add-Content - Path $Profile - Value " Import-Module '$ ( $InstallModule -join " ','" ) '" - Force
77
+ }
78
+
79
+ # If we have packages to install
80
+ if ($InstallAptGet ) {
81
+ # install the packages
82
+ apt- get update &&
83
+ apt- get install - y @InstallAptGet ' --no-install-recommends' &&
84
+ apt- get clean |
85
+ Out-Host
81
86
}
82
- # In our profile, push into the module's directory
83
- Add-Content - Path $Profile - Value " Get-Module $ModuleName | Split-Path | Push-Location" - Force
84
87
85
- # Remove the .git directories from any modules
86
- Get-ChildItem - Path $rootModuleDirectory - Directory - Force - Recurse |
87
- Where-Object Name -eq ' .git' |
88
- Remove-Item - Recurse - Force
88
+ if ($InstallRubyGem ) {
89
+ # Install the Ruby gems
90
+ gem install @InstallRubyGem
91
+ }
92
+
93
+ if ($ModuleName ) {
94
+ # In our profile, push into the module's directory
95
+ Add-Content - Path $Profile - Value " Get-Module $ModuleName | Split-Path | Push-Location" - Force
96
+ }
97
+
98
+ if (-not $KeepGit ) {
99
+ # Remove the .git directories from any modules
100
+ Get-ChildItem - Path $rootModuleDirectory - Directory - Force - Recurse |
101
+ Where-Object Name -eq ' .git' |
102
+ Remove-Item - Recurse - Force
103
+ }
89
104
90
105
# Congratulations! You have successfully initialized the container image.
91
106
# This script should work in about any module, with minor adjustments.
92
107
# If you have any adjustments, please put them below here, in the `#region Custom`
93
108
94
109
# region Custom
95
- gem install jekyll
110
+ bundle config -- global silence_root_warning true
96
111
# endregion Custom
0 commit comments