Parcourir la source

Update docker and makefile

Dima il y a 1 an
Parent
commit
664d562557
4 fichiers modifiés avec 84 ajouts et 55 suppressions
  1. 33 20
      Makefile
  2. 0 15
      build/docker/docker-compose.yml
  3. 16 0
      docker-compose.yml
  4. 35 20
      readme.md

+ 33 - 20
Makefile

@@ -1,46 +1,59 @@
-include config/.env
+include .env
 
-GOOSE_DB_STRING = ${DB_USER}:${DB_PASSWORD}@/${DB_NAME}?parseTime=true
+GOOSE_DB_STRING = "user=${DB_USER} password=${DB_PASSWORD} dbname=${DB_NAME} port=${DB_PORT} host=${DB_HOST} sslmode=disable"
 
 usage:
 	@echo "make run"
-	@echo "make app-build"
-	@echo "make lint"
 	@echo "make test"
 	@echo "make test-cover"
+	@echo "make lint"
+	@echo "make migration-status"
+	@echo "make migration-up"
+	@echo "make migration-down"
 	@echo "make docker-build"
 	@echo "make docker-up"
 	@echo "make docker-down"
-	@echo "make migration-status"
-	@echo "make migration-up"
+	@echo "make install-deps"
+	@echo "make app-build"
 
 run:
 	cd cmd/app && go run main.go
 
-app-build:
-	env GOOS=linux GOARCH=amd64 go build -o build/app/app cmd/app/main.go
+test:
+	go test ./...
+
+test-cover:
+	go test ./... -coverprofile=./coverage.out
+	go tool cover -html=./coverage.out
 
 lint:
 	golangci-lint run --timeout=3m
 
-test:
-	go test ./...
+migration-status:
+	goose -dir migrations postgres ${GOOSE_DB_STRING} status
 
-test-cover:
-	go test ./... -coverprofile=build/coverage.out
-	go tool cover -html=build/coverage.out
+migration-up:
+	goose -dir migrations postgres ${GOOSE_DB_STRING} up
+
+migration-down:
+	goose -dir migrations postgres ${GOOSE_DB_STRING} down
 
 docker-build:
-	docker compose --file build/docker/docker-compose.yml --env-file config/.env --project-name dmitriygnatenko up --build --detach
+	docker compose up --build --detach
 
 docker-up:
-	docker compose --file build/docker/docker-compose.yml --env-file config/.env --project-name dmitriygnatenko up --detach
+	docker compose up --detach
 
 docker-down:
-	docker compose --file build/docker/docker-compose.yml --env-file config/.env --project-name dmitriygnatenko down
+	docker compose down
 
-migration-status:
-	goose -dir migrations mysql ${GOOSE_DB_STRING} status
+install-deps: install-lint install-goose
 
-migration-up:
-	goose -dir migrations mysql ${GOOSE_DB_STRING} up
+install-lint:
+	go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
+
+install-goose:
+	go install github.com/pressly/goose/v3/cmd/goose@latest
+
+app-build:
+	env GOOS=linux GOARCH=amd64 go build -o build/app/app cmd/app/main.go

+ 0 - 15
build/docker/docker-compose.yml

@@ -1,15 +0,0 @@
-version: "3"
-
-services:
-
-    db:
-        image: mariadb:10.5
-        ports:
-            - ${DB_PORT}:3306
-        volumes:
-            - ./mysql:/var/lib/mysql
-        environment:
-            - MARIADB_DATABASE=${DB_NAME}
-            - MARIADB_USER=${DB_USER}
-            - MARIADB_PASSWORD=${DB_PASSWORD}
-            - MARIADB_ROOT_PASSWORD=${DB_PASSWORD}

+ 16 - 0
docker-compose.yml

@@ -0,0 +1,16 @@
+version: "3"
+
+services:
+  db:
+    image: postgres:15.1-alpine
+    ports:
+      - ${DB_PORT}:5432
+    volumes:
+      - dmitriygnatenko_pg_data:/var/lib/postgresql/data
+    environment:
+      - POSTGRES_DB=${DB_NAME}
+      - POSTGRES_USER=${DB_USER}
+      - POSTGRES_PASSWORD=${DB_PASSWORD}
+
+volumes:
+  dmitriygnatenko_pg_data:

+ 35 - 20
readme.md

@@ -6,33 +6,48 @@ config/.env
 APP_PORT=8080
 
 DB_HOST=localhost
-DB_PORT=3306
-DB_NAME=
-DB_USER=
-DB_PASSWORD=
-
-SMTP_HOST=
-SMTP_PORT=
-SMTP_USER=
-SMTP_PASSWORD=
-
-STATIC_VERSION=
-GA_ENABLED=
-
-ADMIN_EMAIL=
-ADMIN_USER=
-ADMIN_PASSWORD=
+DB_PORT=5432
+DB_NAME=homethings
+DB_USER=user
+DB_PASSWORD=pass
+
+DB_MAX_OPEN_CONNS=0
+DB_MAX_IDLE_CONNS=5
+DB_MAX_CONN_LIFETIME=0
+DB_MAX_IDLE_CONN_LIFETIME=300
+
+CORS_ALLOW_ORIGING=*
+CORS_ALLOW_METHODS=GET,POST,PUT,DELETE
+
+SMTP_HOST=smtp.example.com
+SMTP_PORT=25
+SMTP_USER=example@example.com
+SMTP_PASSWORD=5cCd5m2
+
+ERRORS_EMAIL=example@example.com
+
+JWT_SECRET_KEY=test_secret
+JWT_LIFETIME=21600
+
+BASIC_AUTH_USER=user
+BASIC_AUTH_PASSWORD=pass
+
+STATIC_VERSION=1
+
+GA_KEY=UA-1111111-1 (empty for disable)
 ```
 
 ### Команды
 
 - make run (запуск приложения)
-- make app-build (компиляция приложения)
-- make lint (запуск линтера)
 - make test (запуск тестов)
 - make test-cover (статистика по покрытию тестами)
+- make lint (запуск линтера)
+- make migration-status (статус миграций)
+- make migration-up (применение миграций)
+- make migration-down (откат миграций)
 - make docker-build (сборка контейнеров)
 - make docker-up (запуск контейнеров)
 - make docker-down (остановка контейнеров)
-- make migration-status (статус миграций)
-- make migration-up (применение миграций)
+- make install-deps (установка зависимостей)
+- make app-build (компиляция приложения)