This repository has been archived by the owner on Aug 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Dockerfile
351 lines (317 loc) · 12.2 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
###########################################################
# base tools and dependencies
###########################################################
FROM ubuntu:21.04 as base
SHELL ["/bin/bash", "-c"]
# Arguments set during docker-compose build -b --build from .env file
ARG versionAzureCli
ARG versionKubectl
ARG versionTflint
ARG versionGit
ARG versionJq
ARG versionDockerCompose
ARG versionTfsec
ARG versionAnsible
ARG versionPacker
ARG versionCheckov
ARG versionMssqlTools
ARG versionTerraformDocs
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=${USER_UID}
ARG SSH_PASSWD
ENV SSH_PASSWD=${SSH_PASSWD} \
USERNAME=${USERNAME} \
versionAzureCli=${versionAzureCli} \
versionKubectl=${versionKubectl} \
versionTflint=${versionTflint} \
versionJq=${versionJq} \
versionGit=${versionGit} \
versionDockerCompose=${versionDockerCompose} \
versionTfsec=${versionTfsec} \
versionAnsible=${versionAnsible} \
versionPacker=${versionPacker} \
versionCheckov=${versionCheckov} \
versionMssqlTools=${versionMssqlTools} \
versionTerraformDocs=${versionTerraformDocs} \
PATH="${PATH}:/opt/mssql-tools/bin:/home/vscode/.local/lib/shellspec/bin:/home/vscode/go/bin" \
TF_DATA_DIR="/home/${USERNAME}/.terraform.cache" \
TF_PLUGIN_CACHE_DIR="/home/${USERNAME}/.terraform.cache/plugin-cache" \
LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8 \
DEBIAN_FRONTEND=noninteractive
WORKDIR /tf/rover
COPY ./.pip_to_patch_latest .
# installation common tools
RUN apt-get update && \
apt-get install -y \
curl \
ca-certificates \
apt-transport-https \
gettext \
software-properties-common \
unzip \
zip \
make \
sudo \
locales \
vim \
gpg \
apt-utils \
gpg-agent \
bsdmainutils && \
#
# Create USERNAME
#
echo "Creating ${USERNAME} user..." && \
groupadd docker && \
useradd --uid $USER_UID -m -G docker ${USERNAME} && \
#
# Set the locale
locale-gen en_US.UTF-8
#
# ############### APT Repositories ###################
#
# Add Microsoft key
#
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg && \
#
# Add Microsoft repository
#
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/msprod.list && \
curl https://packages.microsoft.com/config/ubuntu/21.04/prod.list >> /etc/apt/sources.list.d/msprod.list && \
#
# Add Docker repository
#
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg && \
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu hirsute stable" > /etc/apt/sources.list.d/docker.list && \
#
# Add Terraform repository
#
curl -fsSL https://apt.releases.hashicorp.com/gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/hashicorp-archive-keyring.gpg && \
echo "deb [arch=amd64] https://apt.releases.hashicorp.com hirsute main" > /etc/apt/sources.list.d/hashicorp.list && \
#
# Kubernetes repo
#
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg && \
echo "deb [arch=amd64] https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list && \
#
apt-get update
#
# ################# Install binary clients ###################
#
#
# Install Docker-Compose - required to rebuild the rover
#
RUN echo "Installing docker-compose ${versionDockerCompose}..." && \
curl -L -o /usr/bin/docker-compose "https://github.com/docker/compose/releases/download/${versionDockerCompose}/docker-compose-Linux-x86_64" && \
chmod +x /usr/bin/docker-compose && \
#
# Install Helm
#
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash && \
#
# Install tflint
#
echo "Installing tflint ${versionTflint}..." && \
curl -sSL -o /tmp/tflint.zip https://github.com/terraform-linters/tflint/releases/download/v${versionTflint}/tflint_linux_amd64.zip && \
unzip -d /usr/bin /tmp/tflint.zip && \
chmod +x /usr/bin/tflint && \
#
# Install tfsec
#
echo "Installing tfsec ${versionTfsec} ..." && \
curl -sSL -o /bin/tfsec https://github.com/tfsec/tfsec/releases/download/v${versionTfsec}/tfsec-linux-amd64 && \
chmod +x /bin/tfsec && \
#
# Install terraform docs
#
echo "Installing terraform docs ${versionTerraformDocs}..." && \
curl -sSL -o /tmp/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v${versionTerraformDocs}/terraform-docs-v${versionTerraformDocs}-linux-amd64.tar.gz && \
tar -zxf /tmp/terraform-docs.tar.gz --directory=/usr/bin && \
chmod +x /usr/bin/terraform-docs && \
#
# Install bash completions for git
#
echo "Installing bash completions for git" && \
mkdir -p /etc/bash_completion.d/ && \
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o /etc/bash_completion.d/git-completion.bash && \
#
# kubectl node shell
#
curl -L0 -o /usr/local/bin/kubectl-node_shell https://github.com/kvaps/kubectl-node-shell/raw/master/kubectl-node_shell && \
chmod +x /usr/local/bin/kubectl-node_shell
#
# ################# Install PIP clients ###################
#
RUN apt-get install -y python3-pip && \
#
# Install pre-commit
#
echo "Installing pre-commit ..." && \
pip3 install pre-commit && \
#
# Install yq
#
echo "Installing yq ..." && \
pip3 install yq && \
#
# Install Azure-cli
#
pip3 install azure-cli==${versionAzureCli} && \
#
# Install checkov
#
echo "Installing Checkov ${versionCheckov} ..." && \
pip3 install checkov==${versionCheckov} && \
#
# Install pywinrm
#
pip3 install pywinrm && \
#
# Clean-up
#
pip3 cache purge
#
# ################ Install apt packages ##################
#
RUN ACCEPT_EULA=Y apt-get install -y --no-install-recommends \
mssql-tools=${versionMssqlTools}-1
#
RUN apt-get install -y --no-install-recommends \
kubectl=${versionKubectl}-00
RUN apt-get install -y --no-install-recommends \
packer=${versionPacker}
# RUN apt-get install -y --no-install-recommends \
# vault
RUN apt-get install -y --no-install-recommends \
docker-ce-cli
RUN apt-get install -y --no-install-recommends \
golang
RUN apt-get install -y --no-install-recommends \
git=${versionGit}
RUN apt-get install -y --no-install-recommends \
ansible=${versionAnsible}
RUN apt-get install -y --no-install-recommends \
openssh-server
RUN apt-get install -y --no-install-recommends \
fonts-powerline
RUN apt-get install -y --no-install-recommends \
jq=${versionJq}
RUN apt-get install -y --no-install-recommends \
powershell && \
pwsh -Command Install-Module -name Az.DesktopVirtualization -Force && \
pwsh -Command Install-Module -name Az.Resources -Force
#
# Patch
# to regenerate the list - pip3 list --outdated --format=columns |tail -n +3|cut -d" " -f1 > pip_to_patch_latest
#
# for i in $(cat .pip_to_patch_latest); do pip3 install $i --upgrade; done && \
# apt-get upgrade -y && \
# Clean-up
#
# apt-get remove -y \
# apt-utils && \
# apt-get autoremove -y && \
# rm -f /tmp/*.zip && rm -f /tmp/*.gz && \
# rm -rf /var/lib/apt/lists/*
#
# Create USERNAME home folder structure
#
RUN mkdir -p /tf/caf \
/tf/rover \
/tf/logs \
/home/${USERNAME}/.ansible \
/home/${USERNAME}/.azure \
/home/${USERNAME}/.gnupg \
/home/${USERNAME}/.packer.d \
/home/${USERNAME}/.ssh \
/home/${USERNAME}/.ssh-localhost \
/home/${USERNAME}/.terraform.logs \
/home/${USERNAME}/.terraform.cache \
/home/${USERNAME}/.terraform.cache/tfstates \
/home/${USERNAME}/.vscode-server \
/home/${USERNAME}/.vscode-server-insiders && \
chown -R ${USER_UID}:${USER_GID} /home/${USERNAME} /tf/rover /tf/caf /tf/logs && \
chmod 777 -R /home/${USERNAME} /tf/caf /tf/rover && \
chmod 700 /home/${USERNAME}/.ssh && \
echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME} && \
# for non-root user
mkdir /commandhistory && \
touch /commandhistory/.bash_history && \
chown -R ${USERNAME} /commandhistory && \
echo "set -o history" >> "/home/${USERNAME}/.bashrc" && \
echo "export HISTCONTROL=ignoredups:erasedups" >> "/home/${USERNAME}/.bashrc" && \
echo "PROMPT_COMMAND=\"${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r\"" >> "/home/${USERNAME}/.bashrc" && \
echo "[ -f /tf/rover/.kubectl_aliases ] && source /tf/rover/.kubectl_aliases" >> "/home/${USERNAME}/.bashrc" && \
echo "alias watch=\"watch \"" >> "/home/${USERNAME}/.bashrc"
#
# Switch to non-root ${USERNAME} context
#
USER ${USERNAME}
COPY .devcontainer/.zshrc $HOME
#
# ssh server for Azure ACI
#
RUN ssh-keygen -q -N "" -t ecdsa -b 521 -f /home/${USERNAME}/.ssh/ssh_host_ecdsa_key && \
sudo apt-get update && \
sudo apt-get install -y \
zsh && \
#
# Install Oh My Zsh
#
# chsh -s /bin/zsh ${USERNAME} && \
sudo runuser -l ${USERNAME} -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended' && \
chmod 700 -R /home/${USERNAME}/.oh-my-zsh && \
echo "alias rover=/tf/rover/rover.sh" >> /home/${USERNAME}/.bashrc && \
echo "alias rover=/tf/rover/rover.sh" >> /home/${USERNAME}/.zshrc && \
echo "alias t=/usr/bin/terraform" >> /home/${USERNAME}/.bashrc && \
echo "alias t=/usr/bin/terraform" >> /home/${USERNAME}/.zshrc && \
echo "alias k=/usr/bin/kubectl" >> /home/${USERNAME}/.zshrc && \
echo "alias k=/usr/bin/kubectl" >> /home/${USERNAME}/.bashrc && \
echo "[ -f /tf/rover/.kubectl_aliases ] && source /tf/rover/.kubectl_aliases" >> /home/${USERNAME}/.zshrc && \
echo "source /tf/rover/zsh-autosuggestions.zsh" >> /home/${USERNAME}/.zshrc && \
echo "alias watch=\"watch \"" >> /home/${USERNAME}/.zshrc
FROM base
ARG versionTerraform
ARG versionVault
ARG USERNAME=vscode
ARG versionRover
ARG versionTflintazrs
ENV versionRover=${versionRover} \
versionVault=${versionVault} \
versionTerraform=${versionTerraform} \
versionTflintazrs=${versionTflintazrs}
#
# Install Terraform
#
# Keeping this method to support alpha build installations
RUN echo "Installing Terraform ${versionTerraform}..." && \
curl -sSL -o /tmp/terraform.zip https://releases.hashicorp.com/terraform/${versionTerraform}/terraform_${versionTerraform}_linux_amd64.zip 2>&1 && \
sudo unzip -d /usr/bin /tmp/terraform.zip && \
sudo chmod +x /usr/bin/terraform && \
mkdir -p /home/${USERNAME}/.terraform.cache/plugin-cache && \
rm /tmp/terraform.zip && \
#
echo ${versionRover} > /tf/rover/version.txt
RUN echo "Installing Vault ${versionVault}..." && \
curl -sSL -o /tmp/vault.zip https://releases.hashicorp.com/vault/${versionVault}/vault_${versionVault}_linux_amd64.zip 2>&1 && \
sudo unzip -d /usr/bin /tmp/vault.zip && \
sudo chmod +x /usr/bin/vault && \
sudo setcap cap_ipc_lock=-ep /usr/bin/vault && \
rm /tmp/vault.zip
RUN echo "Installing Tflint Ruleset ${versionTflintazrs} for Azure..." && \
curl -sSL -o /tmp/tflint-ruleset-azurerm.zip https://github.com/terraform-linters/tflint-ruleset-azurerm/releases/download/v${versionTflintazrs}/tflint-ruleset-azurerm_linux_amd64.zip 2>&1 && \
mkdir -p /home/${USERNAME}/.tflint.d/plugins && \
mkdir -p /home/${USERNAME}/.tflint.d/config && \
echo "plugin \"azurerm\" {" > /home/${USERNAME}/.tflint.d/config/.tflint.hcl && \
echo " enabled = true" >> /home/${USERNAME}/.tflint.d/config/.tflint.hcl && \
echo "}" >> /home/${USERNAME}/.tflint.d/config/.tflint.hcl && \
sudo unzip -d /home/${USERNAME}/.tflint.d/plugins /tmp/tflint-ruleset-azurerm.zip && \
rm /tmp/tflint-ruleset-azurerm.zip
RUN echo "Installing shellspec..." && \
curl -fsSL https://git.io/shellspec | sh -s -- --yes
RUN echo "Installing caflint..." && \
go install github.com/aztfmod/caflint@latest