Skip to content

Commit

Permalink
move pg extras to dcape-pg-upgrade repo
Browse files Browse the repository at this point in the history
  • Loading branch information
LeKovr committed Nov 15, 2020
1 parent b77b7cf commit ac560a4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 141 deletions.
85 changes: 0 additions & 85 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,34 +134,6 @@ apply:
@$(MAKE) -s dc CMD="up -d $(APPS_SYS)" || echo ""
@for f in $(shell echo $(APPS)) ; do $(MAKE) -s $${f}-apply ; done

# Upgrade postgres major version with pg_upgrade
pg_upgrade:
@echo "*** $@ *** " ; \
DCAPE_DB=$${PROJECT_NAME}_db_1 ; \
PG_OLD=`cat ./var/data/db/PG_VERSION` ; \
PG_NEW=`docker inspect --type=image $$PG_IMAGE | jq -r '.[0].ContainerConfig.Env[] | capture("PG_MAJOR=(?<a>.+)") | .a'` ; \
echo "*** $@ *** from $$PG_OLD to $$PG_NEW" ; \
echo -n "Checking PG is down..." ; \
if [[ `docker inspect -f "{{.State.Running}}" $$DCAPE_DB 2>/dev/null` == true ]] ; then \
echo "Postgres container not stop. Exit" && exit 1 ; \
else \
echo "Postgres container not run. Continue" ; \
fi ; \
echo "Move current postgres data directory to ./var/data/db_$$PG_OLD" ; \
mkdir ./var/data/db_$$PG_OLD ; \
mv ./var/data/db/* ./var/data/db_$$PG_OLD/ ; \
cp ./var/data/db_$$PG_OLD/postgresql.conf ./var/data/db_$$PG_OLD/postgresql_store.conf ; \
sed -i "s%include_dir = '/opt/conf.d'%#include_dir = '/opt/conf.d'%" ./var/data/db_$$PG_OLD/postgresql.conf ; \
docker pull tianon/postgres-upgrade:$$PG_OLD-to-$$PG_NEW ; \
docker run --rm \
-v $$PWD/var/data/db_$$PG_OLD:/var/lib/postgresql/$$PG_OLD/data \
-v $$PWD/var/data/db:/var/lib/postgresql/$$PG_NEW/data \
tianon/postgres-upgrade:$$PG_OLD-to-$$PG_NEW ; \
cp -f ./var/data/db_$$PG_OLD/pg_hba.conf ./var/data/db/pg_hba.conf ; \
cp -f ./var/data/db_$$PG_OLD/postgresql_store.conf ./var/data/db/postgresql.conf ; \
echo "If the process succeeds, edit pg_hba.conf, other conf and start postgres container or dcape. \
For more info see https://github.com/dopos/dcape/blob/master/POSTGRES.md"

# build file from app templates
docker-compose.yml: $(DCINC) $(DCFILES)
@echo "*** $@ ***"
Expand Down Expand Up @@ -190,63 +162,6 @@ wild:
wild: CMD=run --rm traefik-acme-wild
wild: dc

# ------------------------------------------------------------------------------
# Upgrade postgres databases via pipeline
upgrade-pg-via-pipe:
@echo "*** $@ *** " ; \
DCAPE_DB=$${PROJECT_NAME}_db_1 ; \
docker pull $$PG_IMAGE ; \
PG_NEW=`docker inspect --type=image $$PG_IMAGE | jq -r '.[0].ContainerConfig.Env[] | capture("PG_MAJOR=(?<a>.+)") | .a'` ; \
echo "Preparing the container with the new postgres version" ; \
PG_PORT_NEW=$(shell expr $(PG_PORT_LOCAL) + 1) ; \
DCAPE_DB_NEW="dcape_db_new" ; \
echo "Deny connections from hosts" ; \
sed -i 's/host all all all md5/#host all all all md5/' $$PWD/var/data/db/pg_hba.conf ; \
docker run --rm -d \
--name dcape_db_new \
-v $$PWD/var/data/db_$$PG_NEW:/var/lib/postgresql/data \
-e "TZ=$$TZ" \
-e "LANG=$$PG_ENCODING" \
--network="d4s_default" \
-p "$$PG_PORT_NEW:5432" \
$$PG_IMAGE ; \
echo -n "Checking for new version PG is ready..." ; \
until [[ `docker inspect -f "{{.State.Running}}" $$DCAPE_DB_NEW` == true ]] ; do sleep 1 ; echo -n "." ; done
@echo "Ok. Run the migration on all databases" ; \
PG_NEW=`docker inspect --type=image $$PG_IMAGE | jq -r '.[0].ContainerConfig.Env[] | capture("PG_MAJOR=(?<a>.+)") | .a'` ; \
DCAPE_DB_NEW="dcape_db_new" ; \
docker exec -i -u postgres $$DCAPE_DB_NEW /bin/bash -c "echo "db:5432:*:postgres:$$PG_DB_PASS" > ~/.pgpass && chmod 0600 ~/.pgpass" ; \
docker exec -i -u postgres $$DCAPE_DB_NEW /bin/bash -c "pg_dumpall -h db -p 5432 | psql && echo "Migration complete." " ; \
docker stop $$DCAPE_DB_NEW ; \
docker stop $$DCAPE_DB ; \
mv ./var/data/db ./var/data/db_previous_version ; \
cp ./var/data/db_/postgresql.conf ./var/data/db_$$PG_OLD/postgresql_store.conf ; \

# echo "If the process succeeds, edit pg_hba.conf, other conf and start postgres container or dcape. \
# For more info see https://github.com/dopos/dcape/blob/master/POSTGRES.md"


# Upgrade postgres major version with pg_dumpall-psql
# Create dump for claster Postgres
pg_dumpall:
@echo "Start $@ to pg_dumpall_$${PROJECT_NAME}_`date +"%d.%m.%Y"`.sql.gz" ;\
DCAPE_DB=$${PROJECT_NAME}_db_1 ; \
docker exec -u postgres $$DCAPE_DB pg_dumpall | gzip -7 -c > \
./var/data/db-backup/pg_dumpall_$${PROJECT_NAME}_`date +"%d.%m.%Y"`.sql.gz

# Load dump for claster Postgres
pg_load_dumpall:
@echo "Start $@ ..." ; \
echo "Load dump file: pg_dumpall_$${PROJECT_NAME}_`date +"%d.%m.%Y"`.sql.gz" ;\
docker exec -u postgres -e PROJECT_NAME=$${PROJECT_NAME} $${PROJECT_NAME}_db_1 \
bash -c 'zcat /opt/backup/pg_dumpall_$${PROJECT_NAME}_`date +"$d.%m.%Y"`.sql.gz | psql' ; \
echo "Load dump complete. Start databases ANALYZE." ; \
docker exec -u postgres $${PROJECT_NAME}_db_1 psql -c "ANALYZE" && \
echo "ANALYZE complete."




# $$PWD используется для того, чтобы текущий каталог был доступен в контейнере по тому же пути
# и относительные тома новых контейнеров могли его использовать
## run docker-compose
Expand Down
55 changes: 0 additions & 55 deletions POSTGRES.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* [webtail](https://github.com/LeKovr/webtail) ([docker](https://store.docker.com/community/images/lekovr/webtail)) - агрегация и www доступ к логам событий приложений (запуск, удаление, обновление)
* [enfist](https://github.com/apisite/app-enfist) ([docker](https://store.docker.com/community/images/apisite/enfist)) - хранилище файлов .env в postgresql
* [narra](https://github.com/dopos/narra) ([docker](https://store.docker.com/community/images/dopos/narra)) - сервис авторизации для nginx через API gitea
* [postgresql](https://www.postgresql.org) ([docker](https://store.docker.com/images/postgres)) - хранение конфигураций приложений и баз данных, если приложению требуется СУБД. Детали в инструкции по работе с [Postgres](POSTGRES.md)
* [postgresql](https://www.postgresql.org) ([docker](https://store.docker.com/images/postgres)) - хранение конфигураций приложений и баз данных, если приложению требуется СУБД. Детали в инструкции по работе с [Postgres](https://github.com/dopos/dcape-pg-upgrade)

**Служебные приложения dcape:**

Expand Down

0 comments on commit ac560a4

Please sign in to comment.