Skip to content

Commit

Permalink
makefile and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
NexVeridian committed Aug 3, 2024
1 parent 2d2a4a4 commit 779a12d
Show file tree
Hide file tree
Showing 12 changed files with 1,037 additions and 1,438 deletions.
8 changes: 6 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
.env
.gitignore
Cargo.lock
docker-compose.dev.yml
docker-compose.yml
docker-compose-postgres.yml
docker-compose-postgres.dev.yml
docker-compose-surrealdb.yml
docker-compose-surrealdb.dev.yml
Makefile
Dockerfile
*.md
shell.nix
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
- [docker-compose-postgres.dev.yml](./docker-compose-postgres.dev.yml)
- [docker-compose-surrealdb.dev.yml](./docker-compose-surrealdb.dev.yml)
#### Then run:
- `docker compose -f docker-compose-postgres.dev.yml up --pull always -d`
- `docker compose -f docker-compose-surrealdb.dev.yml up --pull always -d`
- `make up-postgres.dev`
- `make up-surrealdb.dev`

## Dev Containers
Install docker, vscode and the [Dev Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
COMPOSE_FILES := postgres surrealdb postgres.dev surrealdb.dev

.PHONY: $(addprefix up-,$(COMPOSE_FILES)) $(addprefix down-,$(COMPOSE_FILES))

$(addprefix up-,$(COMPOSE_FILES)):
make down-$(subst up-,,$@)
docker compose -f docker-compose-$(subst up-,,$@).yml up --build --pull always -d

$(addprefix down-,$(COMPOSE_FILES)):
docker compose -f docker-compose-$(subst down-,,$@).yml down --volumes --remove-orphans
docker network prune -f
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ A simple URL shortener using [Next.js](https://nextjs.org/) 14 server actions, [
Create data folder next to docker-compose.yml and .env, and set the data type in .env
```
├── data
│ ├── postgres
│ └── surrealdb
├── docker-compose-postgres.yml
└── .env
```
### Then run:
- `docker compose -f docker-compose-postgres.yml up --pull always -d`
- `docker compose -f docker-compose-surrealdb.yml up --pull always -d`
- `make up-postgres`
- `make up-surrealdb`

### Then exit with:
- `make down-postgres`
- `make down-surrealdb`

## Example .env
```
```shell
# postgres or surrealdb
DB_TYPE=postgres

Expand Down
59 changes: 29 additions & 30 deletions docker-compose-postgres.dev.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
version: "3"
services:
next-url-shortener:
container_name: next-url-shortener
build: .
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres
next-url-shortener:
container_name: next-url-shortener
build: .
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres

postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres
postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres

volumes:
data:
data:

networks:
postgres:
postgres:
59 changes: 29 additions & 30 deletions docker-compose-postgres.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
version: "3"
services:
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres

postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres
postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres

volumes:
data:
data:

networks:
postgres:
postgres:
81 changes: 44 additions & 37 deletions docker-compose-surrealdb.dev.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
version: "3"
services:
nextjs:
build: .
env_file:
- .env
ports:
- "3000:3000"
depends_on:
- surrealdb
networks:
- surrealdb
nextjs:
container_name: next-url-shortener
build: .
env_file:
- .env
ports:
- 3000:3000
depends_on:
- surrealdb
networks:
surrealdb:
# ipv4_address: 172.20.0.2

surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:latest-dev
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
restart: always
deploy:
resources:
reservations:
cpus: "1"
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
- surrealdb
surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:v2.0.0-alpha.8
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
user: root
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
surrealdb:
# ipv4_address: 172.20.0.1

volumes:
data:
data:

networks:
surrealdb:
surrealdb:
# ipam:
# config:
# - subnet: 172.20.0.0/16
# gateway: 172.20.0.254
75 changes: 37 additions & 38 deletions docker-compose-surrealdb.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
version: "3"
services:
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- surrealdb
networks:
- surrealdb
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- surrealdb
networks:
- surrealdb

surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:latest-dev
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
restart: always
deploy:
resources:
reservations:
cpus: 1
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
- surrealdb
surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:latest
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
- surrealdb

volumes:
data:
data:

networks:
surrealdb:
surrealdb:
Loading

0 comments on commit 779a12d

Please sign in to comment.