Skip to content

Commit

Permalink
Updating modules, project structure working
Browse files Browse the repository at this point in the history
  • Loading branch information
Falokut committed Mar 5, 2024
1 parent 2f2a008 commit bc40552
Show file tree
Hide file tree
Showing 32 changed files with 1,285 additions and 999 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@ name: Docker Image CI

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

jobs:
buld-and-push-service-image:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

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

-
name: Set up Docker Buildx

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

- name: Publish to Registry
- name: Publish alpine to Registry
uses: docker/build-push-action@v5
with:
file: alpine.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: falokut/${{ github.event.repository.name }}-alpine:latest
labels: ${{ steps.meta.outputs.labels }}

- name: Publish scratch to Registry
uses: docker/build-push-action@v5
with:
context: .
file: scratch.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: falokut/${{ github.event.repository.name }}:latest
labels: ${{ steps.meta.outputs.labels }}
tags: falokut/${{ github.event.repository.name }}-scratch:latest
labels: ${{ steps.meta.outputs.labels }}
21 changes: 12 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ name: Go

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

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.4'
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.4"

- name: Test
run: go test -v ./...
- name: Test
run: go test -v ./...

- name: Update coverage report
uses: ncruces/go-coverage-report@v0
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Images storage service #

[![Go Report Card](https://goreportcard.com/badge/github.com/Falokut/images_storage_service)](https://goreportcard.com/report/github.com/Falokut/images_storage_service)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/Falokut/images_storage_service)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/Falokut/images_storage_service)
[![Go](https://github.com/Falokut/images_storage_service/actions/workflows/go.yml/badge.svg?branch=master)](https://github.com/Falokut/images_storage_service/actions/workflows/go.yml) ![](https://changkun.de/urlstat?mode=github&repo=Falokut/images_storage_service)
[![Go Coverage](https://github.com/Falokut/images_storage_service/wiki/coverage.svg)](https://raw.githack.com/wiki/Falokut/images_storage_service/coverage.html)
[![License](https://img.shields.io/badge/license-MIT-green)](./LICENSE)


# Content
+ [Images storage service](#images-storage-service)
+ [Docs](#swagger-docs)
Expand All @@ -21,7 +31,7 @@ if supported values is empty, then any type values are supported
| host | listen | HOST | string | ip address or host to listen | |
| port | listen | PORT | string | port to listen | The string should not contain delimiters, only the port number|
| max_request_size | listen | MAX_REQUEST_SIZE | int32 | max request size in mb, by default 4 mb |only > 0|
| max_responce_size | listen | MAX_RESPONCE_SIZE | int32 | max responce size in mb, by default 4 mb |only > 0|
| max_response_size | listen | MAX_RESPONSE_SIZE | int32 | max response size in mb, by default 4 mb |only > 0|
| server_mode | listen | SERVER_MODE | string | Server listen mode, Rest API, gRPC or both | GRPC, REST, BOTH|
|service_name| prometheus | PROMETHEUS_SERVICE_NAME | string | service name, thats will show in prometheus ||
|server_config| prometheus | | nested yml configuration [metrics server config](#prometheus-config) | |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile → alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine AS builder
FROM golang:1.22-alpine AS builder

WORKDIR /app

Expand Down
32 changes: 16 additions & 16 deletions cmd/server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"errors"
"net/http"
"os"
"os/signal"
"strings"
Expand All @@ -13,12 +12,13 @@ import (
server "github.com/Falokut/grpc_rest_server"
"github.com/Falokut/healthcheck"
"github.com/Falokut/images_storage_service/internal/config"
"github.com/Falokut/images_storage_service/internal/handler"
"github.com/Falokut/images_storage_service/internal/repository"
"github.com/Falokut/images_storage_service/internal/service"
img_storage_serv "github.com/Falokut/images_storage_service/pkg/images_storage_service/v1/protos"
jaegerTracer "github.com/Falokut/images_storage_service/pkg/jaeger"
"github.com/Falokut/images_storage_service/pkg/logging"
"github.com/Falokut/images_storage_service/pkg/metrics"
logging "github.com/Falokut/online_cinema_ticket_office.loggerwrapper"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -113,25 +113,25 @@ func main() {
logger.Info("Local storage initializing")
storage = repository.NewLocalStorage(logger.Logger, cfg.BaseLocalStoragePath)

go func() {
mux := http.NewServeMux()
mux.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
if err := http.ListenAndServe(":"+cfg.HealthcheckPort, mux); err != nil {
logger.Errorf("Shutting down, error while running healthcheck endpoint %s", err.Error())
shutdown <- err
return
}
}()
healthcheckManager := healthcheck.NewHealthManager(logger.Logger,
[]healthcheck.HealthcheckResource{}, cfg.HealthcheckPort, func(ctx context.Context) error { return nil })
if err := healthcheckManager.RunHealthcheckEndpoint(); err != nil {
logger.Errorf("Shutting down, error while running healthcheck endpoint %s", err.Error())
shutdown <- err
return
}
}

logger.Info("Service initializing")
service := service.NewImagesStorageService(logger.Logger,
service.Config{MaxImageSize: cfg.MaxImageSize * mb}, storage, metric)
service := service.NewImagesStorageService(logger.Logger, metric, storage,
service.Config{MaxImageSize: cfg.MaxImageSize * mb})

logger.Info("Handler initializing")
handler := handler.NewImagesStorageServiceHandler(logger.Logger,
handler.Config{MaxImageSize: cfg.MaxImageSize * mb}, service)

logger.Info("Server initializing")
s := server.NewServer(logger.Logger, service)
s := server.NewServer(logger.Logger, handler)
go func() {
if err := s.Run(getListenServerConfig(cfg), metric, nil, nil); err != nil {
logger.Errorf("Shutting down, error while running server %s", err.Error())
Expand Down
6 changes: 3 additions & 3 deletions docker/containers-configs/app-configs/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
log_level: "debug" # supported levels: "panic", "fatal", "error", "warning" or "warn", "info", "debug", "trace"
max_image_size: 30
max_image_size: 30
healthcheck_port: 7000

listen:
Expand All @@ -8,7 +8,7 @@ listen:
server_mode: "BOTH"
max_request_size: 30
max_response_size: 30

jaeger:
service_name: "Images_Storage_Service"
address: jaeger:6831
Expand All @@ -21,4 +21,4 @@ prometheus:
port: 7000

minio:
endpoint: "host.docker.internal:9000"
endpoint: "host.docker.internal:9000"
37 changes: 17 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
module github.com/Falokut/images_storage_service

go 1.21.4
go 1.22.0

require (
github.com/Falokut/grpc_errors v1.0.0
github.com/Falokut/healthcheck v0.0.0-20231124155013-bff54f9bc002
github.com/Falokut/online_cinema_ticket_office.loggerwrapper v0.0.0-20231130151717-09aa21496f83
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/ilyakaznacheev/cleanenv v1.5.0
github.com/minio/minio-go/v7 v7.0.66
github.com/minio/minio-go/v7 v7.0.68
github.com/opentracing/opentracing-go v1.2.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_golang v1.19.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/uber/jaeger-client-go v2.30.0+incompatible
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe
google.golang.org/grpc v1.61.0
google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.32.0
)

require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -35,37 +33,36 @@ require (
)

require (
github.com/Falokut/interceptors v1.0.3 // indirect
github.com/Falokut/interceptors v1.0.5 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Falokut/grpc_rest_server v1.0.7
github.com/Falokut/grpc_rest_server v1.0.9
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.3
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.49.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)

0 comments on commit bc40552

Please sign in to comment.