diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bfdd809 --- /dev/null +++ b/Makefile @@ -0,0 +1,78 @@ +basedir=$(PWD) +servicesdir=$(basedir)/services +composefile=$(basedir)/docker-compose.yml +prefix=\n\033[1;37m +suffix=\033[0m\n + +.PHONY: init +init: check clone reticulum dialog hubs-admin hubs-client spoke + @printf "$(prefix)Done$(suffix)" && \ + mutagen-compose down + +.PHONY: check +check: + hash docker-compose || exit 1 + hash mutagen-compose || exit 1 + +.PHONY: clone +clone: + @printf "$(prefix)Cloning source repositories$(suffix)" + -git clone https://github.com/mozilla/reticulum.git $(servicesdir)/reticulum + -git clone https://github.com/mozilla/dialog.git $(servicesdir)/dialog + -git clone https://github.com/mozilla/hubs.git $(servicesdir)/hubs + -git clone https://github.com/mozilla/Spoke.git $(servicesdir)/spoke + +.PHONY: reticulum +reticulum: check + @printf "$(prefix)Initializing Reticulum$(suffix)" && \ + docker-compose -f $(composefile) build reticulum && \ + mutagen-compose -f $(composefile) run --rm reticulum \ + sh -c 'trapped-mix do deps.get, deps.compile, ecto.create' + +.PHONY: dialog +dialog: check + @printf "$(prefix)Initializing Dialog$(suffix)" && \ + docker-compose -f $(composefile) build dialog && \ + mutagen-compose -f $(composefile) run --rm dialog conditional-npm-ci + +.PHONY: hubs-admin +hubs-admin: check + @printf "$(prefix)Initializing Hubs Admin$(suffix)" && \ + docker-compose -f $(composefile) build hubs-admin && \ + mutagen-compose -f $(composefile) run --rm hubs-admin conditional-npm-ci + +.PHONY: hubs-client +hubs-client: check + @printf "$(prefix)Initializing Hubs Client$(suffix)" && \ + docker-compose -f $(composefile) build hubs-client && \ + mutagen-compose -f $(composefile) run --rm hubs-client conditional-npm-ci + +.PHONY: spoke +spoke: check + @printf "$(prefix)Initializing Spoke$(suffix)" && \ + mutagen-compose -f $(composefile) run --rm spoke yarn install + +.PHONY: up +up: check + mutagen-compose -f $(composefile) up --build --detach + +.PHONY: down +down: check + mutagen-compose -f $(composefile) down + +.PHONY: reset +reset: clean init + +.PHONY: clean +clean: check + mutagen-compose -f $(composefile) down --volumes --rmi local && \ + rm -rf $(basedir)/services/reticulum/deps + +.PHONY: observe +observe: + bin/observe + +.PHONY: services-update +services-update: + bin/services-update + diff --git a/README.md b/README.md index 1056de3..d555889 100644 --- a/README.md +++ b/README.md @@ -21,16 +21,42 @@ certificates, you can visit https://hubs.local:4000 from your browser. 127.0.0.1 hubs.local 127.0.0.1 hubs-proxy.local -4. Initialize the services with `bin/init` +4. Initialize the services +```bash +$ make +``` ### Orchestration -* Start containers with `bin/up` -* Stop containers `bin/down` -* Observe running containers with `bin/observe`[^2] -* Restore all services to a fresh state with `bin/reset` -* Update all service source code with `bin/services-update` -* Update service dependencies with `bin/init` +* Start containers +```bash +$ make up +``` + +* Stop containers +```bash +$ make down +``` + +* Observe running containers [^2] +```bash +$ make observe +``` + +* Restore all services to a fresh state +```bash +$ make reset +``` + +* Update all service source code +```bash +$ make services-update +``` + +* Update service dependencies +```bash +$ make init +``` [^2]: Requires `tmux` and `watch` program files in the user’s path diff --git a/bin/down b/bin/down deleted file mode 100755 index 19a04b2..0000000 --- a/bin/down +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -basedir=$(dirname "$0")/.. -mutagen-compose -f "$basedir"/docker-compose.yml down diff --git a/bin/init b/bin/init deleted file mode 100755 index 0d951d1..0000000 --- a/bin/init +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -hash mutagen-compose || exit 1 - -basedir=$(readlink -f "$(dirname "$0")"/..) -prefix='\n\033[1;37m' -suffix='\033[0m\n' - -servicesdir=$basedir/services -echo -e ${prefix}Cloning source repositories$suffix -git clone https://github.com/mozilla/reticulum.git "$servicesdir"/reticulum -git clone https://github.com/mozilla/dialog.git "$servicesdir"/dialog -git clone https://github.com/mozilla/hubs.git "$servicesdir"/hubs -git clone https://github.com/mozilla/Spoke.git "$servicesdir"/spoke - -composefile=$basedir/docker-compose.yml -echo -e ${prefix}Initializing Reticulum$suffix && -docker-compose -f "$composefile" build reticulum && -mutagen-compose -f "$composefile" run --rm reticulum sh -c 'trapped-mix do deps.get, deps.compile, ecto.create' && -echo -e ${prefix}Initializing Dialog$suffix && -docker-compose -f "$composefile" build dialog && -mutagen-compose -f "$composefile" run --rm dialog conditional-npm-ci && -echo -e ${prefix}Initializing Hubs Admin$suffix && -docker-compose -f "$composefile" build hubs-admin && -mutagen-compose -f "$composefile" run --rm hubs-admin conditional-npm-ci && -echo -e ${prefix}Initializing Hubs Client$suffix && -docker-compose -f "$composefile" build hubs-client && -mutagen-compose -f "$composefile" run --rm hubs-client conditional-npm-ci && -echo -e ${prefix}Initializing Spoke$suffix && -mutagen-compose -f "$composefile" run --rm spoke yarn install - -code=$? -mutagen-compose down -exit $code diff --git a/bin/observe b/bin/observe index f4b4f36..687bbc6 100755 --- a/bin/observe +++ b/bin/observe @@ -1,6 +1,7 @@ #!/bin/bash hash docker-compose || exit 1 hash watch || exit 1 +hash tmux || exit 1 basedir=$(readlink -f "$(dirname "$0")"/..) session='hubs-compose' diff --git a/bin/reset b/bin/reset deleted file mode 100755 index 5ea9af3..0000000 --- a/bin/reset +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -basedir=$(readlink -f "$(dirname "$0")"/..) - -mutagen-compose -f "$basedir"/docker-compose.yml down --volumes --rmi local && -rm -rf "$basedir"/services/reticulum/deps && -"$basedir"/bin/init diff --git a/bin/up b/bin/up deleted file mode 100755 index 49c3947..0000000 --- a/bin/up +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -basedir=$(dirname "$0")/.. -mutagen-compose -f "$basedir"/docker-compose.yml up --build --detach diff --git a/decisions/0003-use-makefile.md b/decisions/0003-use-makefile.md new file mode 100644 index 0000000..5ba37cd --- /dev/null +++ b/decisions/0003-use-makefile.md @@ -0,0 +1,22 @@ +# 3. use-makefile + +Date: 2023-06-14 + +## Status + +Accepted + +## Context + +The bin scripts are very useful, but I feel some scripts are less readable. +Also, there were times when I couldn't do detailed operations. + +## Decision + +Using the Makefile as a solution separated some functions and made them more flexible. + +## Consequences + +Configuration management is easier. +Improved the readability of some configuration management scripts. +