Skip to content

Commit eccc33a

Browse files
authored
docker enablement (#193)
1 parent ba66678 commit eccc33a

File tree

6 files changed

+61
-9
lines changed

6 files changed

+61
-9
lines changed

.github/workflows/cd.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
- uses: actions/checkout@v2
1212
with:
1313
token: ${{ secrets.CD_TOKEN }}
14+
1415
- name: Update psd version
1516
shell: pwsh
1617
run: |
@@ -26,13 +27,15 @@ jobs:
2627
"New version: $newVersion"
2728
# set version to be used in later steps
2829
"module_new_version=$newVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
30+
2931
- name: Update changelog
3032
shell: pwsh
3133
run: |
3234
$newVersionString = '## ${{ env.module_new_version }}'
3335
$releaseNotes = Get-Content -Path '${{ github.workspace }}/RELEASE.md' -Raw
3436
$changelog = Get-Content -Path '${{ github.workspace }}/CHANGELOG.md' -Raw
3537
Set-Content -Path '${{ github.workspace }}/CHANGELOG.md' -Value ($newVersionString + "`r`n" + $releaseNotes + "`r`n`r`n" + $changelog)
38+
3639
- name: Update repo
3740
run: |
3841
git config --global user.name 'Greg Brownstein'
@@ -42,14 +45,33 @@ jobs:
4245
git status
4346
git commit -m "Update manifest to ${{ env.module_new_version }}"
4447
git push
48+
4549
- name: Create GitHub release
4650
if: github.ref == 'refs/heads/master'
4751
uses: softprops/action-gh-release@v1
4852
with:
4953
tag_name: v${{ env.module_new_version }}
5054
body_path: ${{ github.workspace }}/RELEASE.md
55+
5156
- name: Publish
5257
if: github.ref == 'refs/heads/master'
5358
shell: pwsh
5459
run: |
5560
Publish-Module -Path "${{ github.workspace }}/${{ env.module_name }}" -NuGetApiKey ${{ secrets.NUGET_KEY }} -Verbose
61+
62+
- name: Login to dockerhub
63+
uses: docker/login-action@v2
64+
with:
65+
username: ${{ secrets.DOCKER_USERNAME }}
66+
password: ${{ secrets.DOCKER_PASSWORD }}
67+
68+
- name: Build image
69+
run: >
70+
docker build
71+
--pull
72+
-t ${{ secrets.DOCKER_USERNAME }}/servicenow-module:latest
73+
-t ${{ secrets.DOCKER_USERNAME }}/servicenow-module:${{ env.module_new_version }}
74+
.
75+
76+
- name: Publish image and tags
77+
run: docker push --all-tags ${{ secrets.DOCKER_USERNAME }}/servicenow-module

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM mcr.microsoft.com/powershell:latest
2+
3+
RUN pwsh -Command 'Set-PSRepository PSGallery -InstallationPolicy Trusted; Install-Module ServiceNow -ErrorAction Stop'
4+
5+
ENV SNOW_SERVER=${SNOW_SERVER}
6+
ENV SNOW_TOKEN=${SNOW_TOKEN}
7+
ENV SNOW_USER=${SNOW_USER}
8+
ENV SNOW_PASS=${SNOW_PASS}
9+
ENV POWERSHELL_TELEMETRY_OPTOUT=1
10+
11+
SHELL ["pwsh"]

RELEASE.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
- Fix `Get-ServiceNowAttachment` returning 0 records when the table name didn't match the table class name, [#188](https://github.com/Snow-Shell/servicenow-powershell/issues/188)
2-
- Update `Add-ServiceNowAttachment` `-Table` and `-ID` parameters with the same 'smarts' as other functions with table name lookup
1+
- Add docker image with each new build and [publish to dockerhub](https://hub.docker.com/repository/docker/gdbarron/servicenow-module). Add the below environment variables to `Get-ServiceNowAuth` for use with docker image, but could be used outside of it as well.
2+
- SNOW_SERVER: the ServiceNow instance, eg. instance.service-now.com
3+
- SNOW_TOKEN: pre-generated oauth token. Provide this or SNOW_USER/SNOW_PASS.
4+
- SNOW_USER: username to connect to SNOW_SERVER
5+
- SNOW_PASS: password for SNOW_USER

Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ Requires authorization in your ServiceNow tenant. Due to the custom nature of S
2222

2323
The ServiceNow module should be installed from the [PowerShell Gallery](https://www.powershellgallery.com/packages/ServiceNow) with `install-module ServiceNow`.
2424

25+
A [docker image](https://hub.docker.com/repository/docker/gdbarron/servicenow-module) is also available with [Microsoft's PowerShell base image](https://hub.docker.com/_/microsoft-powershell) and the ServiceNow module preinstalled. The following environment variables should be used:
26+
- SNOW_SERVER: the ServiceNow instance, eg. instance.service-now.com
27+
- SNOW_TOKEN: pre-generated oauth token. Provide this or SNOW_USER/SNOW_PASS.
28+
- SNOW_USER: username to connect to SNOW_SERVER
29+
- SNOW_PASS: password for SNOW_USER
30+
31+
When using the docker image, creating a new session is not required.
32+
2533
### Creating a new session
2634

2735
Creating a new session will create a script scoped variable `$ServiceNowSession` which will be used by default in other functions.

ServiceNow/Private/Get-ServiceNowAuth.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,35 @@ function Get-ServiceNowAuth {
3535
$hashOut.Headers = @{
3636
'Authorization' = 'Bearer {0}' -f $ServiceNowSession.AccessToken.GetNetworkCredential().password
3737
}
38-
}
39-
else {
38+
} else {
4039
$hashOut.Credential = $ServiceNowSession.Credential
4140
}
4241

4342
if ( $ServiceNowSession.Proxy ) {
4443
$hashOut.Proxy = $ServiceNowSession.Proxy
4544
if ( $ServiceNowSession.ProxyCredential ) {
4645
$hashOut.ProxyCredential = $ServiceNowSession.ProxyCredential
47-
}
48-
else {
46+
} else {
4947
$hashOut.ProxyUseDefaultCredentials = $true
5048
}
5149
}
52-
}
53-
elseif ( $Connection ) {
50+
} elseif ( $Connection ) {
5451
Write-Verbose 'connection'
5552
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
5653
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
5754
$hashOut.Credential = $Credential
5855
$hashOut.Uri = 'https://{0}/api/now/v1' -f $Connection.ServiceNowUri
56+
} elseif ( $env:SNOW_SERVER ) {
57+
$hashOut.Uri = 'https://{0}/api/now' -f $env:SNOW_SERVER
58+
if ( $env:SNOW_TOKEN ) {
59+
$hashOut.Headers = @{
60+
'Authorization' = 'Bearer {0}' -f $env:SNOW_TOKEN
61+
}
62+
} elseif ( $env:SNOW_USER -and $env:SNOW_PASS ) {
63+
$hashOut.Credential = New-Object System.Management.Automation.PSCredential($env:SNOW_USER, ($env:SNOW_PASS | ConvertTo-SecureString -AsPlainText -Force))
64+
} else {
65+
throw 'A ServiceNow server environment variable has been set, but authentication via SNOW_TOKEN or SNOW_USER/SNOW_PASS was not found'
66+
}
5967
} else {
6068
throw "You must authenticate by either calling the New-ServiceNowSession cmdlet or passing in an Azure Automation connection object"
6169
}

ServiceNow/ServiceNow.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'ServiceNow.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '3.2.0'
15+
ModuleVersion = '3.3'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

0 commit comments

Comments
 (0)