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 7, 2024
1 parent 2d2a4a4 commit 5095089
Show file tree
Hide file tree
Showing 14 changed files with 1,056 additions and 1,445 deletions.
9 changes: 8 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/nix:1": {}
"ghcr.io/devcontainers/features/nix:1": {
"packages": [
"btop",
"lazygit",
"nixpkgs-fmt"
],
"extraNixConfig": "experimental-features = nix-command flakes"
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
Expand Down
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
6 changes: 3 additions & 3 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 All @@ -20,7 +20,7 @@ Install docker, vscode and the [Dev Containers Extension](https://marketplace.vi

`nix-shell`

`npx npm-check-updates -u`
`npx npm-check-updates -u && npm i --package-lock-only`

# License
All code in this repository is dual-licensed under either [License-MIT](./LICENSE-MIT) or [LICENSE-APACHE](./LICENSE-Apache) at your option. This means you can select the license you prefer. [Why dual license](https://github.com/bevyengine/bevy/issues/2373)
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
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# next-url-shortener
A simple URL shortener using [Next.js](https://nextjs.org/) 14 server actions, [Postgres](https://www.postgresql.org/) or [SurrealDB](https://surrealdb.com/), [Shadcn/ui](http://ui.shadcn.com/) and [Tailwind](https://tailwindcss.com/).
A URL shortener using [Next.js](https://nextjs.org/) 14 server actions, [Postgres](https://www.postgresql.org/) or [SurrealDB](https://surrealdb.com/), [Shadcn/ui](http://ui.shadcn.com/) and [Tailwind](https://tailwindcss.com/).

# Install
### Copy one
Expand All @@ -9,16 +9,22 @@ 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
├── Makefile
├── 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 All @@ -35,7 +41,8 @@ POSTGRES_DB=url
DB_USER=root
DB_PASSWORD=root

OVERRIDE_URL=s.nexv.dev
# Enter your website url here
# OVERRIDE_URL=s.nexv.dev
```

# License
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.9
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
Loading

0 comments on commit 5095089

Please sign in to comment.