자바스크립트를 활성화 해주세요

p017 Internal PowerShell Gallery운영하기(1)

 ·  ☕ 2 min read

local이나 Internal Network에 PowerShell Gallery를 설치해서 Publish-Module이나 Install-Module을 하는 방법을 설명합니다.

PowerShellGet 모듈 설치

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
root@goorm:~# pwsh
PowerShell 7.0.3
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS /root> install-module PowerShellGet

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A

모듈 확인

PowerShellGet 모듈이 잘 설치되었는 지 확인합니다.

1
2
3
4
5
6
7
PS /root> get-module PowerShellGet

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.2.4.1               PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability}

PS /root>

등록

Register-PSRepository 명령을 사용해서 레포지토리를 등록합니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$Path = '/workspace/pwsh/PowerShellGetRepository'

Import-Module PowerShellGet

$repo = @{
    Name = 'MyRepository'
    SourceLocation = $Path
    PublishLocation = $Path
    InstallationPolicy = 'Trusted'
}
Register-PSRepository @repo

확인

다음과 같이 로컬 path에 Repository가 생성되어 있음을 확인할 수 있습니다.

1
2
3
4
5
6
7
8
PS /workspace/pwsh> mkdir PowerShellGetRepository

PS /workspace/pwsh/PowerShellGetRepository> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
MyRepository              Trusted              /workspace/pwsh/PowerShellGetRepository

하지만 모두가 공개된 path에 파일시스템으로 접근하는것은 그다지 좋은 아이디어는 아닌 것 같습니다. path가 바뀔 수도 있고, 보안상의 문제도 있을 수 있습니다. 그래서 Private Nuget 서비스를 제공하는 repository를 사용하는 방법이 제일 많이 쓰이지만, 설정이 단순하지는 않습니다. 단순화 하는 스크립트가 있으면 좋겠네요.

레퍼런스

공유하기

tkim
글쓴이
tkim
Software Engineer