Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup asdf and direnv managed development environment #44

Merged
merged 13 commits into from
Nov 22, 2023
41 changes: 41 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
tools::has() {
type "$1" &>/dev/null
}

if ! tools::has tput; then
echo "'tput' tool is missing"
fi

console::bold() {
tput bold
}

console::red() {
tput setaf 1
}

console::reset() {
tput sgr0
}

die() {
echo -e "$(console::red)$(console::bold)FATAL: ${*}$(console::reset)" >&2
exit 1
}


asdf::has() {
asdf current $1 >>/dev/null 2>&1
}

use asdf

while read asdf_tool; do
if ! asdf::has ${asdf_tool}; then asdf direnv local ${asdf_tool}; fi
done < <(cat .tool-versions | grep -v '\#')

watch_file ".asdf"
dotenv_if_exists .envrc.local

export JAVA_HOME=$(dirname $(dirname $(expand_path $(asdf which java) "/")))
export ASDF_DIRENV_CLOUSEAU=true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ build.log
build.log
.cache
clouseau.iml
dependency-reduced-pom.xml


# direnv & asdf
.asdf
.envrc.local
4 changes: 4 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
direnv 2.32.3
maven 3.8.2
pgj marked this conversation as resolved.
Show resolved Hide resolved
java zulu-7.48.0.11
scala 2.9.1.final
286 changes: 286 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
instances = clouseau1 clouseau2 clouseau3
ifneq ($(WITH_COOKIE),)
with-cookie := -Dlauncher=with-cookie -Dcookie=$(WITH_COOKIE)
endif

.PHONY: help
# target: help - Print this help
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is nice, I am glad you made available it here too.

help:
@egrep "^# target: " Makefile \
| sed -e 's/^# target: //g' \
| sort \
| awk '{printf(" %-20s", $$1); $$1=$$2=""; print "-" $$0}'

.PHONY: build
# target: build - Build package, run tests and create distribution
build: .asdf check-epmd
@mvn

# target: clouseau1 - Start local inistance of clouseau1 node
# target: clouseau2 - Start local inistance of clouseau2 node
# target: clouseau3 - Start local inistance of clouseau3 node
$(instances): .asdf check-epmd
@mvn scala:run -Dname=$@ $(with-cookie)

.PHONY: clean
# target: clean - Remove build artifacts
clean:
@mvn clean

check-epmd:
@if ! pgrep epmd >>/dev/null 2>&1 ; then echo "Error: Please start 'epmd' first"; exit 1; fi

# ==========================
# Setting up the environment
# --------------------------

define CURRENT_SHELL
"$(shell basename $${SHELL})"
endef

define CURRENT_OS
"$(shell uname -s | tr '[:upper:]' '[:lower:]')"
endef

# Testing from fish
# set SHELL bash && make .asdf
# set SHELL fish && make .asdf
# set SHELL zsh && make .asdf
# set SHELL unsupported && make .asdf
# Testing from other shells
# SHELL=bash && make .asdf
# SHELL=fish && make .asdf
# SHELL=zsh && make .asdf
# SHELL=unsupported && make .asdf

ifndef ASDF_DIRENV_BIN
.asdf:
@case $(CURRENT_SHELL)-$(CURRENT_OS) in \
fish-darwin) echo "$$FISH_DARWIN_HELP" ;; \
bash-darwin) echo "$$BASH_DARWIN_HELP" ;; \
zsh-darwin) echo "$$ZSH_DARWIN_HELP" ;; \
*) echo "$$CONTRIBUTE_SHELL_SETUP" ;; \
esac
else
.asdf:
@touch $@
@touch .envrc
endif

define FISH_DARWIN_HELP
There are two steps which need to be done to set up environment.

- The asdf tool manager would need to be installed
- The direnv plugin for asdf manager would need to be installed


= Setting up asdf tool manager

You can install asdf from brew by following command.

```
brew install asdf
```

Once you finish installation add following line to ~/.config/fish/config.fish

```
source (brew --prefix asdf)/libexec/asdf.fish
```

You can do it by copy/paste of the following line

```
echo -e "\\nsource (brew --prefix asdf)/libexec/asdf.fish" >> ~/.config/fish/config.fish
```

