-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdockerfile
More file actions
132 lines (111 loc) · 4.27 KB
/
dockerfile
File metadata and controls
132 lines (111 loc) · 4.27 KB
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
# This Dockerfile builds a cross platform docker image of powershell.
# It uses the GitHub releases of powershell core to install powershell
# from tarball.
ARG MAJOR_VERSION
################
## Downloader ##
################
FROM --platform=$BUILDPLATFORM ubuntu:22.04 AS downloader
ARG PWSH_VERSION
ARG TARGETOS
ARG TARGETARCH
ENV TZ=Europe/Berlin
ENV DEBIAN_FRONTEND=noninteractive
# What's going on here?
# - Install curl to download tarball
# - Translate architecture to match powershell architecture
# - Download the powershell '.tar.gz' archive
RUN apt-get update -qq && \
apt-get install -qq --yes curl && \
apt-get clean -qq --yes && \
rm -rf /var/lib/apt/lists/*
RUN case ${TARGETARCH} in \
"amd64") PWSH_ARCH=x64 ;; \
"arm") PWSH_ARCH=arm32 ;; \
*) PWSH_ARCH=${TARGETARCH} ;; \
esac && \
curl --silent --location --output /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-${TARGETOS}-${PWSH_ARCH}.tar.gz
# define the folder we will be installing PowerShell to
ENV POWERSHELL_INSTALL_FOLDER=/opt/microsoft/powershell/${MAJOR_VERSION}
# Create the target folder where powershell will be placed and expand powershell to the target folder
RUN mkdir -p ${POWERSHELL_INSTALL_FOLDER} && \
tar -zxf /tmp/powershell.tar.gz -C ${POWERSHELL_INSTALL_FOLDER}
###########
## Final ##
###########
FROM ubuntu:22.04 AS final
ENV TZ=Europe/Berlin
ENV DEBIAN_FRONTEND=noninteractive
LABEL maintainer="Cedric Ahlers <service.clowa@gmail.com>"
# Upgrade packages and cleanup unused dependencies
RUN apt-get update -qq && \
apt-get full-upgrade -qq --yes && \
apt-get dist-upgrade -qq --yes && \
apt-get autoremove -qq --yes && \
apt-get clean -qq --yes && \
rm -rf /var/lib/apt/lists/*
ENV \
# Define ENVs for Localization/Globalization
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
# Set a fixed location for the Module analysis cache.
# See: https://github.com/PowerShell/PowerShell-Docker/issues/103
PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache \
# Disable powershell telemetry
POWERSHELL_TELEMETRY_OPTOUT=1
# Set locale to en_US.UTF-8
RUN apt-get update -qq && \
apt-get install -qq --yes locales && \
apt-get clean -qq --yes && \
rm -rf /var/lib/apt/lists/* && \
locale-gen ${LANG} && update-locale
# Install additional CA certs.
RUN apt-get update -qq && \
apt-get install -qq --yes ca-certificates && \
apt-get clean -qq --yes && \
rm -rf /var/lib/apt/lists/*
# Install the requirements of powershell / .NET
RUN apt-get update -qq && \
apt-get install -qq --yes --no-install-recommends \
# less is required for help in powershell
less \
# required for SSL
ca-certificates \
gss-ntlmssp \
libc6 \
libgcc1 \
libgcc-s1 \
libgssapi-krb5-2 \
libicu70 \
liblttng-ust1 \
libssl3 \
libstdc++6 \
libunwind8 \
zlib1g \
# PowerShell remoting over SSH dependencies
openssh-client \
# Required by dotnet apps using System.Drawing.Common assembly
libgdiplus && \
# Cleanup stuff
apt-get clean -qq --yes && \
rm -rf /var/lib/apt/lists/*
# Copy only the files we need from the previous stage
COPY --from=downloader ["/opt/microsoft/powershell", "/opt/microsoft/powershell"]
# Give all user execute permissions and remove write permissions for others
RUN chmod a+x,o-w /opt/microsoft/powershell/${MAJOR_VERSION}/pwsh && \
# Create the pwsh symbolic link that points to powershell
ln -s /opt/microsoft/powershell/${MAJOR_VERSION}/pwsh /usr/bin/pwsh && \
# Intialize powershell module cache
# and disable telemetry
export POWERSHELL_TELEMETRY_OPTOUT=1; \
pwsh -NoLogo -NoProfile -Command ' \
$ErrorActionPreference = "Stop"; \
$ProgressPreference = "SilentlyContinue"; \
while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) { \
Write-Host "Waiting for" \$env:PSModuleAnalysisCachePath; \
Start-Sleep -Seconds 6; \
}'
# Set default shell of RUN command to powershell
SHELL ["pwsh", "-command"]
CMD ["pwsh"]