From aedbac468414b86d5fee321d48cd693d50797cd8 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Sat, 10 Jun 2023 14:09:24 +0900 Subject: [PATCH 01/12] Add init phase on Makefile for more easy management of bin scripts --- Makefile | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6f380c7 --- /dev/null +++ b/Makefile @@ -0,0 +1,58 @@ +basedir=$(PWD) +servicesdir=$(basedir)/services +composefile=$(basedir)/docker-compose.yml +prefix=\n\033[1;37m +suffix=\033[0m\n + +all: init + +.PHONY: check +check: + 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: + @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: + @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: + @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: + @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: + @printf "$(prefix)Initializing Spoke$(suffix)" && \ + mutagen-compose -f $(composefile) run --rm spoke yarn install + +.PHONY: init +init: check clone reticulum dialog hubs-admin hubs-client spoke + @printf "$(prefix)Done$(suffix)" && \ + mutagen-compose down + +.PHONY: clean +clean: + rm -rf $(servicesdir) + From 73d8b18df9cab259a701708fd22834f17edf18fd Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Tue, 13 Jun 2023 23:00:51 +0900 Subject: [PATCH 02/12] Add up phase on Makefile --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 6f380c7..77012c7 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,10 @@ init: check clone reticulum dialog hubs-admin hubs-client spoke @printf "$(prefix)Done$(suffix)" && \ mutagen-compose down +.PHONY: up +up: + mutagen-compose -f $(composefile) up --build --detach + .PHONY: clean clean: rm -rf $(servicesdir) From ff7434243e69d0b9b5e2755711c90c088f4d9f84 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Tue, 13 Jun 2023 23:17:01 +0900 Subject: [PATCH 03/12] Fix ignore error in clone phase on Makefile for reset phase --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 77012c7..4197be5 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,10 @@ check: .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 + -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: From d92a3ec23d8d435451b914a134ce68b30b9c34db Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Tue, 13 Jun 2023 23:18:45 +0900 Subject: [PATCH 04/12] Refactor add indent at line break on Makefile --- Makefile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 4197be5..c9cb328 100644 --- a/Makefile +++ b/Makefile @@ -21,36 +21,37 @@ clone: .PHONY: reticulum reticulum: @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' + 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: @printf "$(prefix)Initializing Dialog$(suffix)" && \ - docker-compose -f $(composefile) build dialog && \ - mutagen-compose -f $(composefile) run --rm dialog conditional-npm-ci + docker-compose -f $(composefile) build dialog && \ + mutagen-compose -f $(composefile) run --rm dialog conditional-npm-ci .PHONY: hubs-admin hubs-admin: @printf "$(prefix)Initializing Hubs Admin$(suffix)" && \ - docker-compose -f $(composefile) build hubs-admin && \ - mutagen-compose -f $(composefile) run --rm hubs-admin conditional-npm-ci + docker-compose -f $(composefile) build hubs-admin && \ + mutagen-compose -f $(composefile) run --rm hubs-admin conditional-npm-ci .PHONY: hubs-client hubs-client: @printf "$(prefix)Initializing Hubs Client$(suffix)" && \ - docker-compose -f $(composefile) build hubs-client && \ - mutagen-compose -f $(composefile) run --rm hubs-client conditional-npm-ci + docker-compose -f $(composefile) build hubs-client && \ + mutagen-compose -f $(composefile) run --rm hubs-client conditional-npm-ci .PHONY: spoke spoke: @printf "$(prefix)Initializing Spoke$(suffix)" && \ - mutagen-compose -f $(composefile) run --rm spoke yarn install + mutagen-compose -f $(composefile) run --rm spoke yarn install .PHONY: init init: check clone reticulum dialog hubs-admin hubs-client spoke @printf "$(prefix)Done$(suffix)" && \ - mutagen-compose down + mutagen-compose down .PHONY: up up: From a708829ebe20bb7b8c65011f6c02bf16095cd896 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Tue, 13 Jun 2023 23:26:49 +0900 Subject: [PATCH 05/12] Add down phase on Makefile --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index c9cb328..757380b 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,10 @@ init: check clone reticulum dialog hubs-admin hubs-client spoke up: mutagen-compose -f $(composefile) up --build --detach +.PHONY: down +down: + mutagen-compose -f $(composefile) down + .PHONY: clean clean: rm -rf $(servicesdir) From 86547749bfb2b40c433b072ae108a4c0f2aa6098 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Tue, 13 Jun 2023 23:27:29 +0900 Subject: [PATCH 06/12] Add reset phase on Makefile --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 757380b..9cc8975 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,15 @@ up: down: mutagen-compose -f $(composefile) down +.PHONY: reset +reset: clean-reticulum init + .PHONY: clean clean: rm -rf $(servicesdir) +.PHONY: clean-reticulum +clean-reticulum: + mutagen-compose -f $(composefile) down --volumes --rmi local && \ + rm -rf $(basedir)/services/reticulum/deps + From 054be3d91161d35e69a827463a8f3f75113b942f Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Wed, 14 Jun 2023 00:46:07 +0900 Subject: [PATCH 07/12] Fix add check and fix command name on Makefile --- Makefile | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 9cc8975..ebe7c85 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,14 @@ composefile=$(basedir)/docker-compose.yml prefix=\n\033[1;37m suffix=\033[0m\n -all: init +.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 @@ -19,57 +23,48 @@ clone: -git clone https://github.com/mozilla/Spoke.git $(servicesdir)/spoke .PHONY: reticulum -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: +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: +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: +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: +spoke: check @printf "$(prefix)Initializing Spoke$(suffix)" && \ mutagen-compose -f $(composefile) run --rm spoke yarn install -.PHONY: init -init: check clone reticulum dialog hubs-admin hubs-client spoke - @printf "$(prefix)Done$(suffix)" && \ - mutagen-compose down - .PHONY: up -up: +up: check mutagen-compose -f $(composefile) up --build --detach .PHONY: down -down: +down: check mutagen-compose -f $(composefile) down .PHONY: reset -reset: clean-reticulum init +reset: clean init .PHONY: clean -clean: - rm -rf $(servicesdir) - -.PHONY: clean-reticulum -clean-reticulum: +clean: check mutagen-compose -f $(composefile) down --volumes --rmi local && \ rm -rf $(basedir)/services/reticulum/deps From c0ee2ae0f0d5e58495007e90cecfc614c9016bbf Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Wed, 14 Jun 2023 01:05:40 +0900 Subject: [PATCH 08/12] Add alias of /bin/observe and /bin/service-update scripts on Makefile --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index ebe7c85..bfdd809 100644 --- a/Makefile +++ b/Makefile @@ -68,3 +68,11 @@ 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 + From 25f1ad56293cd96af60e5c65e930fd22ee0acf24 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Wed, 14 Jun 2023 01:18:23 +0900 Subject: [PATCH 09/12] Add tmux presence check on bin/observe --- bin/observe | 1 + 1 file changed, 1 insertion(+) 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' From 83aa649073ce470d30d494c8f6b6cd06d16d6839 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Wed, 14 Jun 2023 01:26:46 +0900 Subject: [PATCH 10/12] Fix update readme from using bin scripts to using Makefile --- README.md | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) 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 From 28a8a606f6c45d652917741b46f85febd720c574 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Wed, 14 Jun 2023 02:05:05 +0900 Subject: [PATCH 11/12] Del bin scripts of init up down reset --- bin/down | 3 --- bin/init | 33 --------------------------------- bin/reset | 6 ------ bin/up | 3 --- 4 files changed, 45 deletions(-) delete mode 100755 bin/down delete mode 100755 bin/init delete mode 100755 bin/reset delete mode 100755 bin/up 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/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 From 4be5525353b75a1e811ecc55d1a9cc174d6d3507 Mon Sep 17 00:00:00 2001 From: Iovesophy <15680172+Iovesophy@users.noreply.github.com> Date: Wed, 14 Jun 2023 02:06:54 +0900 Subject: [PATCH 12/12] Add architectural decision record for using Makefile --- decisions/0003-use-makefile.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 decisions/0003-use-makefile.md 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. +