Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
DevOps-Python-tools/.envrc at master · HariSekhon/DevOps-Python-tools · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
HariSekhon
DevOps-Python-tools
Repository navigation
Code
Issues
3
(3)
Pull requests
37
(37)
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
DevOps-Python-tools
/
.envrc
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
214 lines (180 loc) · 7.14 KB
master
Breadcrumbs
DevOps-Python-tools
/
.envrc
Copy path
Top
File metadata and controls
Code
Blame
214 lines (180 loc) · 7.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/usr/bin/env bash
#
vim:ts=4:sts=4:sw=4:et
#
#
Author: Hari Sekhon
#
Date: Mon Feb 22 17:42:01 2021 +0000
#
#
https://github.com/HariSekhon/DevOps-Python-tools
#
#
License: see accompanying Hari Sekhon LICENSE file
#
#
If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
#
https://www.linkedin.com/in/HariSekhon
#
#
============================================================================ #
#
D i r E n v
#
============================================================================ #
#
https://direnv.net/man/direnv-stdlib.1.html
#
See Also:
#
#
.envrc-aws
#
.envrc-gcp
#
.envrc-kubernetes
#
direnv stdlib - loads .envrc from parent dir up to /
#
#
useful to accumulate parent and child directory .envrc settings eg. adding Kubernetes namespace, ArgoCD app etc.
#
#
bypasses security authorization though - use with care
#
source_up
#
#
source_up must be loaded before set -u otherwise gets this error:
#
#
direnv: loading .envrc
#
/bin/bash: line 226: $1: unbound variable
#
#
source_up causes this error is up .envrc is found in parent directories:
#
#
direnv: No ancestor .envrc found
set
-euo pipefail
[
-n
"
${DEBUG
:-
}
"
]
&&
set
-x
src=
"
$(
readlink -f
"
${BASH_SOURCE[0]}
"
)
"
srcdir=
"
$(
cd
"
$(
dirname
"
$src
"
)
"
&&
pwd
)
"
#
============================================================================ #
#
P r e - C o m m i t
#
============================================================================ #
#
Automatically install Pre-Commit Git hooks if not already present
if
!
type
-P pre-commit
&
>
/dev/null
;
then
if
uname -s
|
grep -q Darwin
&&
type
-P brew
&
>
/dev/null
;
then
echo
echo
"
Pre-commit is not installed - installing now using Homebrew...
"
echo
brew install pre-commit
echo
elif
type
-P pip
&
>
/dev/null
;
then
echo
echo
"
Pre-commit is not installed - installing now using Pip...
"
echo
pip install pre-commit
fi
fi
if
[
-f
.pre-commit-config.yaml ]
&&
type
-P pre-commit
&
>
/dev/null
&&
git rev-parse --is-inside-work-tree
&
>
/dev/null
;
then
hook=
"
$(
git rev-parse --show-toplevel
)
/.git/hooks/pre-commit
"
if
[
-L
"
$hook
"
]
;
then
echo
"
Detected symlink hook:
"
echo
ls -l
"
$hook
"
echo
echo
"
Removing
"
rm -f
"
$hook
"
fi
if
!
[
-f
"
$hook
"
]
;
then
echo
echo
"
Pre-commit hook is not installed in local Git repo checkout - installing now...
"
echo
pre-commit install
fi
fi
#
============================================================================ #
#
D o c k e r C o m p o s e
#
============================================================================ #
export
COMPOSE_PROJECT_NAME=
"
DevOps-Python-tools
"
#
============================================================================ #
#
G i t H u b
#
============================================================================ #
#
export GITHUB_ORGANIZATION=HariSekhon
#
============================================================================ #
#
A n s i b l e
#
============================================================================ #
#
use the local repo's ansible.cfg rather than:
#
#
$PWD/ansible.cfg
#
~/.ansible.cfg
#
/etc/ansible/ansible.cfg
#
#
set this in project repos to ensure user environment ANSIBLE_CONFIG doesn't get used
#
export ANSIBLE_CONFIG="/path/to/ansible.cfg"
#
============================================================================ #
#
C l o u d f l a r e
#
============================================================================ #
#
export CLOUDFLARE_EMAIL=hari@...
#
export CLOUDFLARE_API_KEY=... # generate here: https://dash.cloudflare.com/profile/api-tokens
#
export CLOUDFLARE_TOKEN=... # used by cloudflare_api.sh but not by terraform module
#
export the variables for terraform
#
export TF_VAR_cloudflare_email="$CLOUDFLARE_EMAIL"
#
export TF_VAR_cloudflare_api_key="$CLOUDFLARE_API_KEY" # must be a key, not a token using the link above
#
============================================================================ #
#
Load External Envrc Files If Present
#
============================================================================ #
#
XXX: safer to bring all these external .envrc inline if you're worried about changes
#
to it bypassing 'direnv allow' authorization
load_if_exists
(){
#
first arg is a path to a .envrc
#
all other args are passed to the sourcing of .envrc - used by .envrc-kubernetes
#
to pass the context name 'docker-desktop' to switch to
local
envrc=
"
$1
"
shift
if
!
[[
"
$envrc
"
=~
^/ ]]
;
then
envrc=
"
$srcdir
/
$envrc
"
fi
if
[
-f
"
$envrc
"
]
;
then
#
prevent looping on symlinks to this .envrc if given
if
[
"
$(
readlink
"
$envrc
"
)
"
=
"
$src
"
]
;
then
return
fi
echo
echo
"
Loading
$envrc
"
#
shellcheck disable=SC1090,SC1091
.
"
$envrc
"
"
$@
"
fi
}
#
don't do this it may lead to an infinite loop if 'make link' symlinking ~/.envrc to this repo's .envrc
#
(which I do to keep Python virtual automatically loaded at all times because recent pip on Python refuses
#
to install to system Python)
#
load_if_exists ~/.envrc
#
============================================================================ #
#
P y t h o n
#
============================================================================ #
#
.envrc-aws \
#
.envrc-gcp \
#
.envrc-terraform \
#
shellcheck disable=SC2043
for
envrc
in
\
.envrc-python \
;
do
load_if_exists
"
$envrc
"
done
#
============================================================================ #
#
A W S
#
============================================================================ #
if
[[
"
$PWD
"
=~
/aws/ ]]
;
then
load_if_exists .envrc-aws
fi
#
============================================================================ #
#
G C P
#
============================================================================ #
if
[[
"
$PWD
"
=~
/gcp/ ]]
;
then
load_if_exists .envrc-gcp
fi
#
============================================================================ #
#
T e r r a f o r m
#
============================================================================ #
if
[[
"
$PWD
"
=~
/(terra(form)
?
|
tf)(/
|
$) ]]
;
then
load_if_exists .envrc-terraform
fi
#
============================================================================ #
#
K u b e r n e t e s
#
============================================================================ #
if
[
-f
"
$srcdir
/.envrc-kubernetes
"
]
;
then
load_if_exists .envrc-kubernetes docker-desktop
fi
#
============================================================================ #
#
. E n v
#
============================================================================ #
echo
#
read .env too
#
dotenv
load_if_exists .envrc.local
You can’t perform that action at this time.