Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 41 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ include make_commands.mk
DOCKER-COMPOSE-FILE=./docker-compose.yml
NOW := `date +%Y-%m-%d_%H%M%S`
EXISTING_DUMP_FILE_NAME := existing-${NOW}.bak
VERSION_FILE = version.txt
IMAGE_VERSION := $(shell cat $(VERSION_FILE))

FILE=""

Expand All @@ -25,21 +27,35 @@ help:
@echo " make logs/backend - view logs for the backend container"
@echo " make upload-skills - upload skills using the provided USER and PASS"


up: start
start:
up:
@docker ps | grep silver-bassoon-db > /dev/null || docker-compose -f ${DOCKER-COMPOSE-FILE} up -d db
@docker ps | grep silver-bassoon-backend > /dev/null || docker-compose -f ${DOCKER-COMPOSE-FILE} up -d backend
@docker ps | grep silver-bassoon-client > /dev/null || docker-compose -f ${DOCKER-COMPOSE-FILE} up -d client
IMAGE_VERSION=$(IMAGE_VERSION) docker compose -f ${DOCKER-COMPOSE-FILE} up -d db backend client

down: stop
stop:
down:
@docker-compose -f ${DOCKER-COMPOSE-FILE} stop client
@docker-compose -f ${DOCKER-COMPOSE-FILE} stop backend
@docker-compose -f ${DOCKER-COMPOSE-FILE} stop db
@docker compose -f ${DOCKER-COMPOSE-FILE} down

build: stop
docker-compose -f ${DOCKER-COMPOSE-FILE} build --no-cache --force-rm
$(eval VERSION=$(shell cat $(VERSION_FILE)))
$(eval NEW_VERSION=$(shell echo $$(( $(VERSION) + 1 ))))
echo $(NEW_VERSION) > $(VERSION_FILE)
IMAGE_VERSION=$(NEW_VERSION) docker compose -f ${DOCKER-COMPOSE-FILE} build --no-cache --force-rm

push:
# Get version
$(eval VERSION=$(shell cat version.txt))
# Tag and push backend image
docker tag 1gency-app-backend:latest visitors/1gency-app:backend-$(VERSION)
docker push visitors/1gency-app:backend-$(VERSION)
# Tag and push client image
docker tag 1gency-app-client:latest visitors/1gency-app:client-$(VERSION)
docker push visitors/1gency-app:client-$(VERSION)


pull:
$(eval VERSION=$(shell cat version.txt))
docker pull visitors/1gency-app:backend-$(VERSION)
docker pull visitors/1gency-app:client-$(VERSION)


################################################################################
Expand All @@ -56,9 +72,9 @@ schema:
real_backup:
@test -d backend/data || mkdir backend/data
@echo ${EXISTING_DUMP_FILE_NAME} > /tmp/current_export_file_name.txt
@docker ps | grep silver-bassoon-db > /dev/null || docker-compose -f ${DOCKER-COMPOSE-FILE} up -d db
@docker exec -it silver-bassoon-db pg_dump -U python upwork_tools -p 5434 > backend/data/`cat /tmp/current_export_file_name.txt`
@( cd backend/data && ln -sf ./`cat /tmp/current_export_file_name.txt` ./latest.bak )
@docker compose -f ${DOCKER-COMPOSE-FILE} up -d db
@docker compose -f ${DOCKER-COMPOSE-FILE} exec -T db pg_dump -U python upwork_tools -p 5434 > backend/data/$(shell cat /tmp/current_export_file_name.txt)
@( cd backend/data && ln -sf ./$(shell cat /tmp/current_export_file_name.txt) ./latest.bak )
@rm -f /tmp/current_export_file_name.txt

backup: real_backup
Expand All @@ -73,24 +89,21 @@ dump: real_backup
################################################################################
# Импорт произвольного дампа в контейнер #
################################################################################