= Setting up direnv

Run following commands to install direnv plugin

```
asdf plugin-add direnv
asdf install direnv latest
asdf global direnv latest
```

Once you have done with above commands add following to the ~/.config/fish/config.fish

```
# Hook direnv into your shell.
asdf exec direnv hook fish | source

# A shortcut for asdf managed direnv.
function direnv
asdf exec direnv "$$argv"
end
```

You can do it by copy/paste of the following

```
printf "\
# Hook direnv into your shell.
asdf exec direnv hook fish | source

# A shortcut for asdf managed direnv.
function direnv
asdf exec direnv \\"\$$argv\\"
end
" >> ~/.config/fish/config.fish
```

= Enabling direnv integration

- After finishing the above two steps restart your shell.
- Run following `asdf direnv setup --shell fish --version latest`
- Restart your shell once again

endef
export FISH_DARWIN_HELP

define BASH_DARWIN_HELP

There are two steps which need to be done to set up environment.

- The asdf tool manager would need to be installed
- The direnv plugin for asdf manager would need to be installed


= Setting up asdf tool manager

You can install asdf from brew by following command.

```
brew install asdf
```

Once you finish installation add following line to ~/.bash_profile

```
source $$(brew --prefix asdf)/libexec/asdf.sh
```

You can do it by copy/paste of the following line
```
echo -e "\n. $$(brew --prefix asdf)/libexec/asdf.sh" >> ~/.bash_profile
```

= Setting up direnv

Run following commands to install direnv plugin

```
asdf plugin-add direnv
asdf install direnv latest
asdf global direnv latest
```

Once you have done with above commands add following to the ~/.bash_profile

```
# Hook direnv into your shell.
eval "$$(asdf exec direnv hook bash)"

# A shortcut for asdf managed direnv.
direnv() { asdf exec direnv "$$@"; }
```

You can do it by copy/paste of the following

```
cat << EOF >> ~/.bashrc
# Hook direnv into your shell.
eval "$$(asdf exec direnv hook bash)"

# A shortcut for asdf managed direnv.
direnv() { asdf exec direnv "$$@"; }
EOF
```

= Enabling direnv integration

- After finishing the above two steps restart your shell.
- Run following `asdf direnv setup --shell bash --version latest`
- Restart your shell once again

endef
export BASH_DARWIN_HELP

define ZSH_DARWIN_HELP

There are two steps which need to be done to set up environment.

- The asdf tool manager would need to be installed
- The direnv plugin for asdf manager would need to be installed


= Setting up asdf tool manager

You can install asdf from brew by following command.

```
brew install asdf
```

Once you finish installation add following line to ~/.zshrc
(or ${ZDOTDIR}/.zshrc if you use custom location).

```
source $$(brew --prefix asdf)/libexec/asdf.sh
```

You can do it by copy/paste of the following line
```
echo -e "\n. $$(brew --prefix asdf)/libexec/asdf.sh" >> $${ZDOTDIR:-~}/.zshrc
```

= Setting up direnv

Run following commands to install direnv plugin

```
asdf plugin-add direnv
asdf install direnv latest
asdf global direnv latest
```

Once you have done with above commands add following to the ~/.zshrc
(or ${ZDOTDIR}/.zshrc if you use custom location).


```
# Hook direnv into your shell.
eval "$$(asdf exec direnv hook zsh)"

# A shortcut for asdf managed direnv.
direnv() { asdf exec direnv "$$@"; }
```

You can do it by copy/paste of the following

```
cat << EOF >> ~/.zshrc
# Hook direnv into your shell.
eval "$$(asdf exec direnv hook zsh)"

# A shortcut for asdf managed direnv.
direnv() { asdf exec direnv "$$@"; }
EOF
```

= Enabling direnv integration

- After finishing the above two steps restart your shell.
- Run following `asdf direnv setup --shell zsh --version latest`
- Restart your shell once again

endef
export ZSH_DARWIN_HELP


define CONTRIBUTE_SHELL_SETUP
We detected $(CURRENT_SHELL) running on $(CURRENT_OS). Unfortunately
documentation for this combination is not available. Contributions are welcome.
endef
export CONTRIBUTE_SHELL_SETUP
Loading
Loading