66 lines
2.7 KiB
Makefile
Executable File
66 lines
2.7 KiB
Makefile
Executable File
# Dependencies
|
|
dependencies:
|
|
docker-compose -f ./deployment/dependencies/docker-compose.yaml up -d
|
|
|
|
# Database
|
|
create-migration:
|
|
migrate create -ext sql -dir db/migrations -tz Local init
|
|
|
|
# --- for Macos
|
|
migrate:
|
|
migrate -database 'postgres://bank_admin:bank%40%2323%23%40_password@localhost:5424/bank_db?sslmode=disable' -path db/migrations up
|
|
migrate-rollback:
|
|
migrate -database 'postgres://bank_admin:bank%40%2323%23%40_password@localhost:5424/bank_db?sslmode=disable' -path db/migrations down
|
|
seed:
|
|
docker exec -i main-db psql -U bank_admin -d bank_db -f - < db/seed.sql
|
|
|
|
# ---- for linux
|
|
# migrate:
|
|
# migrate -database 'postgresql://bank_admin:bank%40%2323%23%40_password@localhost:5454/bank_db?sslmode=disable' -path db/migrations up
|
|
# migrate-rollback:
|
|
# migrate -database 'postgresql://bank_admin:bank%40%2323%23%40_password@localhost:5454/bank_db?sslmode=disable' -path db/migrations down
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Deploy: build + upload only (PM2-ni serwerde özüň restart et)
|
|
# ---------------------------------------------------------------------------
|
|
DEPLOY_HOST ?= ubuntu@216.250.10.141
|
|
DEPLOY_DIR ?= /home/ubuntu
|
|
BINARY ?= myapp
|
|
|
|
.PHONY: build-linux deploy swagger
|
|
|
|
swagger:
|
|
swag init -g app.go
|
|
|
|
build-linux:
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o $(BINARY) ./app.go
|
|
|
|
deploy: build-linux
|
|
ssh $(DEPLOY_HOST) 'mkdir -p $(DEPLOY_DIR)'
|
|
scp ./$(BINARY) $(DEPLOY_HOST):$(DEPLOY_DIR)/$(BINARY).new
|
|
ssh $(DEPLOY_HOST) 'cd $(DEPLOY_DIR) && chmod +x $(BINARY).new && mv $(BINARY).new $(BINARY)'
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Docker (serwerde internet ýok). Papka serwere göni göçürilýär:
|
|
# 1) internet bar maşynda: make docker-bundle → dist/ içine ähli image-ler
|
|
# 2) serwerde: make docker-load (bir gezek, ýa-da täze bundle-da)
|
|
# docker compose up -d --build (internetsiz build)
|
|
# ---------------------------------------------------------------------------
|
|
DOCKER_PLATFORM ?= linux/amd64
|
|
DOCKER_BASE_IMAGES ?= golang:1.26.4-alpine postgres:14.1-alpine
|
|
DOCKER_IMAGES ?= main-app:latest main-minio:latest $(DOCKER_BASE_IMAGES)
|
|
DOCKER_BUNDLE ?= dist/online-back-images.tar.gz
|
|
|
|
.PHONY: docker-bundle docker-load
|
|
|
|
docker-bundle:
|
|
for img in $(DOCKER_BASE_IMAGES); do \
|
|
docker image inspect $$img >/dev/null 2>&1 || docker pull --platform $(DOCKER_PLATFORM) $$img || exit 1; \
|
|
done
|
|
DOCKER_DEFAULT_PLATFORM=$(DOCKER_PLATFORM) docker compose build
|
|
mkdir -p $(dir $(DOCKER_BUNDLE))
|
|
docker save $(DOCKER_IMAGES) | gzip > $(DOCKER_BUNDLE)
|
|
|
|
docker-load:
|
|
gunzip -c $(DOCKER_BUNDLE) | docker load
|