This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
.envrc
358 lines (317 loc) · 10.3 KB
/
.envrc
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
352
353
354
355
356
357
358
#
# Commands dependencies
# =====================
#
DIRENV_CMD_DEPENDENCIES="unzip tar mkdir curl chmod rm"
for mandatory_cmd in ${DIRENV_CMD_DEPENDENCIES}; do
if [ -z "$(which ${mandatory_cmd})" ]; then
echo "===> Mandatory command not found: ${mandatory_cmd}"
exit 1
fi
done
#
# Ruby configuration
# =====================
#
layout ruby
#use ruby 3.0.2
#direnv_load brew bundle exec -- direnv dump
#direnv_load brew bundle
#
# Node configuration
# =====================
#
export NODE_VERSIONS="v20.15.0"
if [ -f ".nvmrc" ]; then
#
# Nvm installation
# ==========================
#
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
NVM_VERSION=${NVM_VERSION:-"v0.39.7"}
NVM_PKG_URL="https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh"
if [ ! -e "${HOME}/.nvm/nvm.sh" ]; then
echo "===> Getting nvm:${NVM_VERSION} (can take a while to execute)"
curl -s -L "${NVM_PKG_URL}" | bash
echo "nvm install ${NODE_VERSIONS}"
nvm install ${NODE_VERSIONS}
fi
source "${HOME}/.nvm/nvm.sh"
# nvm use ${NODE_VERSIONS}
fi
layout_node
# Either use node version specified in package.json
#use node package.json
#
# Other configuration
# =====================
#
#sudo apt install openjdk-11-dbg
#sudo update-java-alternatives -s java-1.11.0-openjdk-amd64
export DIRENV_TMP_DIR="${PWD}/.direnv"
export DIRENV_BIN_DIR="${DIRENV_TMP_DIR}/bin"
if [ ! -e "${DIRENV_BIN_DIR}" ]; then
mkdir -p "${DIRENV_BIN_DIR}"
fi
export PATH="${DIRENV_BIN_DIR}:${PATH}"
#
# Python configuration
# =====================
#
export PYTHON_VERSION=${PYTHON_VERSION:-"3.11.6"}
#
# Python pyenv installation
# ==========================
#
PYENV_PKG_URL="https://pyenv.run"
if [ ! -e "${HOME}/.pyenv/bin/pyenv" ]; then
echo "===> Getting pyenv (can take a while to execute)"
curl -s -L "${PYENV_PKG_URL}" | bash
echo "===> Run : pyenv init"
echo "===> Run : pyenv local ${PYTHON_VERSION}"
fi
#
# Python 2 requirements
# ==========================
#
if command -v pyenv; then
for VERSION in $(pyenv versions --bare | egrep '^2.'); do
pyenv shell ${VERSION}
pip install py2venv
done
fi
export VENV_TMP_DIR="${PWD}/.venv"
export VENV_BIN_DIR="${VENV_TMP_DIR}/bin"
# check if python version is set in current dir
# .python-version will be created by : pyenv local ${PYTHON_VERSION}
if [ -f ".python-version" ]; then
if [ ! -d "${VENV_TMP_DIR}" ]; then
echo "Installing virtualenv for $(cat .python-version)"
# if we didn't install `py2venv` for python 2.x, we would need to use
# `virtualenv`, which you would have to install separately.
python -m venv ${VENV_TMP_DIR}
fi
echo "Activating $(cat .python-version) virtualenv"
source ${VENV_BIN_DIR}/activate
# announce python version and show the path of the current python in ${PATH}
echo "Virtualenv has been activated for $(cat .python-version)"
#echo "$(which python)"
fi
if command -v pyenv >/dev/null 2>&1; then
# layout pyenv ${PYTHON_VERSION}
layout pyenv
else
layout_python3
# layout_anaconda
fi
#
# Direnv configuration
# =====================
#
DIRENV_PYTHON_LIBS_DIR_RELATIVE="$(find ${DIRENV_TMP_DIR} -type d -name site-packages)"
# python package are in venv
if [ ! -e "${DIRENV_PYTHON_LIBS_DIR_RELATIVE}" ]; then
DIRENV_PYTHON_LIBS_DIR_RELATIVE="$(find ${VENV_TMP_DIR} -type d -name site-packages)"
fi
export DIRENV_PYTHON_LIBS_DIR="$(realpath ${DIRENV_PYTHON_LIBS_DIR_RELATIVE})"
if command -v pyenv >/dev/null 2>&1; then
#
# Python pip requirements
# ==========================
#
for VERSION in $(pyenv versions --bare | egrep '^2.'); do
pyenv shell ${VERSION} 2>/dev/null
pip install py2venv
done
#
# Python pip upgrade
# ==========================
#
# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
for VERSION in $(pyenv versions --bare); do
pyenv shell ${VERSION} 2>/dev/null
pip install --upgrade pip
done
fi
# if pyenv and venv
if [ -f ".python-version" ]; then
#
# Python pipenv installation
# ==========================
#
# python -m pip install pipenv==2023.7.23
PIPENV_VERSION=${PIPENV_VERSION:-"2023.7.23"}
if [ ! -e "${VENV_BIN_DIR}/pipenv" ]; then
echo "===> Getting pipenv:${PIPENV_VERSION} (can take a while to execute)"
python -m pip install pipenv=="${PIPENV_VERSION}"
fi
#
# Python 3 requirements
# ==========================
#
#python -m pip install -r ansible/requirements.txt -r requirements.txt
python -m pipenv install --dev --site-packages --ignore-pipfile 2>/dev/null
#
# Below install what you do not have already in Pipfile.lock or requirements.txt
# ==========================
#
# Python pre-commit installation
# ==========================
#
# python -m pip install pre-commit==3.7.1
PRECOMMIT_VERSION=${PRECOMMIT_VERSION:-"3.7.1"}
if [ ! -e "${VENV_BIN_DIR}/pre-commit" ]; then
echo "===> Getting pre-commit:${PRECOMMIT_VERSION} (can take a while to execute)"
python -m pip install pre-commit=="${PRECOMMIT_VERSION}" # nosemgrep
fi
pre-commit install 2>/dev/null || true
#
# Ansible CLI installation
# ==========================
#
# python -m pip install --user https://github.com/ansible/ansible/archive/stable-2.16.tar.gz
ANSIBLE_VERSION=${ANSIBLE_VERSION:-"2.16"}
ANSIBLE_PKG_URL="https://github.com/ansible/ansible/archive/stable-${ANSIBLE_VERSION}.tar.gz"
if [ ! -e "${VENV_BIN_DIR}/ansible" ]; then
echo "===> Getting ansible:${ANSIBLE_VERSION} (can take a while to execute)"
python -m pip install "${ANSIBLE_PKG_URL}"
fi
#
# Ansible configuration
# =====================
#
# export ANSIBLE_LIBRARY="${PWD}/plugins/modules:${ANSIBLE_LIBRARY}"
unset ANSIBLE_LIBRARY
#export ANSIBLE_SSH_ARGS="-F ${PWD}/ssh.cfg"
#export ANSIBLE_INVENTORY="hosts"
export ANSIBLE_COLLECTIONS_PATHS="${DIRENV_TMP_DIR}"
fi
#
# Terraform CLI installation
# ==========================
#
TF_VERSION=${TF_VERSION:-"1.7.5"}
TF_ARCH="linux_amd64"
TF_PKG_NAME="terraform_${TF_VERSION}_${TF_ARCH}.zip"
TF_PKG_URL="https://releases.hashicorp.com/terraform/${TF_VERSION}/${TF_PKG_NAME}"
TF_PKG_PATH="${DIRENV_TMP_DIR}/${TF_PKG_NAME}"
if [ ! -e "${DIRENV_BIN_DIR}/terraform" ]; then
echo "===> Getting terraform:${TF_VERSION}:${TF_ARCH} (can take a while to execute)"
curl -s -L "${TF_PKG_URL}" -o "${TF_PKG_PATH}"
unzip ${TF_PKG_PATH} -d ${DIRENV_BIN_DIR}
chmod 700 ${DIRENV_BIN_DIR}/terraform
rm -f ${TF_PKG_PATH}
fi
#
# Terraform CLI configuration
# ==========================
#
export TF_PLUGIN_CACHE_DIR="${DIRENV_TMP_DIR}/terraform-plugin-cache"
if [ ! -e "${TF_PLUGIN_CACHE_DIR}" ]; then
mkdir -p "${TF_PLUGIN_CACHE_DIR}"
fi
#
# Terraform security installation
# ==========================
#
#https://github.com/aquasecurity/tfsec/releases/download/v1.23.3/tfsec-linux-amd64
TF_SEC_VERSION=${TF_SEC_VERSION:-"1.23.3"}
TF_SEC_ARCH="linux-amd64"
TF_SEC_PKG_NAME="tfsec-${TF_SEC_ARCH}"
TF_SEC_PKG_PATH="${DIRENV_TMP_DIR}/${TF_SEC_PKG_NAME}"
TF_SEC_PKG_URL="https://github.com/aquasecurity/tfsec/releases/download/v${TF_SEC_VERSION}/${TF_SEC_PKG_NAME}"
if [ ! -e "${DIRENV_BIN_DIR}/tfsec" ]; then
echo "===> Getting tfec:${TF_SEC_VERSION} (can take a while to execute)"
curl -s -L "${TF_SEC_PKG_URL}" -o "${TF_SEC_PKG_PATH}"
mv "${TF_SEC_PKG_PATH}" "${DIRENV_BIN_DIR}/tfsec"
chmod 700 ${DIRENV_BIN_DIR}/tfsec
fi
#
# Terraform linter installation
# ==========================
#
#curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
TFLINT_VERSION=${TFLINT_VERSION:-"v0.37.0"}
TF_LINT_PKG_URL="https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh"
if [ ! -e "${DIRENV_BIN_DIR}/tflint" ]; then
echo "===> Getting tflint:${TFLINT_VERSION} (can take a while to execute)"
export TFLINT_INSTALL_PATH="${DIRENV_BIN_DIR}"
curl -s -L "${TF_LINT_PKG_URL}" | bash
fi
#
# Terraform docs installation
# ==========================
#
#curl -Lo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-$(uname)-amd64.tar.gz
TF_DOCS_VERSION=${TF_DOCS_VERSION:-"0.16.0"}
TF_DOCS_ARCH="linux-amd64"
TF_DOCS_PKG_NAME="terraform-docs-v${TF_DOCS_VERSION}-${TF_DOCS_ARCH}.tar.gz"
TF_DOCS_PKG_PATH="${DIRENV_TMP_DIR}/${TF_DOCS_PKG_NAME}"
TF_DOCS_PKG_URL="https://github.com/terraform-docs/terraform-docs/releases/download/v${TF_DOCS_VERSION}/${TF_DOCS_PKG_NAME}"
if [ ! -e "${DIRENV_BIN_DIR}/terraform-docs" ]; then
echo "===> Getting terraform-docs:${TF_DOCS_VERSION} (can take a while to execute)"
curl -s -L "${TF_DOCS_PKG_URL}" -o "${TF_DOCS_PKG_PATH}"
tar -xf ${TF_DOCS_PKG_PATH} -C ${DIRENV_BIN_DIR}
rm -f ${TF_DOCS_PKG_PATH}
fi
#
# GO installation
# ==========================
#
#curl -O https://storage.googleapis.com/golang/go1.13.5.linux-amd64.tar.gz
#GO_VERSION=${GO_VERSION:-"1.18.1"}
#GO_ARCH="linux-amd64"
#GO_PKG_NAME="go${GO_VERSION}.${GO_ARCH}.tar.gz"
#GO_PKG_PATH="${DIRENV_TMP_DIR}/${GO_PKG_NAME}"
#GO_PKG_URL="https://storage.googleapis.com/golang/${GO_PKG_NAME}"
#if [ ! -e "${DIRENV_BIN_DIR}/go/bin/go" ]; then
# echo "===> Getting go:${GO_VERSION} (can take a while to execute)"
# curl -s -L "${GO_PKG_URL}" -o "${GO_PKG_PATH}"
# tar -xf ${GO_PKG_PATH} -C ${DIRENV_BIN_DIR}
# rm -f ${GO_PKG_PATH}
#fi
#
#PATH_add ${DIRENV_BIN_DIR}/go/bin/
#
# GO sec installation
# ==========================
#
#curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.11.0
GO_SEC_VERSION="2.11.0"
GO_SEC_PKG_URL="https://raw.githubusercontent.com/securego/gosec/master/install.sh"
if [ ! -e "${HOME}/go/bin/gosec" ]; then
echo "===> Getting go sec:${GO_SEC_VERSION} (can take a while to execute)"
curl -sfL "${GO_SEC_PKG_URL}" | sh -s -- -b $(go env GOPATH)/bin v${GO_SEC_VERSION}
fi
#
# GO shfmt installation
# ==========================
#
go install mvdan.cc/sh/v3/cmd/shfmt@latest # shfmt
GO_SHFMT_VERSION="latest"
GO_SHFMT_PKG_PATH="mvdan.cc/sh/v3/cmd/shfmt@${GO_SHFMT_VERSION}"
if [ ! -e "${DIRENV_BIN_DIR}/go/bin/shfmt" ]; then
echo "===> Getting go shfmt:${GO_SHFMT_VERSION} (can take a while to execute)"
GOPATH="${DIRENV_BIN_DIR}/go/"
go install ${GO_SHFMT_PKG_PATH}
fi
#layout go
#
# Environment configuration
# =========================
#
#
DOTENV_ADDONS=".env .env.secrets"
for addon in ${DOTENV_ADDONS}; do
if [ -e "${PWD}/${addon}" ]; then
dotenv ${PWD}/${addon}
fi
done
ENV_ADDONS=".env.local"
for addon in ${ENV_ADDONS}; do
if [ -e "${PWD}/${addon}" ]; then
source ${PWD}/${addon}
fi
done
# See https://github.com/direnv/direnv/wiki/PS1
unset PS1