-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
195 lines (169 loc) · 5.68 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# https://taskfile.dev
version: "3"
vars:
HOST: "http://localhost:4000"
ORB_PROD_ROOT: "_build/orb-prod"
# DOCKER_ORB_HOST: "http://hello-phx-web1.orb.local"
DOCKER_ORB_HOST: "https://web.hello-phx.orb.local"
# dotenv: [".envrc"]
includes:
fly-io:
taskfile: ./Taskfile-fly-io.yml
aliases: [f, fly]
optional: true
## Render has first class support for Phoenix applications.
tasks:
default: mix test
sh: iex --erl "-kernel shell_history enabled" -S mix
# iex with test support in test env
tsh: MIX_ENV=test task sh
run: iex --erl "-kernel shell_history enabled" -S mix phx.server
open: open {{.HOST}}
board: open {{.HOST}}/dev/dashboard/home
# json format request: http://localhost:4000/?_format=json
# unknonw page: http://localhost:4000/unknown-page/to/404
deps: mix do deps.get + deps.compile
## Git ops
cmt: mix git_ops.release --yes && git push --follow-tags
app-info: mix git_ops.project_info
init-release: mix git_ops.release --initial
allow-env:
run: once
cmds:
- direnv allow
sources:
- .envrc
## local prod deployment https://hexdocs.pm/phoenix/deployment.html
lp:
cmds:
- |
source .env.prod
MIX_ENV=prod mix phx.server
# with iex
# MIX_ENV=prod iex -S mix phx.server
# in daemon mode
# MIX_ENV=prod elixir --erl "-detached" -S mix phx.server
lp-sh:
cmds:
- |
source .env.prod
MIX_ENV=prod iex -S mix
lp-build:
desc: build local prod release
cmds:
- |
mix deps.get --only prod
MIX_ENV=prod mix compile
MIX_ENV=prod mix assets.deploy
lp-db-setup:
cmds:
- |
source .env.prod
MIX_ENV=prod mix ecto.setup
lp-mig:
cmds:
- |
source .env.prod
MIX_ENV=prod mix ecto.migrate
## Release mode https://hexdocs.pm/phoenix/releases.html
psh: task pbin -- remote
prun: task pbin -- start_iex
pbin:
desc: "run by: task pbin -- start"
cmds:
- |
source .env.prod
_build/prod/rel/hello_phx/bin/hello_phx {{.CLI_ARGS}}
prel:
deps:
- lp-build
cmds:
- |
MIX_ENV=prod mix release --overwrite
pdb: pgcli hello_phx_prod
pmig:
cmds:
- |
source .env.prod
_build/prod/rel/hello_phx/bin/migrate
## Local prod env in Orbstack
# run `orb` into default ubuntu box(ubox1), then do belows in current project root:
orb-home: curl http://ubox1.orb.local:4000/api | jq
orb-ping: curl http://ubox1.orb.local:4000/api/ping
orb-run: orb {{.ORB_PROD_ROOT}}/current/bin/hello_phx {{.CLI_ARGS}}
orb-pid: task orb-run -- pid
orb-sh: task orb-run -- remote
orb-stop: task orb-run -- stop
# deploy a version from github vsn release in orb env, as following:
# task orb-deploy -- v0.1.4
orb-deploy: orb {{.ORB_PROD_ROOT}}/deploy.sh {{.CLI_ARGS}}
orb-setup: |
mkdir {{.ORB_PROD_ROOT}}
orb run/setup.sh {{.ORB_PROD_ROOT}}
orb-setup-local: |
mkdir {{.ORB_PROD_ROOT}}
cp run/deploy.sh {{.ORB_PROD_ROOT}}/
## Docker build with orbstack
dk-build: docker build -t hello_phx .
# docker images
# https://hub.docker.com/r/cao7113/hello-phx
# https://github.com/cao7113/hello-phx/pkgs/container/hello-phx
dk-pull-ghcr: docker pull ghcr.io/cao7113/hello-phx
dk-run: docker run --name hello-phx --rm -it -p 4000:4000 ghcr.io/cao7113/hello-phx bin/hello_phx start_iex
dk-ping: curl http://hello-phx-web-1.orb.local | jq
dk-sh: docker run --rm -it ghcr.io/cao7113/hello-phx sh
# task dcom -- up
dcom: |
docker compose build --build-arg GIT_COMMIT_ID=$(git log -1 --format="%H") --build-arg GIT_COMMIT_TIME=$(git log -1 --format="%ct") web
docker compose {{.CLI_ARGS}}
# docker pull docker.linkos.org/hexpm/elixir:1.17.2-erlang-27.0-debian-bullseye-20240701-slim
# docker pull docker.linkos.org/library/debian:bullseye-20240701-slim
# docker pull docker.linkos.org/library/postgres
## Livebook cluster testing
# Attach on notebook's runtime with: [email protected] and hello cookie
lv-hello1: iex --name [email protected] --cookie hello --erl "-kernel shell_history enabled" -S mix phx.server
# below not work in livebook?
# lv-hello11: iex --sname hello-phx1 --cookie hello --erl "-kernel shell_history enabled" -S mix
lv-start: livebook server {{.CLI_ARGS}}
lv-data: task lv-start -- notebooks/explore-data.livemd
lv-help: task lv-start -- --help
lv-install: mix archive.install hex livebook
# https://fly.io/docs/elixir/advanced-guides/clustering-from-home-to-your-app-in-fly/
lv-fly-remote: run/cluster-with-remote.sh
dns-query: dig hello-phx-up.internal aaaa
## DB Setup
pgcli: pgcli postgresql://postgres:postgres@localhost:5433
# db: sudo -u postgres pgcli hello_phx_dev
sql: pgcli hello_phx_dev
mig: mix ecto.migrate
db-redo:
cmds:
- mix ecto.rollback --step 1
- mix ecto.migrate --step 1
install-pg:
desc: install pg
sources:
- which psql
cmds:
- brew install postgresql
init-pg-user:
desc: create init dev user
cmds:
- echo use postgres as default password
- psql postgres -c "CREATE ROLE postgres LOGIN CREATEDB"
## psql -U postgres -c "\conninfo"
#- createuser postgres -s -P
install-pgcli:
desc: install pgcli
sources:
- which pgcli
cmds:
- brew install pgcli
## Setup phx env
setup: mix setup
# https://hexdocs.pm/phoenix/installation.html
# for elixir and erlang install ref https://github.com/cao7113/hello-elixir/blob/main/Taskfile.yml#L27
# install phx app generator
install-phx-new: mix archive.install hex phx_new --force
# mix help phx.new
mk-hello: mix phx.new hello-phx --module HelloPhx --app hello_phx --verbose --install