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

Add Makefile for more easy management of /bin scripts #38

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions bin/down

This file was deleted.

33 changes: 0 additions & 33 deletions bin/init

This file was deleted.

1 change: 1 addition & 0 deletions bin/observe
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 0 additions & 6 deletions bin/reset

This file was deleted.

3 changes: 0 additions & 3 deletions bin/up

This file was deleted.

22 changes: 22 additions & 0 deletions decisions/0003-use-makefile.md
Original file line number Diff line number Diff line change
@@ -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.