-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
178 lines (153 loc) · 6.95 KB
/
Dockerfile
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
FROM --platform=linux/amd64 ubuntu:22.04
ARG TARGETARCH=x64
ARG AGENT_VERSION=3.240.1
# ARG for optional components, defaults to 1 (enabled), set to 0 to disable
ARG ADD_DOCKER=1
ARG ADD_AZURE_CLI=1
ARG ADD_AWS_CLI=1
ARG ADD_POWERSHELL=1
ARG ADD_AZURE_PWSH_CLI=1
ARG ADD_AWS_PWSH_CLI=1
ARG ADD_KUBECTL=1
ARG ADD_KUBELOGIN=1
ARG ADD_KUSTOMIZE=1
ARG ADD_HELM=1
ARG ADD_YQ=1
ARG ADD_JQ=1
ARG ADD_TERRAFORM=1
ARG ADD_TERRASPACE=1
ARG ADD_SUDO=1
USER root
# To make it easier for build and release pipelines to run apt-get,
# configure apt to not require confirmation (assume the -y argument by default)
ENV DEBIAN_FRONTEND=noninteractive
# Install agent dependencies...
RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes \
&& apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
software-properties-common \
ca-certificates \
curl \
wget \
bzip2 \
zip \
unzip \
xz-utils \
git \
netcat \
iputils-ping \
gss-ntlmssp \
ucf \
debsums \
libcurl4 \
libicu70 \
libunwind8 \
libxcb1 \
libnss3 \
libssl-dev\
libssl3 \
liblttng-ust-common1 \
liblttng-ust-ctl5 \
liblttng-ust1 \
libnuma1 \
libdpkg-perl \
libfile-fcntllock-perl \
libfile-fnmatch-perl \
liblocale-gettext-perl \
&& apt-get upgrade \
&& apt clean
# Install sudo...
RUN test "${ADD_SUDO}" = "1" || exit 0 && \
apt-get install -y --no-install-recommends sudo \
&& apt clean \
&& echo "%agent ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/agent
# Install Docker
RUN test "${ADD_DOCKER}" = "1" || exit 0 && \
apt-get install -y --no-install-recommends docker.io \
&& apt clean
# Install awscli
RUN test "${ADD_AWS_CLI}" = "1" || exit 0 && \
apt-get install -y --no-install-recommends awscli \
&& apt clean
# Install jq
RUN test "${ADD_JQ}" = "1" || exit 0 && \
apt-get install -y --no-install-recommends jq \
&& apt clean
# Install latest Azure CLI https://learn.microsoft.com/cli/azure/install-azure-cli-linux
RUN test "${ADD_AZURE_CLI}" = "1" || exit 0 && \
curl -sLS "https://aka.ms/InstallAzureCLIDeb" | bash \
&& apt clean \
&& az config set extension.use_dynamic_install=yes_without_prompt \
&& az extension add --name azure-devops \
&& az extension add --name resource-graph
# Install latest PowerShell https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-linux
RUN test "${ADD_POWERSHELL}" = "1" || exit 0 && \
curl -sLO "https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb" \
&& dpkg -i packages-microsoft-prod.deb \
&& rm -f packages-microsoft-prod.deb \
&& apt-get update \
&& apt-get install -y powershell \
&& apt clean
# Install latest Azure Powershell Modules https://learn.microsoft.com/powershell/azure/install-azps-linux
RUN test "${ADD_POWERSHELL}" = "1" || exit 0 && \
test "${ADD_AZURE_PWSH_CLI}" = "1" || exit 0 && \
pwsh -Command "[Net.ServicePointManager]::SecurityProtocol=[Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; Install-Module -Name Az -Repository PSGallery -Scope AllUsers -Force;"
# Install AWS Tools for PowerShell (bundle) https://aws.amazon.com/powershell/
RUN test "${ADD_POWERSHELL}" = "1" || exit 0 && \
test "${ADD_AWS_PWSH_CLI}" = "1" || exit 0 && \
pwsh -Command "[Net.ServicePointManager]::SecurityProtocol=[Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; Install-Module -Name AWSPowerShell.NetCore -Repository PSGallery -Scope AllUsers -Force;"
# Install Kubectl - https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
RUN test "${ADD_KUBECTL}" = "1" || exit 0 && \
curl -sLO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
&& install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl \
&& rm -f kubectl
# Install Kubelogin https://github.com/Azure/kubelogin/releases
RUN test "${ADD_KUBELOGIN}" = "1" || exit 0 && \
curl -sLO "https://github.com/Azure/kubelogin/releases/download/v$(curl -sI https://github.com/Azure/kubelogin/releases/latest | grep '^location:' | grep -Eo '[0-9]+[.][0-9]+[.][0-9]+')/kubelogin-linux-amd64.zip" \
&& unzip -j kubelogin-linux-amd64.zip \
&& install -o root -g root -m 0755 kubelogin /usr/local/bin/kubelogin \
&& rm -f kubelogin-linux-amd64.zip kubelogin
# Install YQ - https://github.com/mikefarah/yq
RUN test "${ADD_YQ}" = "1" || exit 0 && \
curl -sLO "https://github.com/mikefarah/yq/releases/download/v$(curl -sI https://github.com/mikefarah/yq/releases/latest | grep '^location:' | grep -Eo '[0-9]+[.][0-9]+[.][0-9]+')/yq_linux_amd64" \
&& install -o root -g root -m 0755 yq_linux_amd64 /usr/local/bin/yq \
&& rm -f yq_linux_amd64
# Install Terraform https://developer.hashicorp.com/terraform/install
RUN test "${ADD_TERRAFORM}" = "1" || exit 0 && \
curl -sL https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/terraform-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/terraform-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/terraform.list \
&& apt update \
&& apt install -y terraform \
&& apt clean
# Instal Terraspace https://terraspace.cloud/docs/install/
RUN test "${ADD_TERRASPACE}" = "1" || exit 0 && \
curl -sL https://apt.boltops.com/boltops-key.public | apt-key add - \
&& echo "deb https://apt.boltops.com stable main" > /etc/apt/sources.list.d/boltops.list \
&& apt-get update \
&& apt-get install -y terraspace \
&& apt clean
# Install HELM https://helm.sh/docs/intro/install/
RUN test "${ADD_HELM}" = "1" || exit 0 && \
curl -sL https://baltocdn.com/helm/signing.asc | gpg --dearmor -o /usr/share/keyrings/helm.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" > /etc/apt/sources.list.d/helm-stable-debian.list \
&& apt-get update \
&& apt-get install helm \
&& apt clean
# Install Kustomize https://kubectl.docs.kubernetes.io/installation/kustomize/
RUN test "${ADD_KUSTOMIZE}" = "1" || exit 0 && \
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash \
&& install -o root -g root -m 0755 kustomize /usr/local/bin/kustomize \
&& rm -f kustomize
# Install Azure DevOps Agent
WORKDIR /azp
RUN curl -LsS "https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/vsts-agent-linux-${TARGETARCH}-${AGENT_VERSION}.tar.gz" | tar -xz \
&& ./bin/installdependencies.sh
# Agent Startup script
COPY --chmod=0755 ./start.sh .
# Create agent user and set up home directory
RUN useradd -m -d /home/agent agent \
&& chown -R agent:agent /azp /home/agent
USER agent
# Option to run the agent as root or not.
ENV AGENT_ALLOW_RUNASROOT="false"
ENTRYPOINT [ "./start.sh" ]