sndev bash script and docker reliability stuff

This commit is contained in:
keyan 2024-03-06 19:04:55 -06:00
parent 0614cfe979
commit 51dba02569
4 changed files with 82 additions and 8 deletions

1
.gitignore vendored
View File

@ -34,6 +34,7 @@ envbak
.env.development.local .env.development.local
.env.test.local .env.test.local
.env.production.local .env.production.local
.env.sndev
# vercel # vercel
.vercel .vercel

View File

@ -8,6 +8,5 @@ WORKDIR /app
EXPOSE 3000 EXPOSE 3000
RUN npm install --loglevel verbose --legacy-peer-deps RUN npm ci --loglevel verbose --legacy-peer-deps
RUN npx prisma migrate dev CMD npx prisma migrate dev && npm run dev
CMD npm run dev

View File

@ -4,17 +4,17 @@ services:
container_name: db container_name: db
build: ./db build: ./db
restart: always restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready -U sn -d stackernews"]
interval: 5s
timeout: 5s
retries: 5
expose: expose:
- "5432" - "5432"
ports: ports:
- "5431:5432" - "5431:5432"
env_file: env_file:
- ./.env.sndev - ./.env.sndev
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
volumes: volumes:
- ./anon.sql:/docker-entrypoint-initdb.d/anon.sql - ./anon.sql:/docker-entrypoint-initdb.d/anon.sql
- db:/var/lib/postgresql/data - db:/var/lib/postgresql/data
@ -31,6 +31,10 @@ services:
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
restart: true
opensearch:
condition: service_healthy
restart: true
env_file: env_file:
- ./.env.sndev - ./.env.sndev
expose: expose:
@ -49,10 +53,13 @@ services:
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
restart: true
app: app:
condition: service_healthy condition: service_healthy
restart: true
opensearch: opensearch:
condition: service_healthy condition: service_healthy
restart: true
env_file: env_file:
- ./.env.sndev - ./.env.sndev
ports: ports:
@ -116,6 +123,11 @@ services:
os-dashboard: os-dashboard:
image: opensearchproject/opensearch-dashboards:latest image: opensearchproject/opensearch-dashboards:latest
container_name: os-dashboard container_name: os-dashboard
restart: always
depends_on:
opensearch:
condition: service_healthy
restart: true
environment: environment:
- opensearch.ssl.verificationMode=none - opensearch.ssl.verificationMode=none
- server.ssl.enabled=false - server.ssl.enabled=false

62
sndev Executable file
View File

@ -0,0 +1,62 @@
#!/bin/bash
sndev__start() {
if [ ! -x "$(command -v docker-compose)" ]; then
echo "docker compose is not installed"
echo "installation instructions are here: https://docs.docker.com/desktop/"
exit 0
fi
if ! [ -f .env.sndev ]; then
echo ".env.sndev does not exist."
echo "creating from .env.sample"
cp .env.sample .env.sndev
fi
echo "Starting application"
docker compose up
}
sndev__stop() {
echo "Stopping application"
docker compose down
}
sndev__delete() {
echo "Deleting application"
docker compose down --volumes --remove-orphans
}
sndev__help() {
if [ $# -eq 3 ]; then
call "sndev__$1__$2__$3" "$@"
elif [ $# -eq 2 ]; then
call "sndev__$1__$2" "$@"
else
help="sndev manages a docker based stacker news development environment
USAGE
$ sndev [COMMAND]
COMMANDS
start start env
stop stop env
delete delete env
help display help for sndev
"
echo "$help"
fi
}
call() {
func=$1
if type "$func" 1>/dev/null 2>&1; then
shift
"$func" "$@" # invoke our named function w/ all remaining arguments
else
sndev__help
exit 1
fi
}
call "sndev__$1" "$@"