2021-05-13 20:05:27 +00:00
BASH := $( shell which bash)
2021-05-22 14:36:40 +00:00
#### Makefile config ####
#### NOTE: do not edit this file, override these in your env instead ####
2021-05-13 20:05:27 +00:00
# what flavour do we want?
2021-05-05 08:05:51 +00:00
FLAVOUR ?= classic
2021-06-08 14:11:02 +00:00
FLAVOUR_PATH ?= flavours/$( FLAVOUR)
2021-05-13 20:05:27 +00:00
2021-05-22 14:36:40 +00:00
# do we want to use Docker? set as env var:
# - WITH_DOCKER=total : use docker for everything (default)
# - WITH_DOCKER=partial : use docker for services like the DB
# - WITH_DOCKER=easy : use docker for services like the DB & compiled utilities like messctl
# - WITH_DOCKER=no : please no
WITH_DOCKER ?= total
# other configs
2022-03-06 00:32:13 +00:00
FORKS_PATH ?= forks/
2021-05-23 08:23:53 +00:00
MIX_ENV ?= dev
2021-05-05 08:05:51 +00:00
ORG_NAME ?= bonfirenetworks
2021-06-22 13:26:54 +00:00
APP_NAME ?= bonfire
2021-01-07 13:02:25 +00:00
UID := $( shell id -u)
GID := $( shell id -g)
2021-06-22 13:26:54 +00:00
APP_REL_CONTAINER = " $( APP_NAME) _release "
2021-09-26 09:32:07 +00:00
WEB_CONTAINER ?= $( APP_NAME) _web
2021-04-20 13:07:54 +00:00
APP_REL_DOCKERFILE = Dockerfile.release
APP_REL_DOCKERCOMPOSE = docker-compose.release.yml
2021-05-16 08:34:50 +00:00
APP_VSN ?= ` grep -m 1 'version:' mix.exs | cut -d '"' -f2`
2022-03-26 03:21:07 +00:00
APP_VSN_EXTRA ?= alpha
2021-04-20 13:07:54 +00:00
APP_BUILD ?= ` git rev-parse --short HEAD`
2021-06-22 13:26:54 +00:00
APP_DOCKER_REPO = " $( ORG_NAME) / $( APP_NAME) - $( FLAVOUR) "
2021-12-12 18:44:34 +00:00
DB_DOCKER_IMAGE ?= postgis/postgis:12-3.1-alpine
2021-12-17 02:57:51 +00:00
CONFIG_PATH = $( FLAVOUR_PATH) /config
2020-11-05 10:02:29 +00:00
2021-05-22 14:36:40 +00:00
#### GENERAL SETUP RELATED COMMANDS ####
2021-01-07 13:02:25 +00:00
export UID
export GID
2021-05-13 20:05:27 +00:00
d e f i n e s e t u p _ e n v
2021-12-17 02:57:51 +00:00
$( eval ENV_DIR := $( CONFIG_PATH) /$( MIX_ENV) )
2021-05-13 20:05:27 +00:00
@echo " Loading environment variables from $( ENV_DIR) "
2021-06-25 10:50:05 +00:00
@$( call load_env,$( ENV_DIR) /public.env)
@$( call load_env,$( ENV_DIR) /secrets.env)
2021-05-13 20:05:27 +00:00
e n d e f
d e f i n e l o a d _ e n v
2021-06-25 10:50:05 +00:00
$( eval ENV_FILE := $( 1) )
2021-12-17 02:57:51 +00:00
# @echo "Loading env vars from $(ENV_FILE)"
2021-06-25 10:50:05 +00:00
$( eval include $( ENV_FILE) ) # import env into make
2021-05-13 20:05:27 +00:00
$( eval export ) # export env from make
e n d e f
2021-05-22 14:36:40 +00:00
pre-config : pre -init ## Initialise env files, and create some required folders, files and softlinks
2021-06-16 19:25:54 +00:00
@echo " You can now edit your config for flavour ' $( FLAVOUR) ' in config/ $( MIX_ENV) /secrets.env, config/ $( MIX_ENV) /public.env and ./config/ more generally. "
2021-05-22 14:36:40 +00:00
pre-init :
2021-11-18 23:31:46 +00:00
@echo " Setting flavour to $( FLAVOUR_PATH) "
2021-12-14 00:06:37 +00:00
@ln -sfn $( FLAVOUR_PATH) /config ./config
2022-04-28 08:42:31 +00:00
@rm -rf ./priv/repo
@cp -rn $( FLAVOUR_PATH) /repo ./priv/repo
2021-10-30 19:21:04 +00:00
@mkdir -p data/
2022-03-15 22:08:28 +00:00
@rm -rf ./data/current_flavour
2022-01-17 06:19:58 +00:00
@ln -sf ../$( FLAVOUR_PATH) ./data/current_flavour
2021-12-12 21:26:42 +00:00
@mkdir -p $( CONFIG_PATH) /prod
@mkdir -p $( CONFIG_PATH) /dev
@touch $( CONFIG_PATH) /deps.path
2021-12-17 02:13:36 +00:00
@cp -n $( CONFIG_PATH) /templates/public.env $( CONFIG_PATH) /dev/ | true
@cp -n $( CONFIG_PATH) /templates/public.env $( CONFIG_PATH) /prod/ | true
@cp -n $( CONFIG_PATH) /templates/not_secret.env $( CONFIG_PATH) /dev/secrets.env | true
@cp -n $( CONFIG_PATH) /templates/not_secret.env $( CONFIG_PATH) /prod/secrets.env | true
2021-05-22 14:36:40 +00:00
2022-05-04 02:13:47 +00:00
pre-run : pre -init
2021-04-20 13:07:54 +00:00
@mkdir -p forks/
@mkdir -p data/uploads/
2021-07-10 17:35:41 +00:00
@mkdir -p priv/static/data
@ln -s data/uploads priv/static/data/ | true
2021-04-22 20:11:26 +00:00
@mkdir -p data/search/dev
2021-09-19 23:01:17 +00:00
@chmod 700 .erlang.cookie
2021-04-20 13:07:54 +00:00
2022-05-04 02:13:47 +00:00
init : pre -run
2021-11-18 23:31:46 +00:00
@$( call setup_env)
2022-03-04 21:07:22 +00:00
@echo " Light that fire... $( APP_NAME) with $( FLAVOUR) flavour in $( MIX_ENV) - docker: $( WITH_DOCKER) - $( APP_VSN) - $( APP_BUILD) - $( FLAVOUR_PATH) "
2021-05-22 14:36:40 +00:00
@make --no-print-directory pre-init
@make --no-print-directory services
2020-09-16 13:26:29 +00:00
2021-06-17 14:08:31 +00:00
help : ## Makefile commands help
2021-05-22 14:36:40 +00:00
@perl -nle'print $& if m{^[a-zA-Z_-~.%]+:.*?## .*$$}' $( MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2020-09-16 13:32:14 +00:00
2021-05-22 14:36:40 +00:00
env.exports : ## Display the vars from dotenv files that you need to load in your environment
2021-06-08 14:11:02 +00:00
@awk 'NF { if( $$1 != "#" ){ print "export " $$0 }}' $( FLAVOUR_PATH) /config/dev/*.env
2021-01-20 08:57:27 +00:00
2020-12-29 15:34:56 +00:00
2021-05-22 14:36:40 +00:00
#### COMMON COMMANDS ####
2020-09-17 10:44:25 +00:00
2021-06-25 11:17:01 +00:00
setup : build mix ~setup js .deps .get ## First run - prepare environment and dependencies
2021-04-20 13:07:54 +00:00
2021-06-24 22:53:43 +00:00
dev : init dev .run ## Run the app in development
dev.run :
2021-05-22 14:36:40 +00:00
i f e q ( $( WITH_DOCKER ) , t o t a l )
@make --no-print-directory docker.stop.web
2021-09-26 09:15:32 +00:00
docker-compose run --name $( WEB_CONTAINER) --service-ports web
2022-01-17 06:19:58 +00:00
# docker-compose --verbose run --name $(WEB_CONTAINER) --service-ports web
2021-05-22 14:36:40 +00:00
e l s e
iex -S mix phx.server
e n d i f
2021-04-20 13:07:54 +00:00
2021-12-16 22:56:46 +00:00
doc : ## Generate docs from code & readmes
2022-03-29 22:02:21 +00:00
@make --no-print-directory mix.remote~docs
2021-12-16 22:56:46 +00:00
2021-11-26 03:36:54 +00:00
recompile : ## Force the app to recompile
@make --no-print-directory cmd cmd = "mix compile --force"
2022-03-16 04:30:58 +00:00
dev.test : init test .env .server dev .run
2021-06-24 22:53:43 +00:00
2021-05-22 14:36:40 +00:00
dev.bg : init ## Run the app in dev mode, as a background service
i f e q ( $( WITH_DOCKER ) , t o t a l )
@make --no-print-directory docker.stop.web
2021-09-26 09:15:32 +00:00
docker-compose run --detach --name $( WEB_CONTAINER) --service-ports web elixir -S mix phx.server
2021-05-22 14:36:40 +00:00
e l s e
elixir --erl "-detached" -S mix phx.server
echo Running in background...
ps au | grep beam
e n d i f
2020-12-26 17:01:34 +00:00
2021-09-26 02:04:07 +00:00
db.migrate : mix ~ecto .migrate ## Run latest database migrations (eg. after adding/upgrading an app/extension)
db.seeds : mix ~ecto .migrate mix ~ecto .seeds ## Run latest database seeds (eg. inserting required data after adding/upgrading an app/extension)
2021-12-24 09:44:29 +00:00
db.reset : init dev .search .reset db .pre -migrations mix ~ecto .reset ## Reset the DB (caution: this means DATA LOSS)
2021-07-10 12:55:18 +00:00
dev.search.reset :
2021-09-26 02:04:07 +00:00
i f e q ( $( WITH_DOCKER ) , n o )
echo ...
e l s e
2021-07-10 12:55:18 +00:00
@docker-compose rm -s -v search
2021-09-13 09:46:37 +00:00
e n d i f
2021-09-26 02:04:07 +00:00
rm -rf data/search/dev
2020-09-17 10:44:25 +00:00
2021-05-22 14:36:40 +00:00
db.rollback : mix ~ecto .rollback ## Rollback previous DB migration (caution: this means DATA LOSS)
2020-11-05 08:25:10 +00:00
2022-05-05 21:55:00 +00:00
db.rollback.all : ## Rollback ALL DB migrations (caution: this means DATA LOSS)
@make --no-print-directory cmd cmd = "mix ecto.rollback --all"
2021-05-11 11:41:42 +00:00
2021-05-22 14:36:40 +00:00
#### UPDATE COMMANDS ####
2022-02-24 18:49:49 +00:00
update : init update .repo build update .forks update .deps mix ~deps .get mix ~ecto .migrate js .deps .get update .repo ## Update the dev app and all dependencies/extensions/forks, and run migrations
2021-05-22 14:36:40 +00:00
2022-02-12 05:54:56 +00:00
update.app : update .repo update .deps ## Update the app and Bonfire extensions in ./deps
update.deps : ## Update Bonfire extensions in ./deps
2022-05-06 01:10:33 +00:00
@rm -rf deps/*/assets/pnpm-lock.yaml
2021-06-22 21:02:04 +00:00
@make --no-print-directory mix.remote~updates
update.repo :
2022-01-05 21:13:25 +00:00
@chmod +x git-publish.sh && ./git-publish.sh . pull
2021-05-11 11:41:42 +00:00
2022-01-17 09:27:11 +00:00
update.repo.pull :
@chmod +x git-publish.sh && ./git-publish.sh . pull only
2021-05-22 14:36:40 +00:00
update.deps.bonfire : init mix .remote ~bonfire .deps ## Update to the latest Bonfire extensions in ./deps
2022-01-17 06:19:58 +00:00
2021-05-22 14:36:40 +00:00
update.deps.all : ## Update evey single dependency (use with caution)
@make --no-print-directory update.dep~"--all"
2021-05-11 11:41:42 +00:00
2021-05-22 14:36:40 +00:00
update.dep~% : ## Update a specify dep (eg. `make update.dep~pointers`)
2022-01-05 21:09:34 +00:00
@chmod +x git-publish.sh && ./git-publish.sh $( FORKS_PATH) /$* pull
2022-04-07 03:06:53 +00:00
@make --no-print-directory mix.remote~" deps.update $* "
2021-04-20 13:07:54 +00:00
2021-06-08 14:21:51 +00:00
update.forks : ## Pull the latest commits from all ./forks
2022-01-05 21:09:34 +00:00
@jungle git fetch || echo "Jungle not available, will fetch one by one instead."
@chmod +x git-publish.sh && find $( FORKS_PATH) -mindepth 1 -maxdepth 1 -type d -exec ./git-publish.sh { } maybe-pull \;
2022-01-05 21:22:52 +00:00
# TODO: run in parallel? find $(FORKS_PATH) -mindepth 1 -maxdepth 1 -type d | xargs -P 50 -I '{}' ./git-publish.sh '{}'
2021-07-08 12:55:35 +00:00
update.fork~% : ## Pull the latest commits from all ./forks
2022-01-05 21:09:34 +00:00
@chmod +x git-publish.sh && find $( FORKS_PATH) /$* -mindepth 0 -maxdepth 0 -type d -exec ./git-publish.sh { } pull \;
2021-04-20 14:14:57 +00:00
2021-10-06 09:46:19 +00:00
deps.get : mix .remote ~deps .get mix ~deps .get js .ext .deps .get ## Fetch locked version of non-forked deps
2021-04-20 13:07:54 +00:00
2022-04-06 06:12:13 +00:00
deps.clean.data : mix ~bonfire .deps .clean .data
deps.clean.api : mix ~bonfire .deps .clean .api
2021-11-24 10:25:06 +00:00
2021-05-22 14:36:40 +00:00
#### DEPENDENCY & EXTENSION RELATED COMMANDS ####
2021-04-20 13:07:54 +00:00
2021-10-06 09:46:19 +00:00
js.deps.get : js .assets .deps .get js .ext .deps .get
js.assets.deps.get :
2021-11-13 07:42:51 +00:00
@pnpm -v || npm -g install pnpm
2021-08-02 11:15:38 +00:00
@chmod +x ./assets/install.sh
2021-09-19 21:02:18 +00:00
@make --no-print-directory cmd cmd = ./assets/install.sh
2021-10-06 09:46:19 +00:00
js.ext.deps.get :
@chmod +x ./config/deps.js.sh
2021-09-19 21:02:18 +00:00
@make --no-print-directory cmd cmd = ./config/deps.js.sh
2021-06-08 11:37:53 +00:00
2021-11-28 04:53:15 +00:00
deps.outdated :
@make mix.remote~"hex.outdated --all"
2021-12-03 00:34:19 +00:00
dep.clean :
make --no-print-directory cmd cmd = " mix deps.clean $( dep) --build "
2020-11-17 08:10:36 +00:00
2021-05-22 14:36:40 +00:00
dep.clone.local : ## Clone a git dep and use the local version, eg: `make dep.clone.local dep="bonfire_me" repo=https://github.com/bonfire-networks/bonfire_me`
git clone $( repo) $( FORKS_PATH) $( dep) 2> /dev/null || ( cd $( FORKS_PATH) $( dep) ; git pull)
@make --no-print-directory dep.go.local dep = $( dep)
2020-11-05 10:02:29 +00:00
2021-05-22 14:36:40 +00:00
deps.clone.local.all : ## Clone all bonfire deps / extensions
@curl -s https://api.github.com/orgs/bonfire-networks/repos?per_page= 500 | ruby -rrubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[make dep.clone.local dep="#{repo["name"]}" repo="#{repo["ssh_url"]}" ]}'
2020-11-05 10:02:29 +00:00
2021-05-22 14:36:40 +00:00
dep.go.local :
@make --no-print-directory dep.go.local.path dep = $( dep) path = $( FORKS_PATH) $( dep)
2020-11-05 10:02:29 +00:00
2021-05-22 14:36:40 +00:00
dep.go.local~% : ## Switch to using a local path, eg: make dep.go.local~pointers
@make --no-print-directory dep.go.local dep = " $* "
2020-11-05 10:02:29 +00:00
2021-05-22 14:36:40 +00:00
dep.go.local.path : ## Switch to using a local path, specifying the path, eg: make dep.go.local dep=pointers path=./libs/pointers
@make --no-print-directory dep.local~add dep = $( dep) path = $( path)
@make --no-print-directory dep.local~enable dep = $( dep) path = ""
2021-04-20 13:07:54 +00:00
2021-05-22 14:36:40 +00:00
dep.go.git : ## Switch to using a git repo, eg: make dep.go.git dep="pointers" repo=https://github.com/bonfire-networks/pointers (specifying the repo is optional if previously specified)
@make --no-print-directory dep.git~add dep = $( dep) $( repo) 2> /dev/null || true
@make --no-print-directory dep.git~enable dep = $( dep) repo = ""
@make --no-print-directory dep.local~disable dep = $( dep) path = ""
2020-11-10 07:44:00 +00:00
2021-05-22 14:36:40 +00:00
dep.go.hex : ## Switch to using a library from hex.pm, eg: make dep.go.hex dep="pointers" version="~> 0.2" (specifying the version is optional if previously specified)
@make --no-print-directory dep.hex~add dep = $( dep) version = $( version) 2> /dev/null || true
@make --no-print-directory dep.hex~enable dep = $( dep) version = ""
@make --no-print-directory dep.git~disable dep = $( dep) repo = ""
@make --no-print-directory dep.local~disable dep = $( dep) path = ""
2021-01-07 13:02:25 +00:00
2021-05-22 14:36:40 +00:00
dep.hex~% : ## add/enable/disable/delete a hex dep with messctl command, eg: `make dep.hex.enable dep=pointers version="~> 0.2"
2022-01-17 06:19:58 +00:00
@make --no-print-directory messctl args = " $* $( dep) $( version) "
2022-04-15 19:56:35 +00:00
@make --no-print-directory cmd cmd = " mix deps.clean $( dep) "
2021-01-09 12:50:23 +00:00
2021-05-22 14:36:40 +00:00
dep.git~% : ## add/enable/disable/delete a git dep with messctl command, eg: `make dep.hex.enable dep=pointers repo=https://github.com/bonfire-networks/pointers#main
@make --no-print-directory messctl args = " $* $( dep) $( repo) config/deps.git "
2022-04-15 19:56:35 +00:00
@make --no-print-directory cmd cmd = " mix deps.clean $( dep) "
2021-01-09 12:50:23 +00:00
2021-05-22 14:36:40 +00:00
dep.local~% : ## add/enable/disable/delete a local dep with messctl command, eg: `make dep.hex.enable dep=pointers path=./libs/pointers
@make --no-print-directory messctl args = " $* $( dep) $( path) config/deps.path "
2022-04-15 19:56:35 +00:00
@make --no-print-directory cmd cmd = " mix deps.clean $( dep) "
2021-05-18 18:42:06 +00:00
2021-05-22 14:36:40 +00:00
messctl~% : ## Utility to manage the deps in deps.hex, deps.git, and deps.path (eg. `make messctl~help`)
@make --no-print-directory messctl args = $*
2020-12-31 13:17:10 +00:00
2021-05-22 14:36:40 +00:00
messctl : init
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run web messctl $( args)
e l s e i f e q ( $( WITH_DOCKER ) , e a s y )
docker-compose run web messctl $( args)
e l s e
echo "Make sure you have compiled/installed messctl first: https://github.com/bonfire-networks/messctl"
messctl $( args)
e n d i f
2021-05-06 17:43:03 +00:00
2021-01-13 20:44:05 +00:00
2021-05-22 14:36:40 +00:00
#### CONTRIBUTION RELATED COMMANDS ####
2021-05-11 12:16:15 +00:00
2022-01-25 05:05:42 +00:00
contrib.forks : contrib .forks .publish git .publish ## Push all changes to the app and extensions in ./forks
2021-04-20 13:07:54 +00:00
2021-05-22 14:36:40 +00:00
contrib.release : contrib .forks .publish contrib .app .release ## Push all changes to the app and extensions in ./forks, increment the app version number, and push a new version/release
2021-04-20 13:07:54 +00:00
2021-05-22 14:36:40 +00:00
contrib.app.up : update .app git .publish ## Update ./deps and push all changes to the app
2021-04-20 13:07:54 +00:00
2021-05-22 14:36:40 +00:00
contrib.app.release : update .app contrib .app .release .increment git .publish ## Update ./deps, increment the app version number and push
contrib.app.release.increment :
2022-01-05 21:22:52 +00:00
@cd lib/mix/tasks/release/ && mix escript.build && ./release ../../../../ $( APP_VSN_EXTRA)
2021-05-22 14:36:40 +00:00
contrib.forks.publish :
2022-01-05 21:22:52 +00:00
@jungle git fetch || echo "Jungle not available, will fetch one by one instead."
@chmod +x git-publish.sh && find $( FORKS_PATH) -mindepth 1 -maxdepth 1 -type d -exec ./git-publish.sh { } \;
# TODO: run in parallel?
2021-04-20 13:07:54 +00:00
2021-05-22 14:36:40 +00:00
git.forks.add : deps .git .fix ## Run the git add command on each fork
find $( FORKS_PATH) -mindepth 1 -maxdepth 1 -type d -exec echo add { } \; -exec git -C '{}' add --all . \;
2021-06-08 11:49:59 +00:00
git.forks.status : ## Run a git status on each fork
2022-01-05 21:22:52 +00:00
@jungle git status || find $( FORKS_PATH) -mindepth 1 -maxdepth 1 -type d -exec echo { } \; -exec git -C '{}' status \;
2021-06-01 18:27:22 +00:00
2021-05-22 14:36:40 +00:00
git.forks~% : ## Run a git command on each fork (eg. `make git.forks~pull` pulls the latest version of all local deps from its git remote
2021-06-01 18:27:22 +00:00
@find $( FORKS_PATH) -mindepth 1 -maxdepth 1 -type d -exec echo $* { } \; -exec git -C '{}' $* \;
2021-05-22 14:36:40 +00:00
2022-02-28 09:39:28 +00:00
git.diff : ## List all diffs in forks
@find $( FORKS_PATH) -mindepth 1 -maxdepth 1 -type d -exec echo { } \; -exec git -C '{}' --no-pager diff --color --exit-code \;
deps.git.fix : ## Run a git command on each dep, to ignore chmod changes
find ./deps -mindepth 1 -maxdepth 1 -type d -exec git -C '{}' config core.fileMode false \;
find ./forks -mindepth 1 -maxdepth 1 -type d -exec git -C '{}' config core.fileMode false \;
git.merge~% : ## Draft-merge another branch, eg `make git-merge-with-valueflows-api` to merge branch `with-valueflows-api` into the current one
git merge --no-ff --no-commit $*
git.conflicts : ## Find any git conflicts in ./forks
find $( FORKS_PATH) -mindepth 1 -maxdepth 1 -type d -exec echo add { } \; -exec git -C '{}' diff --name-only --diff-filter= U \;
git.publish :
chmod +x git-publish.sh
./git-publish.sh
2021-05-22 14:36:40 +00:00
#### TESTING RELATED COMMANDS ####
2021-06-03 11:24:50 +00:00
test.env :
$( eval export MIX_ENV = test )
2022-04-13 13:55:20 +00:00
$( eval export SERVER_PORT = 4001)
$( eval export PUBLIC_PORT = 4001)
2022-03-16 04:30:58 +00:00
test.env.server : test .env
$( eval export START_SERVER = true )
2021-06-03 11:24:50 +00:00
test : init test .env ## Run tests. You can also run only specific tests, eg: `make test only=forks/bonfire_social/test`
2021-05-22 14:36:40 +00:00
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run web mix test $( only)
e l s e
mix test $( only)
e n d i f
2021-06-03 11:24:50 +00:00
test.stale : init test .env ## Run only stale tests
2021-05-22 14:36:40 +00:00
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run web mix test $( only) --stale
e l s e
mix test $( only) --stale
e n d i f
2021-06-03 11:24:50 +00:00
test.remote : test .env ## Run tests (ignoring changes in local forks)
2021-05-22 14:36:40 +00:00
@make --no-print-directory mix.remote~" test $( only) "
2021-06-10 14:46:57 +00:00
test.watch : init test .env ## Run stale tests, and wait for changes to any module's code, and re-run affected tests
2021-05-22 14:36:40 +00:00
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run web mix test.watch --stale $( only)
e l s e
mix test.watch --stale $( only)
e n d i f
2021-06-10 14:46:57 +00:00
test.interactive : init test .env ## Run stale tests, and wait for changes to any module's code, and re-run affected tests, and interactively choose which tests to run
2021-06-10 10:02:52 +00:00
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run web mix test.interactive --stale $( only)
e l s e
mix test.interactive --stale $( only)
e n d i f
2021-05-22 14:36:40 +00:00
# dev-test-watch: init ## Run tests
# docker-compose run --service-ports -e MIX_ENV=test web iex -S mix phx.server
test.db.reset : init db .pre -migrations ## Create or reset the test DB
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run -e MIX_ENV = test web mix ecto.reset
e l s e
MIX_ENV = test mix ecto.reset
e n d i f
#### RELEASE RELATED COMMANDS (Docker-specific for now) ####
2021-06-17 10:13:57 +00:00
rel.env :
$( eval export MIX_ENV = prod)
$( eval export )
2021-05-22 14:36:40 +00:00
2021-06-17 10:13:57 +00:00
rel.config.prepare : rel .env # copy current flavour's config, without using symlinks
2022-04-07 05:55:20 +00:00
rm -rf ./data/current_flavour
2022-05-06 03:48:49 +00:00
mkdir -p data
2021-06-17 10:46:47 +00:00
@cp -rfL $( FLAVOUR_PATH) ./data/current_flavour
2021-05-05 11:14:05 +00:00
2022-04-07 05:55:20 +00:00
rel.prepare : rel .env rel .config .prepare # copy current flavour's config, without using symlinks
@mkdir -p forks/ && mkdir -p data/uploads/ && touch data/current_flavour/config/deps.path
rel.rebuild : rel .env init rel .prepare assets .prepare ## Build the Docker image
2021-04-20 13:07:54 +00:00
docker build \
--no-cache \
2021-06-17 10:46:47 +00:00
--build-arg FLAVOUR_PATH = data/current_flavour \
2021-04-20 13:07:54 +00:00
--build-arg APP_NAME = $( APP_NAME) \
--build-arg APP_VSN = $( APP_VSN) \
--build-arg APP_BUILD = $( APP_BUILD) \
-t $( APP_DOCKER_REPO) :$( APP_VSN) -release-$( APP_BUILD) \
-f $( APP_REL_DOCKERFILE) .
@echo Build complete: $( APP_DOCKER_REPO) :$( APP_VSN) -release-$( APP_BUILD)
2022-04-07 05:55:20 +00:00
rel.build : rel .env init rel .prepare assets .prepare ## Build the Docker image using previous cache
2021-06-16 19:25:54 +00:00
@echo " Building $( APP_NAME) with flavour $( FLAVOUR) "
2021-04-20 13:07:54 +00:00
docker build \
2021-06-17 10:46:47 +00:00
--build-arg FLAVOUR_PATH = data/current_flavour \
2021-04-20 13:07:54 +00:00
--build-arg APP_NAME = $( APP_NAME) \
--build-arg APP_VSN = $( APP_VSN) \
--build-arg APP_BUILD = $( APP_BUILD) \
-t $( APP_DOCKER_REPO) :$( APP_VSN) -release-$( APP_BUILD) \
-f $( APP_REL_DOCKERFILE) .
@echo Build complete: $( APP_DOCKER_REPO) :$( APP_VSN) -release-$( APP_BUILD)
2021-06-17 10:46:47 +00:00
@echo "Remember to run make rel.tag.latest or make rel.push"
2021-04-20 13:07:54 +00:00
2021-06-17 13:44:30 +00:00
rel.tag.latest : rel .env ## Add latest tag to last build
2021-04-20 13:07:54 +00:00
@docker tag $( APP_DOCKER_REPO) :$( APP_VSN) -release-$( APP_BUILD) $( APP_DOCKER_REPO) :latest
2021-06-17 13:44:30 +00:00
rel.push : rel .env ## Add latest tag to last build and push to Docker Hub
2021-04-20 13:07:54 +00:00
@docker push $( APP_DOCKER_REPO) :latest
2021-06-17 10:13:57 +00:00
rel.run : rel .env init docker .stop .web ## Run the app in Docker & starts a new `iex` console
2021-09-26 09:15:32 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) run --name $( WEB_CONTAINER) --service-ports --rm web bin/bonfire start_iex
2021-04-20 13:07:54 +00:00
2021-06-17 10:13:57 +00:00
rel.run.bg : rel .env init docker .stop .web ## Run the app in Docker, and keep running in the background
2021-04-20 13:07:54 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) up -d
2021-06-17 13:44:30 +00:00
rel.stop : rel .env ## Stop the running release
2021-04-20 13:07:54 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) stop
2022-01-17 09:27:11 +00:00
rel.update : rel .env update .repo .pull
2021-06-22 21:02:04 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) pull
@echo Remember to run migrations on your DB...
2021-11-23 10:23:33 +00:00
rel.logs :
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) logs
2021-06-20 11:53:57 +00:00
rel.down : rel .env rel .stop ## Stop the running release
2021-06-17 10:13:57 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) down
2021-06-20 11:53:57 +00:00
rel.shell : rel .env init docker .stop .web ## Runs a the app container and opens a simple shell inside of the container, useful to explore the image
2021-09-26 09:15:32 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) run --name $( WEB_CONTAINER) --service-ports --rm web /bin/bash
2021-05-13 20:05:27 +00:00
2021-06-22 13:26:54 +00:00
rel.shell.bg : rel .env init ## Runs a simple shell inside of the running app container, useful to explore the image
2021-06-20 11:57:10 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) exec web /bin/bash
2021-06-20 11:53:57 +00:00
2021-06-22 13:26:54 +00:00
rel.db.shell.bg : rel .env init ## Runs a simple shell inside of the DB container, useful to explore the image
2021-06-20 11:57:10 +00:00
@docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) exec db /bin/bash
2021-06-20 11:53:57 +00:00
2021-06-22 13:26:54 +00:00
rel.db.dump : rel .env init
docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) exec db /bin/bash -c " PGPASSWORD= $( POSTGRES_PASSWORD) pg_dump --username $( POSTGRES_USER) $( POSTGRES_DB) " > data/db_dump.sql
2021-06-20 11:53:57 +00:00
2021-06-22 13:26:54 +00:00
rel.db.restore : rel .env init
cat $( file) | docker exec -i bonfire_release_db_1 /bin/bash -c " PGPASSWORD= $( POSTGRES_PASSWORD) psql -U $( POSTGRES_USER) $( POSTGRES_DB) "
2021-05-19 06:42:43 +00:00
2021-05-22 14:36:40 +00:00
#### DOCKER-SPECIFIC COMMANDS ####
2021-06-17 14:08:31 +00:00
services : ## Start background docker services (eg. db and search backends).
i f e q ( $( MIX_ENV ) , p r o d )
docker-compose -p $( APP_REL_CONTAINER) -f $( APP_REL_DOCKERCOMPOSE) up -d db search
e l s e
2021-05-22 14:36:40 +00:00
i f e q ( $( WITH_DOCKER ) , n o )
@echo ....
e l s e
docker-compose up -d db search
e n d i f
2021-06-17 10:06:13 +00:00
e n d i f
2021-05-22 14:36:40 +00:00
build : init ## Build the docker image
2021-07-10 19:05:56 +00:00
i f e q ( $( WITH_DOCKER ) , n o )
2021-05-22 14:36:40 +00:00
@echo Skip building container...
2021-07-10 19:05:56 +00:00
e l s e
@mkdir -p deps
2021-11-23 09:59:59 +00:00
docker-compose pull
2021-07-10 19:05:56 +00:00
docker-compose build
2021-05-22 14:36:40 +00:00
e n d i f
2021-10-05 02:40:01 +00:00
rebuild : init ## Build the docker image
i f e q ( $( WITH_DOCKER ) , n o )
@echo Skip building container...
e l s e
@mkdir -p deps
docker-compose build --no-cache
e n d i f
2021-05-22 14:36:40 +00:00
cmd~% : init ## Run a specific command in the container, eg: `make cmd-messclt` or `make cmd~time` or `make cmd~echo args=hello`
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run --service-ports web $* $( args)
e l s e
@$* $( args)
e n d i f
shell : init ## Open the shell of the Docker web container, in dev mode
@make cmd~bash
docker.stop.web :
2021-09-26 09:15:32 +00:00
@docker stop $( WEB_CONTAINER) 2> /dev/null || true
@docker rm $( WEB_CONTAINER) 2> /dev/null || true
2021-05-22 14:36:40 +00:00
#### MISC COMMANDS ####
2021-07-22 12:02:11 +00:00
cmd : init
2021-05-22 14:36:40 +00:00
i f e q ( $( WITH_DOCKER ) , t o t a l )
2021-07-22 12:02:11 +00:00
docker-compose run web bash -c " $( cmd) $( args) "
2021-05-22 14:36:40 +00:00
e l s e
2021-07-22 12:02:11 +00:00
$( cmd) $( args)
2021-05-22 14:36:40 +00:00
e n d i f
2021-07-22 12:02:11 +00:00
cmd~% : init ## Run a specific command, eg: `make cmd~"mix deps.get"` or `make cmd~deps.update args=pointers`
2021-09-19 21:02:18 +00:00
@make --no-print-directory cmd cmd = " $* " $( args)
2021-07-22 12:02:11 +00:00
mix~% : init ## Run a specific mix command, eg: `make mix~deps.get` or `make mix~deps.update args=pointers`
@make --no-print-directory cmd cmd = " mix $* " $( args)
2021-05-22 14:36:40 +00:00
mix.remote~% : init ## Run a specific mix command, while ignoring any deps cloned into ./forks, eg: `make mix~deps.get` or `make mix~deps.update args=pointers`
i f e q ( $( WITH_DOCKER ) , t o t a l )
docker-compose run -e WITH_FORKS = 0 web mix $* $( args)
e l s e
WITH_FORKS = 0 mix $* $( args)
e n d i f
2022-05-09 01:35:31 +00:00
i f e q ( e x h , $( firstword $ ( MAKECMDGOALS ) ) )
args := $( wordlist 2, $( words $( MAKECMDGOALS) ) , $( MAKECMDGOALS) )
$( eval $( args) :; @true)
e n d i f
exh% : init ## ## Run a specific exh command, see https://github.com/rowlandcodes/exhelp
@exh -S mix $( args)
2021-05-22 14:36:40 +00:00
licenses : init
2022-02-24 18:39:19 +00:00
@mkdir -p docs/DEPENDENCIES/
@make --no-print-directory mix.remote~licenses && mv DEPENDENCIES.md docs/DEPENDENCIES/$( FLAVOUR) .md
2021-05-22 14:36:40 +00:00
2021-06-09 11:42:40 +00:00
localise.extract :
@make --no-print-directory mix~"bonfire.localise.extract --merge"
2021-06-04 08:58:52 +00:00
2021-05-22 14:36:40 +00:00
assets.prepare :
2021-06-16 19:25:54 +00:00
@cp lib/*/*/overlay/* rel/overlays/ 2> /dev/null || true
2021-05-22 14:36:40 +00:00
db.pre-migrations : ## Workaround for some issues running migrations
touch deps/*/lib/migrations.ex 2> /dev/null || echo "continue"
touch forks/*/lib/migrations.ex 2> /dev/null || echo "continue"
touch priv/repo/* 2> /dev/null || echo "continue"
2021-06-04 08:02:25 +00:00
secrets :
@cd lib/mix/tasks/secrets/ && mix escript.build && ./secrets 128 3