aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Dockerfile17
-rw-r--r--README.md8
-rw-r--r--compose.yaml24
-rw-r--r--container.env.example7
-rw-r--r--package.json4
-rwxr-xr-xscripts/build-image.sh8
-rwxr-xr-xscripts/image-startup.sh5
-rwxr-xr-xscripts/start-local-db.sh (renamed from start-local-db.sh)0
9 files changed, 72 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 26fe5e3..8d8a4fc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,7 +27,7 @@ yarn-error.log*
# local env files
.env*.local
-.env
+*.env
# vercel
.vercel
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..0966017
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,17 @@
+FROM node:slim
+
+EXPOSE 3000/tcp
+WORKDIR /usr/app
+COPY ./ ./
+
+SHELL ["/bin/bash", "-c"]
+
+RUN apt update && \
+ apt install openssl -y && \
+ apt clean && \
+ apt autoclean && \
+ apt autoremove && \
+ npm install --ignore-scripts && \
+ npm install -g prisma
+
+ENTRYPOINT ["/bin/bash", "-c", "scripts/image-startup.sh"]
diff --git a/README.md b/README.md
index 05bc64b..2301307 100644
--- a/README.md
+++ b/README.md
@@ -35,10 +35,16 @@ The project is open to contributions. Feel free to open an issue or even a pull-
1. Clone the repository (or fork it if you intend to contribute)
2. `npm install`
-3. Start a PostgreSQL server. You can run `./start-local-db.sh` if you don’t have a server already.
+3. Start a PostgreSQL server. You can run `./scripts/start-local-db.sh` if you don’t have a server already.
4. Copy the file `.env.example` as `.env`
5. `npm run dev`
+## Run in a container
+1. Run `npm run build-image` to build the docker image from the Dockerfile
+2. Copy the file `container.env.example` as `container.env`
+3. Run `npm run start-container` to start the postgres and the spliit2 containers
+3. You can access the app by browsing to http://localhost:3000
+
## License
MIT, see [LICENSE](./LICENSE).
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 0000000..86a4656
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,24 @@
+services:
+ app:
+ image: spliit2:latest
+ ports:
+ - 3000:3000
+ env_file:
+ - container.env
+ depends_on:
+ db:
+ condition: service_healthy
+
+ db:
+ image: postgres:latest
+ ports:
+ - 5432:5432
+ env_file:
+ - container.env
+ volumes:
+ - /var/lib/postgresql/data:/var/lib/postgresql/data
+ healthcheck:
+ test: ["CMD-SHELL", "pg_isready -U postgres"]
+ interval: 5s
+ timeout: 5s
+ retries: 5
diff --git a/container.env.example b/container.env.example
new file mode 100644
index 0000000..ecfc160
--- /dev/null
+++ b/container.env.example
@@ -0,0 +1,7 @@
+# db
+POSTGRES_PASSWORD=1234
+
+# app
+POSTGRES_PRISMA_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db
+POSTGRES_URL_NON_POOLING=postgresql://postgres:${POSTGRES_PASSWORD}@db
+NEXT_PUBLIC_BASE_URL=http://localhost:3000
diff --git a/package.json b/package.json
index 23bd680..fb15f06 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,9 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
- "postinstall": "prisma migrate deploy && prisma generate"
+ "postinstall": "prisma migrate deploy && prisma generate",
+ "build-image": "./scripts/build-image.sh",
+ "start-container": "docker compose --env-file container.env up"
},
"dependencies": {
"@hookform/resolvers": "^3.3.2",
diff --git a/scripts/build-image.sh b/scripts/build-image.sh
new file mode 100755
index 0000000..55ef4a4
--- /dev/null
+++ b/scripts/build-image.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+SPLIIT_APP_NAME=$(node -p -e "require('./package.json').name")
+SPLIIT_VERSION=$(node -p -e "require('./package.json').version")
+
+docker buildx build --no-cache -t ${SPLIIT_APP_NAME}:${SPLIIT_VERSION} -t ${SPLIIT_APP_NAME}:latest .
+
+docker image prune -f
diff --git a/scripts/image-startup.sh b/scripts/image-startup.sh
new file mode 100755
index 0000000..8a3a90a
--- /dev/null
+++ b/scripts/image-startup.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+prisma migrate deploy
+prisma generate
+npm run dev
diff --git a/start-local-db.sh b/scripts/start-local-db.sh
index c97173d..c97173d 100755
--- a/start-local-db.sh
+++ b/scripts/start-local-db.sh