Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
fix: postgres volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
jreydman committed Oct 5, 2023
1 parent 3fdf692 commit cb73d9c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
!.yarn/sdks
!.yarn/versions
.pnp.*

/database
1 change: 0 additions & 1 deletion server/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/docs
/files


!yarn-offline-mirror/
!.yarn/plugins
!.yarn/releases
Expand Down
3 changes: 3 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ lerna-debug.log*
!.yarn/releases
!.yarn/sdks
!.yarn/versions

/Docker/docker-compose.yaml*

2 changes: 1 addition & 1 deletion server/Docker/app.prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY --from=cache /tmp/node_modules ./node_modules
COPY . .

RUN if [ ! -f .env ]; then cp ./env-example .env; fi
RUN sed -i -e 's/^DATABASE_HOST.*/DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres/' -e 's/^MAIL_HOST.*/MAIL_HOST=${COMPOSE_PROJECT_NAME}-maildev/' .env
RUN sed -i -e 's/^DATABASE_HOST.*/DATABASE_HOST='${COMPOSE_PROJECT_NAME}'-postgres/' -e 's/^MAIL_HOST.*/MAIL_HOST='${COMPOSE_PROJECT_NAME}'-maildev/' .env


COPY ./package*.json .
Expand Down
24 changes: 12 additions & 12 deletions server/Docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ services:
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
volumes: #production-toggle
- db-data:${DATABASE_PATH_CONTAINER}/data #production-toggle
healthcheck:
<<: *common-healthcheck
test: [ "CMD-SHELL", "pg_isready -d ${DATABASE_NAME} -U ${DATABASE_USERNAME}" ]
# <Virtual stage> ports: #toggle
# <Virtual stage> - ${DATABASE_PORT}:${DATABASE_PORT} #toggle
# <Virtual stage> ports: #stage-toggle
# <Virtual stage> - ${DATABASE_PORT}:${DATABASE_PORT} #stage-toggle
#endservice

maildev: #service
Expand All @@ -91,7 +93,7 @@ services:
- ${MAIL_CLIENT_PORT}
- ${MAIL_PORT}
ports:
# <Virtual stage> - ${MAIL_PORT}:${MAIL_PORT} #toggle
# <Virtual stage> - ${MAIL_PORT}:${MAIL_PORT} #stage-toggle
- ${MAIL_CLIENT_PORT}:${MAIL_CLIENT_PORT}
#endservice

Expand Down Expand Up @@ -123,8 +125,6 @@ services:
image: node:18-alpine
working_dir: ${SERVER_PATH_CONTAINER}
command: [ "yarn", "start:development" ]
volumes:
- ../:${SERVER_PATH_CONTAINER}
environment:
- NODE_ENV=development
- DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres
Expand Down Expand Up @@ -158,10 +158,10 @@ services:
- DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres
- MAIL_HOST=${COMPOSE_PROJECT_NAME}-maildev

#volumes:
# db-data:
# driver: local
# driver_opts:
# type: none
# o: bind
# device: ${DATABASE_PATH_LOCAL}/data
volumes:
db-data:
driver: local
driver_opts:
type: none
o: bind
device: ../../database/data
167 changes: 0 additions & 167 deletions server/Docker/docker-compose.yaml''

This file was deleted.

8 changes: 4 additions & 4 deletions server/env-example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ BACKEND_DOMAIN=http://localhost:3000
COMPOSE_PROJECT_NAME=teameights

DATABASE_TYPE=postgres
#localhost
DATABASE_HOST=teameights-postgres
#teameights-postgres
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USERNAME=root
[email protected]
Expand Down Expand Up @@ -38,8 +38,8 @@ ACCESS_KEY_ID=
SECRET_ACCESS_KEY=
AWS_S3_REGION=
AWS_DEFAULT_S3_BUCKET=

MAIL_HOST=teameights-maildev#localhost
#teameights-maildev
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USER=
MAIL_PASSWORD=
Expand Down
22 changes: 18 additions & 4 deletions server/sh-scripts/compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,32 @@ sleep 3

reverse_stage_toggle() {
if [ "$1" = "local" ]; then
echo "Info! Setup docker-compose <Local>"
$sed_command -e '/postgres: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#toggle/\1#toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#toggle/\1#toggle/;}' "$PARENT_DIR"/"$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Setup docker-compose stage-toggle <Local>"
$sed_command -e '/postgres: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#stage-toggle/\1#stage-toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#stage-toggle/\1#stage-toggle/;}' "$PARENT_DIR"/"$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Finish edit docker-compose"

fi
if [ "$1" = "virtual" ]; then
echo "Info! Setup docker-compose <Virtual>"
$sed_command -e '/postgres: #service/,/#endservice/ {;s/\(.*\)#toggle/# <Virtual stage>\1#toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/\(.*\)#toggle/# <Virtual stage>\1#toggle/;}' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Setup docker-compose stage-toggle <Virtual>"
$sed_command -e '/postgres: #service/,/#endservice/ {;s/\(.*\)#stage-toggle/# <Virtual stage>\1#stage-toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/\(.*\)#stage-toggle/# <Virtual stage>\1#stage-toggle/;}' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Finish edit docker-compose"
fi
$sed_command -e 's/# <Virtual stage># <Virtual stage>/# <Virtual stage>/' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
}

reverse_production_toggle() {
if [ "$1" = "true" ]; then
echo "Info! Setup docker-compose production-toggle <Active>"
$sed_command -e '/postgres: #service/,/#endservice/ {;s/# <Production Activity>\(.*\)#production-toggle/\1#production-toggle/;}' "$PARENT_DIR"/"$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Finish edit docker-compose"
else
echo "Info! Setup docker-compose production-toggle <Inactive>"
$sed_command -e '/postgres: #service/,/#endservice/ {;s/\(.*\)#production-toggle/# <Production Activity>\1#production-toggle/;}' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Finish edit docker-compose"
fi
$sed_command -e 's/# <Production Activity># <Production Activity>/# <Production Activity>/' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
}

case $stage in
local)
echo "Step! Running local staging..."
Expand All @@ -93,6 +106,7 @@ case $stage in
virtual)
echo "Step! Running docker staging..."
reverse_stage_toggle "virtual"
if [ "$type" = 'production' ]; then reverse_production_toggle "true"; fi
if [ "$type" = 'development' ]; then type="virtual-development"; fi
echo "Info! Running docker"
docker-compose -f "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml --env-file .env --profile $stage-$type up -d
Expand Down

0 comments on commit cb73d9c

Please sign in to comment.