import-v1: stop
@if [ -z ${FILE} ]; then ( echo "Usage: make import FILE=some_file_for_import"; exit 1; ) fi
@if [ ! -f ${FILE} -a ! -h ${FILE} ]; then ( echo "File ${FILE} not found"; exit 1 ) fi
# Оставляем гарантированно только один контейнер, db (совместно с операцией stop).
@docker ps | grep silver-bassoon-db > /dev/null || docker-compose -f ${DOCKER-COMPOSE-FILE} up -d db
@docker compose -f ${DOCKER-COMPOSE-FILE} up -d db
@echo "Copy db file to container..."
@docker cp -L ${FILE} silver-bassoon-db:/tmp/imported_dump.bak || exit 1
@echo "recreate db in container..."
@docker exec -it silver-bassoon-db psql -U python -d postgres -p 5434 -c 'drop database if exists upwork_tools;'
@docker exec -it silver-bassoon-db psql -U python -d postgres -p 5434 -c 'create database upwork_tools;'
@docker compose -f ${DOCKER-COMPOSE-FILE} cp -L ${FILE} db:/tmp/imported_dump.bak || exit 1
@echo "Recreate db in container..."
@docker compose -f ${DOCKER-COMPOSE-FILE} exec -T db psql -U python -d postgres -p 5434 -c 'drop database if exists upwork_tools;'
@docker compose -f ${DOCKER-COMPOSE-FILE} exec -T db psql -U python -d postgres -p 5434 -c 'create database upwork_tools;'
@echo "Import db into container..."
@echo "psql -U python -d upwork_tools -p 5434 < /tmp/imported_dump.bak" > /tmp/recreate_in_docker.sh
@chmod a+x /tmp/recreate_in_docker.sh
@docker cp /tmp/recreate_in_docker.sh silver-bassoon-db:/tmp
@docker exec -it silver-bassoon-db bash /tmp/recreate_in_docker.sh
@docker compose -f ${DOCKER-COMPOSE-FILE} exec -T db bash -c 'psql -U python -d upwork_tools -p 5434 < /tmp/imported_dump.bak'
@echo "** data/latest.bak imported into database container. **"
@make start
@echo "** all containers has been started. **"
@echo "** all containers have been started. **"

import:
@if [ -z ${FILE} ]; then echo "Usage: make import FILE=some_file_for_import"; exit 1; fi
Expand All @@ -102,14 +115,13 @@ import:
@echo "Copy db file to container..."
@docker compose -f ${DOCKER-COMPOSE-FILE} cp -L ${FILE} db:/tmp/imported_dump.bak || exit 1
@echo "Drop old db in container..."
@docker compose -f ${DOCKER-COMPOSE-FILE} exec db bash -c 'PGPASSWORD=python psql -U python -d postgres -p 5434 -c "drop database if exists upwork_tools;"'
@docker compose -f ${DOCKER-COMPOSE-FILE} exec -T db bash -c 'PGPASSWORD=python psql -U python -d postgres -p 5434 -c "drop database if exists upwork_tools;"'
@echo "Initialize blank db in container..."
@docker compose -f ${DOCKER-COMPOSE-FILE} exec db psql -U python -d postgres -p 5434 -c 'create database upwork_tools;'
@docker compose -f ${DOCKER-COMPOSE-FILE} exec -T db psql -U python -d postgres -p 5434 -c 'create database upwork_tools;'
@echo "Import db into container..."
@docker compose -f ${DOCKER-COMPOSE-FILE} exec db bash -c 'psql -U python -d upwork_tools -p 5434 < /tmp/imported_dump.bak'
@docker compose -f ${DOCKER-COMPOSE-FILE} exec -T db bash -c 'psql -U python -d upwork_tools -p 5434 < /tmp/imported_dump.bak'
@docker compose -f ${DOCKER-COMPOSE-FILE} up -d
@echo "** all containers has been started. **"

@echo "** all containers have been started. **"

################################################################################
# Импорт последнего существующего дампа в контейнер #
Expand Down
2 changes: 1 addition & 1 deletion client/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Vue.config.productionTip = false;
// Vue.prototype.$hostname = Vue.config.productionTip
// ? 'http://localhost:5000'
// : 'http://localhost:5000';
Vue.prototype.$hostname = 'http://localhost:5000';
Vue.prototype.$hostname = 'https://app.1gency.ee';
Vue.prototype.appConfig = config;

Vue.component('Wrapper', Wrapper);
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
client:
container_name: silver-bassoon-client
image: visitors/1gency-app:client-${IMAGE_VERSION}
build:
context: client
dockerfile: Dockerfile.dev
Expand All @@ -13,7 +13,7 @@ services:
- backend

backend:
container_name: silver-bassoon-backend
image: visitors/1gency-app:backend-${IMAGE_VERSION}
build:
context: backend
args:
Expand All @@ -30,7 +30,6 @@ services:
FLASK_DEBUG: true

db:
container_name: silver-bassoon-db
image: postgres:16
environment:
POSTGRES_USER: python
Expand Down
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: '3.7'
services:

client:
container_name: silver-bassoon-client
image: visitors/1gency-app:client-${IMAGE_VERSION}
build:
context: client
ports:
Expand All @@ -11,7 +10,7 @@ services:
- backend

backend:
container_name: silver-bassoon-backend
image: visitors/1gency-app:backend-${IMAGE_VERSION}
build:
context: backend
volumes:
Expand All @@ -20,10 +19,9 @@ services:
- '5000:5000'
depends_on:
- db
command: 'gunicorn --bind 0.0.0.0:5000 app:app --timeout 600 -w 3'
command: 'gunicorn --bind 0.0.0.0:5000 app:app'

db:
container_name: silver-bassoon-db
image: postgres:15
environment:
POSTGRES_USER: python
Expand Down
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14