Skip to content

Commit

Permalink
Dev3 (#21)
Browse files Browse the repository at this point in the history
* update API documantation files

* delete Empty struct

* TP-933 update: results validation func

* dev: rename function NewRandomString

* dev: update: package crypto

* dev add: default avatar for user

* dev add: default avatar

* dev add: ramrepo -- fillPinTableRows, fillSessionTableRows

* TP-6d1 add: choose https/http in config/config.yml

* TP-565 add: TestCheckLogin

* TP-565 add: TeshLogin

* dev del: block else

* added dataSourceName as a new OpenDB argument

* TP-a49 add: fileserver

* TP-565 add,update: added TestSignUp, TestLogout, updated previous tests

* TP-a49 add: log fileserver

* minor update in test

* dev update: passing the config from main and return from main when errors

* dev update: moved the const variable higher

* dev add: wrapping errors in func OpenDB and prealocation

* add targets for testing

* added tests for usecases

* TP-565 add: error test

* dev update: configs, Makefile and handlers auth

* TP-aad add: er-diagram.png and docker-compose file

* TP-aad add: migrations

* TP-aad update: er-diagram.png

* TP-aad update: rename users relation to auth

* TP-ee7 update: change register router and start server

* TP-ee7 update: divided into 3 layers: delivery, usecase, repository

* TP-ee7 add: middleware auth

* TP-46f add: repository based on posgtres

* TP-aad add: description relations and description of functional dependencies

* TP-aad update: relations.md

* TP-aad update: relations.md

* TP-5b0 add: handler upload and change avatar

* TP-5b0 update: change upload avatar dir

* TP-aad update: merge relations auth and profile in profile

* TP-5b0 update: made requests to global variables

* TP-5b0 add: get all data in repository

* TP-aad update: rename migrations: add prefix 00n_*.sql

* TP-5b0 update: get profile info

* TP-5b0 update: entity user

* TP-5b0 update: handler edit user info

* dev2 add: search_path in all migrations

* dev2 add: volumes in docker-compose.yml

* TP-5b0 add: validation of new user data

* TP-e3a add: pin creations

* TP-e3a update: reducing the number of database requests when creating a pin

* TP-e3a add: likes, delete pin

* PT-e3a add: hander for edit pins

* TP-aad_db update: move creating triggers after create tables

* TP-c80 add: middleware with csrf token verification or installation

* TP-c80 update: updated the check for the need to update the csrf token

* TP-c80 update: updated the check for the need to update the csrf token

* TP-2f3 add: repository with storage in redis

* dev2 update: hashing the password when it is changed

* dev2 add: method PUT in allowed

* TP-add_db update: add ERD-description

* dev2 update: cors

* TP-fcc_handlers_board update: add board repository, usecase, moved general validation in /pkg, corrected old tests

* TP-aad add: attribute amout_me for profile relation

* TP-aad add: migrations 003_alter_relations.sql

* TP-5b0 add: attribute AboutMe

* TP-e3a update: select pins from tape

* TP-e3a update: select pin for tape

* TP-e3a add: chek avalability pins

* TP-e3a add: check action fix pin on board

* TP-e3a add: user info when get pin

* TP-ffc_handlers_board update: add response codes/messages

* TP-ffc_handlers_board update: add repo.go with general info about repository layer

* TP-ffc_handlers_board update: add CreateBoard, GetUserBoards, GetCertainBoard handlers

* TP-ffc_handlers_board update: add access for contributors in GetUserBoards handler

* TP-e3a add: getting user pins

* TP-ffc_handlers_board update: add UpdateBoard, DeleteBoard handlers, fixed previous changes

* TP-a9b add: pkg/validator

* TP-ffc_handlers_board update: fixed GetBoardsByUserID, GetBoardByID in board repository

* dev2 add: returning count like when request on set like

* TP-113 add: logger

* TP-113 add: logger in context

* TP-113 add: get logger in handlers

* dev2 add: check set like to pin from user

* TP-113 add: logger with formater

* TP-errors update: usecase image

* TP-erros update: both sides fall into range

* TP-f21 update: responseOk

* TP-f21 update: rename BoardUsecase to boardUsecase

* TP-f21 update: repository board

* TP-f21 update: logger in delivery board

* TP-f21 add: fix pins on board

* TP-28e add: mock for usecases and repositories

* TP-28e_mockTests update: add tests on CreateNewBoard, UpdateBoardInfo

* TP-2e4 update: old test

* TP-28e_mockTests update: add GetBoardsByUsername test

* TP-28e_mockTests update: modified test_with_coverage target

* TP-28e_mockTests update: add GetCertainBoard, GetBoardByUsername tests

* TP-28e_mockTests update: add DeleteCertainBoard test

* TP-28e_mockTests update: moved return value checking into if clause

* TP-28e_mockTests update: moved logger initialization to the outer scope

* TP-28e_mockTests: replaced log.Fatal with t.Fatalf

* TP-2e4 add testing cover

* TP-28e_mockTests update: delete makefile target, delete old pin usecase_test

* TP-28e_mockTests update: update makefile

* dev2 update: deleted generated mock duplicates

* TP-2e4 add: usecase test session and image

* dev2 update: not view deleted pin in tape

* dev2 add: test for usecase pin

* dev2 add: returning count like with delete

* dev2 del: status code 204 on path /api/v1/csrf

* dev2 update: select pin users

* dev2 update: fail test

* TP-2e4 add: cover usecase/pin

* TP-ffc_handlers_board_fix update: add types.go with common content types, defined general errors, add error-code mapping

* TP-ffc_handlers_board_fix update: fixed tags assignment, add GetBoardInfoForUpdade method

* TP-ffc_handlers_board_fix update: moved validation to the delivery layer, add Sanitize() method for entity, usecase structures, add GetBoardInfoForUpdate() method, regenerate mocks

* TP-ffc_handlers_board_fix update: regenerate mocks

* TP-ffc_handlers_board_fix update: add board validation, additional errors, err-code mapping,GetBoardInfoForUpdate() on the delivery layer

* dev 2 update: minor board repo fix

* TP-db2 update: test version of working with the tape

* TP-db2 add: return user id on request login

* TP-db2 update: feed condition change

* dev2 update: fixed error display

* dev2 update: add field in GetCertainBoard response

* TP-db2 update: feed pins

* TP-db2: update repository add filters

* dev2 update: check valid photo for pin

* TP-619 add: config for redis and .env file for postgres

* TP-619 add: pkg config for parse *.conf files

* TP-619 add: connect with config

* TP-619 update: check author for edit pin

* dev2 update: add insertBoard, CreateBoard, GetBoardByUserID tests

* TP-fcc_board_dataflow_change: removed dto from usecase, changed entity structure, add structures on the delivery layer

* dev2 update: fixed pins view on board(s)

* dev2 update: changed null value processing in board repo methods

* dev 2 update: fixed double delete on board

* TP-d07 update: rename func to dirToSave

* update: use PrefixURLImage

* dev2 update: changed permissions on uploaded images, added :8081 in AllowedOrigins

* TP-f07 add: entity Message

* TP-f07 add write layers: delivery, usecase, repository for message

* TP-f07 update sql queries

* TP-f07 add: fake communication via websocket

* TP-f07 add: origin patterns

* TP-f07 add: implementation http.Flusher

* TP-500 update: add global errors package with general application error types, errors

* TP-500 update: add function to get logger from ctx

* TP-500 update: add middleware with request timeout assignment

* TP-500 update: add general rest api errors on the delivery layer, add getCodeStatusHttp for errors, responseErr for err convertion and response assignment

* TP-500 update: add user subscription handlers, converter from postgresql error to application error in user and subscription repos

* TP-409 add: description real time server as .proto

* TP-500_subscriptions update: add handlers for getting user/profile info with subscriptions, made some optimizations

* TP-500_subscriptions: add id field in profile header

* TP-409 add: skeleton real time server

* TP-409 add: partitions package internal/microservices/realtime

* TP-409 update: websocket handler

* TP-409 update func new websocket

* TP-409 update: entity message json tag

* dev3: changed pagination for subscriptions, minor errors update

* dev3 minor: removed default case

* TP-409 add: get feed user chats with other users

* microservice auth

* TP-34d_search: add user, board, pin search with pagination and sort options

* TP-34d_search: changed pin likes aggregation

* TP-4b9 update: auth

* TP-0a2 add: metrics

* TP-34d_search: add DeletePinFromBoard handler

* dev3 minor: deleted redundant query.go from search repo

* TP-0a2 update: move api/auth, api/realtime to internal/api/auth, internal/api/realtime

* dev3 del defer close grpc connect

* dev3 del: scheme https for prometheus target pinspire.online:9100

* dev3 update: change option for proto files

* TP-cc2 add: proto description service messenger

* TP-cc2 add: microservice messenger

* Tp cc2 ms message (#19)

* TP-cc2 update: ms messenger

* TP-cc2 update: rename key metadata for auth

* TP-cc2 add: metrics

* dev3: add author_username field in GetCertainBoard

* dev3 update: address for metrics servers

* dev3 add: eventType in message response

* TP-c01_ci-cd: add Dockerfiles for nginx and microservices, add service deps,healthchecks

* TP-c01_ci-cd: changed prometheus targets, servers addresses from localhost:<port> to :<port>, replaced string servers params with env variables

* TP-3a4 add: output files flag for logging

* dev3 add: generate mocks

* TP-c01_ci-cd: add linter configuration

* TP-c01_ci-cd: add named volumes for postgres and redis, add compose.prod.yml for pulling images while deploying

* TP-c01_ci-cd: add workflows description, add configuration file for ansible, add inventory in .gitignore

* TP-c01_ci-cd: add kafka healthcheck

* TP-c01_ci-cd: deleted nginx config from compose.yml, changed triggers, changed ports

* TP-c01_ci-cd: deleted dev3 from triggers

* TP-c01_ci-cd: changed triggers, add step

* TP-59b add: comments

* TP-6ec_easyjson: generated easyjson, changed serialization for user, board, search, subscription

* TP-1c3 add: notification ws handler

* TP-1c3 update: the subscription is carried out on the backend

* TP-1c3 update: work with realtime for chat

* TP-1c3 update: proto scheme for a reltime microservice

* TP-1c3 update: chat

* TP-1c3 update: rename request publish struct

* TP-1c3 update: regenerate

* TP-1c3 add: notification after commenting on the pin

* TP-1c3 add: easyjson generation

* TP-8da update: returned user from and to when deleting message

* Update websocket.go: delete unused package "os"

* TP-6ec_easyjson: add rest easyjson

* dev4: removed pull request trigger for deploy workflow

* dev4: replaced auth service host:port string with env variables, moved auth config to main.go

* TP-87a_filtration: add filtration of pin content

* TP-87a_filtration: add task with cloud api token provision, add '2023_2_OND_team' folder to dest

* dev4: replaced google vision client with image filter interface

* de4: changed deployment branch, add cloud api token to the .env file

* dev4: add images volume for main service container

* dev4: changed makefile variable, included all branches in CI

---------

Co-authored-by: wonderf00l <maks22036@gmail.com>
Co-authored-by: wonderf00l <105116952+wonderf00l@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 20, 2023
1 parent 255906c commit e94b753
Show file tree
Hide file tree
Showing 125 changed files with 7,019 additions and 849 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Start pinspire CI

on:
workflow_dispatch: {}
push: {}
pull_request:
types: [opened, edited, reopened]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Get repository code
uses: actions/checkout@v4
- name: Test application
continue-on-error: true
run: go test ./...
lint:
runs-on: ubuntu-latest
steps:
- name: Get repository code
uses: actions/checkout@v4
- name: Lint application
run: make lint
build:
runs-on: ubuntu-latest
steps:
- name: Get repository code
uses: actions/checkout@v4
- name: Build application
run: make build_all
58 changes: 58 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Start Pinspire deployment

on:
workflow_dispatch: {}
push:
branches:
- main
- dev4

jobs:
build_images:
runs-on: ubuntu-latest
steps:
- name: get repository code
uses: actions/checkout@v4
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Build docker images of services
run: |
docker build -t pinspireapp/main:latest -f deployments/Dockerfile.main . &
docker build -t pinspireapp/auth:latest -f deployments/Dockerfile.auth . &
docker build -t pinspireapp/realtime:latest -f deployments/Dockerfile.realtime . &
docker build -t pinspireapp/messenger:latest -f deployments/Dockerfile.messenger . &
for p in $(jobs -p); do wait "$p" || { echo "job $p failed" >&2; exit; }; done
- name: Push docker images
run: |
docker push pinspireapp/main:latest &
docker push pinspireapp/auth:latest &
docker push pinspireapp/realtime:latest &
docker push pinspireapp/messenger:latest &
for p in $(jobs -p); do wait "$p" || { echo "job $p failed" >&2; exit; }; done
deploy:
runs-on: ubuntu-latest
needs: build_images
steps:
- name: fetch changes
uses: appleboy/ssh-action@master
with:
host: pinspire.online
username: ${{ secrets.REMOTE_USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
cd ${{ secrets.PINSPIRE_BACKEND_PATH }}
sudo git switch dev4
sudo git pull
- name: deploy application
uses: appleboy/ssh-action@master
with:
host: pinspire.online
username: ${{ secrets.REMOTE_USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
cd ${{ secrets.PINSPIRE_BACKEND_PATH }}/deployments
sudo docker compose down main_service auth_service realtime_service messenger_service
sudo docker rmi pinspireapp/main:latest pinspireapp/auth:latest pinspireapp/realtime:latest pinspireapp/messenger:latest
sudo docker compose -f docker-compose.yml -f compose.prod.yml up -d
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ testdata/
cert/
.env
redis.conf
inventory
keyVision.json
script*
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
.PHONY: build run test test_with_coverage cleantest retest doc generate cover_all currcover
.PHONY: build_auth build_realtime build_messenger
.PHONY: build_auth build_realtime build_messenger build_all
.PHONY: .install-linter lint lint-fast

ENTRYPOINT=cmd/app/main.go
DOC_DIR=./docs
COV_OUT=coverage.out
COV_HTML=coverage.html
CURRCOVER=github.com/go-park-mail-ru/2023_2_OND_team/internal/pkg/delivery/http/v1

PROJECT_BIN = $(CURDIR)/bin
$(shell [ -f bin ] || mkdir -p $(PROJECT_BIN))
GOLANGCI_LINT = $(PROJECT_BIN)/golangci-lint

build:
go build -o bin/app cmd/app/*.go

Expand All @@ -19,6 +24,8 @@ build_realtime:
build_messenger:
go build -o bin/messenger cmd/messenger/*.go

build_all: build build_auth build_realtime build_messenger

run: build
./bin/app

Expand Down Expand Up @@ -51,3 +58,11 @@ currcover:
go test -cover -v -coverprofile=cover.out ${CURRCOVER}
go tool cover -html=cover.out -o cover.html

.install-linter:
[ -f $(PROJECT_BIN)/golangci-lint ] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_BIN) v1.55.2

lint: .install-linter
$(GOLANGCI_LINT) run ./... --config=configs/.golangci.yml

lint-fast: .install-linter
$(GOLANGCI_LINT) run ./... --fast --config=configs/.golangci.yml
13 changes: 11 additions & 2 deletions api/proto/realtime.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ package realtime;

service RealTime {
rpc Publish(PublishMessage) returns (google.protobuf.Empty) {}
rpc Subscribe(Channel) returns (stream Message) {}
rpc Subscribe(Channels) returns (stream Message) {}
}

message Channels {
repeated Channel chans = 1;
}

message Channel {
Expand All @@ -27,10 +31,15 @@ message EventObject {
EventType type = 2;
}

message EventMap {
int64 type = 1;
map<string, string> m = 2;
}

message Message {
oneof body {
EventObject object = 1;
string content = 2;
EventMap content = 2;
}
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/app/config.go

This file was deleted.

20 changes: 19 additions & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ package main

import (
"context"
"flag"
"fmt"
"os"

"github.com/go-park-mail-ru/2023_2_OND_team/internal/app"
"github.com/go-park-mail-ru/2023_2_OND_team/pkg/logger"
"github.com/joho/godotenv"
)

var (
logOutput = flag.String("log", "stdout", "file paths to write logging output to")
logErrorOutput = flag.String("logerror", "stderr", "path to write internal logger errors to.")
)

// @title Pinspire API
Expand All @@ -21,15 +29,25 @@ import (
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

func main() {
godotenv.Load()
flag.Parse()
ctxBase, cancel := context.WithCancel(context.Background())
defer cancel()

log, err := logger.New(logger.RFC3339FormatTime())
log, err := logger.New(
logger.RFC3339FormatTime(),
logger.SetOutputPaths(*logOutput),
logger.SetErrorOutputPaths(*logErrorOutput),
)
if err != nil {
fmt.Println(err)
return
}
defer log.Sync()

configFiles := app.ConfigFiles{
ServerConfigFile: "configs/config.yml",
AddrAuthServer: os.Getenv("AUTH_SERVICE_HOST") + ":" + os.Getenv("AUTH_SERVICE_PORT"), // "localhost:8085",
}
app.Run(ctxBase, log, configFiles)
}
2 changes: 1 addition & 1 deletion cmd/auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package main
import "github.com/go-park-mail-ru/2023_2_OND_team/internal/app/auth"

var configAuth = auth.Config{
Addr: "localhost:8085",
Addr: "0.0.0.0:8085",
RedisFileConfig: "redis.conf",
}
4 changes: 3 additions & 1 deletion cmd/realtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"

"github.com/joho/godotenv"
"google.golang.org/grpc"

rt "github.com/go-park-mail-ru/2023_2_OND_team/internal/api/realtime"
Expand All @@ -16,6 +17,7 @@ import (
const _address = "localhost:8090"

func main() {
godotenv.Load()
log, err := logger.New()
if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -44,7 +46,7 @@ func RealTimeRun(log *logger.Logger, addr string) error {
}

serv := grpc.NewServer(grpc.ChainUnaryInterceptor(
interceptor.Monitoring(metrics, "localhost:8091"),
interceptor.Monitoring(metrics, "0.0.0.0:8091"),
interceptor.Logger(log),
))
rt.RegisterRealTimeServer(serv, realtime.NewServer(node))
Expand Down
Loading

0 comments on commit e94b753

Please sign in to comment.