Skip to content

Commit a70591c

Browse files
committed
dx: add Makefile to simplify getting started
1 parent 91cb67a commit a70591c

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LOGIN_CODE_SALT="algora-login-code"
66
LOCAL_STORE_TTL=3600
77
LOCAL_STORE_SALT="algora-local-store"
88

9-
DATABASE_URL="postgresql://algora:password@localhost:5432/algora"
9+
DATABASE_URL="postgresql://postgres:postgres@localhost:15432/algora_dev"
1010

1111
GITHUB_CLIENT_ID=""
1212
GITHUB_CLIENT_SECRET=""

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.PHONY: help install server watch postgres postgres-rm psql
2+
3+
help:
4+
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
5+
6+
install: ## Run the initial setup
7+
mix setup
8+
9+
server: ## Start the web server
10+
iex -S mix phx.server
11+
12+
watch: ## Recompile on file changes
13+
find lib/ | entr mix compile
14+
15+
postgres: ## Start a container with latest postgres
16+
docker run --detach -e POSTGRES_PASSWORD="postgres" -p 15432:5432 --name algora_db --volume=algora_db:/var/lib/postgresql/data postgres:latest
17+
18+
postgres-rm: ## Stop and remove the postgres container
19+
docker stop algora_db && docker rm algora_db
20+
21+
psql: ## Connect to postgres
22+
docker exec -it algora_db psql -U postgres -d algora_dev

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,18 @@ To get a local copy up and running, follow these steps.
112112

113113
### Prerequisites
114114

115-
- PostgreSQL
116-
- [asdf](https://github.com/asdf-vm/asdf) (optional) - install Elixir and Erlang/OTP
117-
- [direnv](https://github.com/direnv/direnv) (optional) - load environment variables
115+
The easiest way to get up and running is to [install](https://docs.docker.com/get-docker/) and use Docker for running Postgres.
116+
117+
Make sure Docker, Elixir, Erlang and Node.js are all installed on your development machine. The [.tool-versions](https://github.com/algora-io/algora/blob/main/.tool-versions) file is available to use with [asdf](https://github.com/asdf-vm/asdf) or similar tools.
118+
119+
We also recommend using [direnv](https://github.com/direnv/direnv) to load environment variables and [entr](https://github.com/eradman/entr) to watch for file changes.
118120

119121
### Setting up the project
120122

121123
1. Clone the repo and go to the project folder
122124

123125
```sh
124-
git clone https://github.com/algora-io/algora.git; cd algora
126+
git clone git@github.com:algora-io/algora.git && cd algora
125127
```
126128

127129
2. Install Elixir and Erlang/OTP
@@ -130,40 +132,34 @@ To get a local copy up and running, follow these steps.
130132
asdf install
131133
```
132134

133-
3. Create a new PostgreSQL user
135+
3. Initialize and load `.env`
134136

135137
```sh
136-
sudo -u postgres psql
137-
```
138-
139-
```sql
140-
CREATE USER algora WITH PASSWORD 'password';
141-
ALTER USER algora WITH CREATEDB;
138+
cp .env.example .env && direnv allow .env
142139
```
143140

144-
4. Initialize and load `.env`
141+
4. Start a container with latest postgres
145142

146143
```sh
147-
cp .env.example .env
148-
direnv allow .env
144+
make postgres
149145
```
150146

151147
5. Install and setup dependencies
152148

153149
```sh
154-
mix setup
150+
make install
155151
```
156152

157-
6. Start your development server
153+
6. Start the web server inside IEx
158154

159155
```sh
160-
iex -S mix phx.server
156+
make server
161157
```
162158

163159
7. (Optional) Watch for file changes and auto reload IEx shell in a separate terminal
164160

165161
```sh
166-
find lib/ | entr mix compile
162+
make watch
167163
```
168164

169165
### Setting up external services

0 commit comments

Comments
 (0)