Docker container version (#39)

* + Dockerfile and compose file
+ Scripts dir and startup script
+ Build image npm script

* * Moves env to file

* + Tags image with info from package.json
* Moves image creation to script
* Updates README

* Update README.md

Co-authored-by: Sebastien Castiel <sebastien@castiel.me>

---------

Co-authored-by: Maxime Jacob <mjacob-no-reply@proton.me>
Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
This commit is contained in:
Max
2024-01-11 15:25:08 -05:00
committed by GitHub
parent ddce4d0bdb
commit 76427c9f13
9 changed files with 72 additions and 3 deletions

2
.gitignore vendored
View File

@@ -27,7 +27,7 @@ yarn-error.log*
# local env files
.env*.local
.env
*.env
# vercel
.vercel

17
Dockerfile Normal file
View File

@@ -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"]

View File

@@ -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 dont have a server already.
3. Start a PostgreSQL server. You can run `./scripts/start-local-db.sh` if you dont 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).

24
compose.yaml Normal file
View File

@@ -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

7
container.env.example Normal file
View File

@@ -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

View File

@@ -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",

8
scripts/build-image.sh Executable file
View File

@@ -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

5
scripts/image-startup.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
prisma migrate deploy
prisma generate
npm run dev