Skip to content

Commit

Permalink
Merge pull request #26 from go-park-mail-ru/dev4
Browse files Browse the repository at this point in the history
Dev4
  • Loading branch information
Gvidow committed Dec 20, 2023
2 parents b7224ed + e71947b commit dd2e177
Show file tree
Hide file tree
Showing 68 changed files with 4,034 additions and 572 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
8 changes: 0 additions & 8 deletions cmd/app/config.go

This file was deleted.

7 changes: 7 additions & 0 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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 (
Expand All @@ -27,6 +29,7 @@ var (
// @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()
Expand All @@ -42,5 +45,9 @@ func main() {
}
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 @@ -11,11 +11,13 @@ import (
grpcMetrics "github.com/go-park-mail-ru/2023_2_OND_team/internal/pkg/metrics/grpc"
"github.com/go-park-mail-ru/2023_2_OND_team/internal/pkg/middleware/grpc/interceptor"
"github.com/go-park-mail-ru/2023_2_OND_team/pkg/logger"
"github.com/joho/godotenv"
)

const _address = "localhost:8090"
const _address = "0.0.0.0:8090"

func main() {
godotenv.Load()
log, err := logger.New()
if err != nil {
fmt.Println(err)
Expand Down
Loading

0 comments on commit dd2e177

Please sign in to comment.