Skip to content

Commit

Permalink
Merge branch 'dev' into BCFW-26-bd2
Browse files Browse the repository at this point in the history
  • Loading branch information
SlashLight authored Dec 22, 2024
2 parents 833390c + e722234 commit 1de1301
Show file tree
Hide file tree
Showing 109 changed files with 12,377 additions and 2,912 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

jobs:

linter:
runs-on: ubuntu-latest
steps:
- run:
sudo apt-get install libwebp-dev
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: false
- name: Set environment variables
run: |
echo "GOROOT=$(go env GOROOT)" >> $GITHUB_ENV
echo "GOBIN=$(go env GOBIN)" >> $GITHUB_ENV
- name: Install golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: golangci-lint
run: golangci-lint run --new-from-rev origin/dev

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...

build:
needs: [tests, linter]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v2
- name: Set up SSH
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Fetch .env file from server
run: |
ssh -o StrictHostKeyChecking=no ubuntu@185.241.194.197 '
# Read the contents of the .env file and output it
cat ~/2024_2_BetterCallFirewall/.env
' > .env
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_LOGIN }} --password-stdin
- name: Build Docker images
run: |
for service in auth authgrpc chat community file post postgrpc profile profilegrpc sticker; do
docker build -t slashlight/${service}:${GITHUB_SHA::8} -t slashlight/${service}:latest -f Dockerfile${service} .
docker push slashlight/${service}:${GITHUB_SHA::8}
docker push slashlight/${service}:latest
done
14 changes: 12 additions & 2 deletions DB/migrations/000001_init_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ CREATE TABLE IF NOT EXISTS post (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
author_id INT REFERENCES profile(id) ON DELETE CASCADE,
community_id INT REFERENCES community(id) ON DELETE CASCADE DEFAULT NULL,
content TEXT CONSTRAINT content_post_length CHECK (CHAR_LENGTH(content) <= 500) DEFAULT '',
file_path TEXT CONSTRAINT file_path_length CHECK (CHAR_LENGTH(file_path) <= 100) DEFAULT '',
content TEXT CONSTRAINT content_post_length CHECK (CHAR_LENGTH(content) <= 1000) DEFAULT '',
file_path TEXT CONSTRAINT file_path_length CHECK (CHAR_LENGTH(file_path) <= 1000) DEFAULT '',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
Expand All @@ -57,6 +57,8 @@ CREATE TABLE IF NOT EXISTS message (
receiver INT REFERENCES profile(id) ON DELETE CASCADE ,
sender INT REFERENCES profile(id) ON DELETE CASCADE ,
content TEXT CONSTRAINT content_message_length CHECK (CHAR_LENGTH(content) <= 500) DEFAULT '',
file_path TEXT CONSTRAINT file_path_message_length CHECK (CHAR_LENGTH(file_path) <= 1000) DEFAULT '',
sticker_path TEXT CONSTRAINT sticker_path_message_length CHECK (CHAR_LENGTH(sticker_path) <= 100) DEFAULT '',
is_read BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
Expand All @@ -67,6 +69,8 @@ CREATE TABLE IF NOT EXISTS comment (
user_id INT REFERENCES profile(id) ON DELETE CASCADE ,
post_id INT REFERENCES post(id) ON DELETE CASCADE ,
content TEXT CONSTRAINT content_comment_length CHECK (CHAR_LENGTH(content) <= 500) DEFAULT '',
file_path TEXT CONSTRAINT file_path_comment CHECK ( CHAR_LENGTH(file_path) <= 1000 ) DEFAULT '',
sticker_path TEXT CONSTRAINT sticker_path_comment_length CHECK (CHAR_LENGTH(sticker_path) <= 200) DEFAULT '',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
Expand All @@ -79,6 +83,12 @@ CREATE TABLE IF NOT EXISTS reaction (
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS sticker (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
file_path TEXT CONSTRAINT file_path_length CHECK (CHAR_LENGTH(file_path) <= 100) DEFAULT '',
profile_id INT REFERENCES profile(id)
);

ALTER TABLE friend
ADD FOREIGN KEY ("sender") REFERENCES profile(id) ON DELETE CASCADE,
ADD FOREIGN KEY ("receiver") REFERENCES profile(id) ON DELETE CASCADE ;
Expand Down
25 changes: 25 additions & 0 deletions Dockerfilesticker
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:alpine AS build

WORKDIR /stickers

COPY go.mod .
COPY go.sum .

RUN go mod download
RUN go mod vendor

COPY . .

RUN go build cmd/stickers/main.go

FROM alpine:latest

WORKDIR /stickers

EXPOSE 8088

COPY .env .

COPY --from=build /stickers/main /stickers/main

CMD ["./main"]
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
test:
go test -v ./... -coverprofile=cover.out && go tool cover -html=cover.out -o cover.html
go test ./... -coverprofile=cover.out \
&& go tool cover -func=cover.out | grep -vE "*mock.go|*easyjson.go|*pb.go|*mock_helper.go" \
&& go tool cover -html=cover.out -o cover.html


start:
docker compose up --build
Expand All @@ -16,4 +19,7 @@ gen-proto:
proto/*.proto

lint:
golangci-lint run
golangci-lint run

gen-easy-json:
easyjson -all internal/models/*.go
4 changes: 3 additions & 1 deletion cmd/gRPC/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func main() {

go func() {
http.Handle("/api/v1/metrics", promhttp.Handler())
http.ListenAndServe(":6001", nil)
if err = http.ListenAndServe(":6001", nil); err != nil {
panic(err)
}
}()

log.Printf("Listening on :%s with protocol gRPC", cfg.AUTHGRPC.Port)
Expand Down
4 changes: 3 additions & 1 deletion cmd/gRPC/post/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func main() {
}
go func() {
http.Handle("/api/v1/metrics", promhttp.Handler())
http.ListenAndServe(":6002", nil)
if err = http.ListenAndServe(":6002", nil); err != nil {
panic(err)
}
}()

log.Printf("Listening on :%s with protocol gRPC", cfg.POSTGRPC.Port)
Expand Down
4 changes: 3 additions & 1 deletion cmd/gRPC/profile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func main() {

go func() {
http.Handle("/api/v1/metrics", promhttp.Handler())
http.ListenAndServe(":6003", nil)
if err = http.ListenAndServe(":6003", nil); err != nil {
panic(err)
}
}()

log.Printf("Listening on :%s with protocol gRPC", cfg.PROFILEGRPC.Port)
Expand Down
29 changes: 29 additions & 0 deletions cmd/stickers/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"flag"
"log"

"github.com/2024_2_BetterCallFirewall/internal/app/stickers"

Check failure on line 7 in cmd/stickers/main.go

View workflow job for this annotation

GitHub Actions / linter

could not import github.com/2024_2_BetterCallFirewall/internal/app/stickers (-: # github.com/2024_2_BetterCallFirewall/internal/app/stickers
"github.com/2024_2_BetterCallFirewall/internal/config"
)

func main() {
confPath := flag.String("c", ".env", "path to config file")
flag.Parse()

cfg, err := config.GetConfig(*confPath)
if err != nil {
panic(err)
}

server, err := stickers.GetHTTPServer(cfg)
if err != nil {
panic(err)
}

log.Printf("Starting server on port %s", cfg.STICKER.Port)
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}
58 changes: 30 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@ version: '3.9'

services:
authgrpc:
build:
context: .
dockerfile: Dockerfileauthgrpc
image: slashlight/authgrpc:latest
restart: always
ports:
- "7072:7072"
depends_on:
- redis

profilegrpc:
build:
context: .
dockerfile: Dockerfileprofilegrpc
image: slashlight/profilegrpc:latest
restart: always
ports:
- "7074:7074"
depends_on:
- db
- authgrpc
postgrpc:
build:
context: .
dockerfile: Dockerfilepostgrpc
image: slashlight/postgrpc:latest
restart: always
ports:
- "7075:7075"
Expand All @@ -33,9 +27,7 @@ services:
- profilegrpc

community:
build:
context: .
dockerfile: Dockerfilecommunity
image: slashlight/community:latest
restart: always
ports:
- "8086:8086"
Expand All @@ -45,9 +37,7 @@ services:
- authgrpc

auth:
build:
context: .
dockerfile: Dockerfileauth
image: slashlight/auth:latest
restart: always
ports:
- "8082:8082"
Expand All @@ -57,11 +47,10 @@ services:
- community

file:
build:
context: .
dockerfile: Dockerfilefile
image: slashlight/file:latest
volumes:
- ./image:/image
- ./files:/files
restart: always
ports:
- "8083:8083"
Expand All @@ -70,9 +59,7 @@ services:
- auth

profile:
build:
context: .
dockerfile: Dockerfileprofile
image: slashlight/profile:latest
restart: always
ports:
- "8084:8084"
Expand All @@ -83,9 +70,7 @@ services:
- file

post:
build:
context: .
dockerfile: Dockerfilepost
image: slashlight/post:latest
restart: always
ports:
- "8085:8085"
Expand All @@ -96,9 +81,7 @@ services:
- community
- profile
chat:
build:
context: .
dockerfile: Dockerfilechat
image: slashlight/chat:latest
restart: always
ports:
- "8087:8087"
Expand All @@ -107,6 +90,15 @@ services:
- authgrpc
- post

stickers:
image: slashlight/sticker:latest
restart: always
ports:
- "8088:8088"
depends_on:
- db
- authgrpc

db:
image: postgres:latest
command: -c config_file=/etc/postgresql/postgresql.conf
Expand Down Expand Up @@ -179,5 +171,15 @@ services:
ports:
- "9100:9100"

watchtower:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- WATCHTOWER_POLL_INTERVAL=60
- WATCHTOWER_USERNAME=${DOCKER_USERNAME}
- WATCHTOWER_PASSWORD=${DOCKER_PASSWORD}


volumes:
postgres_data:
postgres_data:
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ require (
github.com/jackc/pgx/v5 v5.7.1
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/mailru/easyjson v0.7.7
github.com/microcosm-cc/bluemonday v1.0.27
github.com/prometheus/client_golang v1.20.5
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
Expand All @@ -24,15 +26,18 @@ require (
)

require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
Loading

0 comments on commit 1de1301

Please sign in to comment.