Skip to content

Commit

Permalink
Merge pull request #104 from go-park-mail-ru/dev
Browse files Browse the repository at this point in the history
mvp
  • Loading branch information
Max425 authored Dec 18, 2024
2 parents ee12c38 + c116619 commit ac212df
Show file tree
Hide file tree
Showing 106 changed files with 8,104 additions and 310 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CD

on:
push:
branches:
- main
- dev
paths:
- 'microservices/**'
- 'config/**'
- 'cmd/**'

jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
ENV: prod
DOCKER_COMPOSE_PATH: docker/docker-compose.prod.yaml
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
steps:
- name: Check out code into directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push microservice images
run: |
services=(user playlist artist album track csat genre)
for service in "${services[@]}"; do
docker compose -f "$DOCKER_COMPOSE_PATH" build novamusic-${service}
docker tag ${DOCKER_USERNAME}/novamusic-${service}:latest ${DOCKER_USERNAME}/novamusic-${service}:${GITHUB_SHA::8}
docker push ${DOCKER_USERNAME}/novamusic-${service}:${GITHUB_SHA::8}
docker push ${DOCKER_USERNAME}/novamusic-${service}:latest
done
migrate:
name: Postgres Migration
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out code into directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Copy migration files to server
uses: appleboy/[email protected]
with:
host: 185.241.194.24
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
source: "internal/db/postgres/migrations/*"
target: "/home/ubuntu/nova-music/backend/"

- name: Run database migrations
uses: appleboy/[email protected]
with:
host: 185.241.194.24
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: |
cd /home/ubuntu/nova-music/backend/
sudo make postgres-migrate
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ go.work.sum
.prod.env

coverage.out.tmp
*/nginx/logs/
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test:
## View code coverage report if it exists otherwise generate.
view-coverage: --check-coverage
@go test -coverpkg=./... -coverprofile=coverage.out.tmp ./...
@cat coverage.out.tmp | grep -v "mock\|cmd\|config\|internal\|docs\|metrics\|pkg\|routes\|proto" > coverage.out
@cat coverage.out.tmp | grep -v "mock\|cmd\|config\|internal\|docs\|metrics\|pkg\|routes\|proto\|easyjson" > coverage.out
@go tool cover -func=coverage.out

.PHONY: view-coverage-html
Expand Down Expand Up @@ -275,3 +275,17 @@ clean-all: clean clean-test
%-reset:
$(eval DB := $(shell echo $* | tr '[:lower:]' '[:upper:]'))
@GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) $($(DB)_CONNECTION) reset

################################################################################
# Codegen
################################################################################

.PHONY: generate
## Create easyjson unmarshalers for structs with ////easyjson:json flag
generate:
@find . -type f -name '*_easyjson.go' -delete
@FILES=$$(find . -type f -name "*dto.go" -o -wholename "*/models/*.go" -o -wholename "*/utils/response.go"); \
for file in $$FILES; do \
easyjson $$file; \
done

2 changes: 0 additions & 2 deletions cmd/csat/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"
"sync"

Expand Down Expand Up @@ -36,7 +35,6 @@ func main() {

s := httpServer.New(cfg, pg, s3, logger, metrics)
csatHttp.BindRoutes(s)
fmt.Println("csat http binded")

var wg sync.WaitGroup
wg.Add(1)
Expand Down
6 changes: 3 additions & 3 deletions config/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ service:
writeTimeout: 10
idleTimeout: 120
contextTimeout: 5

grpc:
port: :9000
maxConnectionIdle: 5
Expand All @@ -29,10 +29,10 @@ service:
headerName: X-Csrf-Token

jwt:
expire: 3600
expire: 604800
cookie:
name: jwt-token
maxAge: 86400
maxAge: 604800
secure: false
httpOnly: true

Expand Down
8 changes: 4 additions & 4 deletions config/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ service:
writeTimeout: 10
idleTimeout: 120
contextTimeout: 5

grpc:
port: :9000
maxConnectionIdle: 5
Expand Down Expand Up @@ -33,10 +33,10 @@ service:
headerName: X-Csrf-Token

jwt:
expire: 3600
expire: 604800
cookie:
name: jwt-token
maxAge: 86400
maxAge: 604800
secure: true
httpOnly: true

Expand All @@ -52,4 +52,4 @@ postgres:

minio:
url: nova-music.ru:8010
sslMode: true
sslMode: true
44 changes: 44 additions & 0 deletions docker/.prod.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
SERVICE_NAME=novamusic

USER_VERSION=v0.1
PLAYLIST_VERSION=v0.1
CSAT_VERSION=v0.1
ARTIST_VERSION=v0.1
ALBUM_VERSION=v0.1
GENRE_VERSION=v0.1
TRACK_VERSION=v0.1

HOST=nova-music.ru
ENV=prod

CONFIG_PATH=config/

POSTGRES_HOST=
POSTGRES_PORT=
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=

MINIO_USER=
MINIO_PASSWORD=

CSRF_SALT=
JWT_SECRET=

SSL_PATH=

PROMETHEUS_URL=
PROMETHEUS_PORT=

GRAFANA_PORT=
GF_SECURITY_ADMIN_USER=
GF_SECURITY_ADMIN_PASSWORD=
GF_USERS_ALLOW_SIGN_UP=
GF_SERVER_ROOT_URL=
GF_SERVER_DOMAIN=

ALERTMANAGER_PORT=
ALERTMANAGER_EXTERNAL_URL=

TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=
4 changes: 3 additions & 1 deletion docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ ENV GOOS=linux
ENV GO111MODULE=on

ENV GOCACHE=/root/.cache/go-build
#RUN --mount=type=cache,target="/root/.cache/go-build" \
# go build -mod=vendor -o bin/main cmd/$MICROSERVICE/main.go
RUN --mount=type=cache,target="/root/.cache/go-build" \
go build -mod=vendor -o bin/main cmd/$MICROSERVICE/main.go
go build -o bin/main cmd/$MICROSERVICE/main.go

ENTRYPOINT [ "/microservice/bin/main" ]
Loading

0 comments on commit ac212df

Please sign in to comment.