-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from go-park-mail-ru/dev
Dev
- Loading branch information
Showing
155 changed files
with
8,914 additions
and
2,911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:1.21.0-alpine AS builder | ||
|
||
COPY . /github.com/go-park-mail-ru/2024_1_TeaStealers/ | ||
WORKDIR /github.com/go-park-mail-ru/2024_1_TeaStealers/ | ||
|
||
RUN go mod download | ||
RUN go clean --modcache | ||
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/auth/main.go | ||
|
||
|
||
FROM scratch AS runner | ||
|
||
WORKDIR /docker-cian-advert/ | ||
|
||
COPY --from=builder /github.com/go-park-mail-ru/2024_1_TeaStealers/.bin . | ||
COPY --from=builder /github.com/go-park-mail-ru/2024_1_TeaStealers/config config/ | ||
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip / | ||
|
||
ENV TZ="Europe/Moscow" | ||
ENV ZONEINFO=/zoneinfo.zip | ||
EXPOSE 80 443 | ||
|
||
ENTRYPOINT ["./.bin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:1.21.0-alpine AS builder | ||
|
||
COPY . /github.com/go-park-mail-ru/2024_1_TeaStealers/ | ||
WORKDIR /github.com/go-park-mail-ru/2024_1_TeaStealers/ | ||
|
||
RUN go mod download | ||
RUN go clean --modcache | ||
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/auth/main.go | ||
|
||
|
||
FROM scratch AS runner | ||
|
||
WORKDIR /docker-cian-auth/ | ||
|
||
COPY --from=builder /github.com/go-park-mail-ru/2024_1_TeaStealers/.bin . | ||
COPY --from=builder /github.com/go-park-mail-ru/2024_1_TeaStealers/config config/ | ||
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip / | ||
|
||
ENV TZ="Europe/Moscow" | ||
ENV ZONEINFO=/zoneinfo.zip | ||
EXPOSE 80 443 | ||
|
||
ENTRYPOINT ["./.bin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:1.21.0-alpine AS builder | ||
|
||
COPY . /github.com/go-park-mail-ru/2024_1_TeaStealers/ | ||
WORKDIR /github.com/go-park-mail-ru/2024_1_TeaStealers/ | ||
|
||
RUN go mod download | ||
RUN go clean --modcache | ||
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/auth/main.go | ||
|
||
|
||
FROM scratch AS runner | ||
|
||
WORKDIR /docker-cian-user/ | ||
|
||
COPY --from=builder /github.com/go-park-mail-ru/2024_1_TeaStealers/.bin . | ||
COPY --from=builder /github.com/go-park-mail-ru/2024_1_TeaStealers/config config/ | ||
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip / | ||
|
||
ENV TZ="Europe/Moscow" | ||
ENV ZONEINFO=/zoneinfo.zip | ||
EXPOSE 80 443 | ||
|
||
ENTRYPOINT ["./.bin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
genAdverts "2024_1_TeaStealers/internal/pkg/adverts/delivery/grpc/gen" | ||
advertsR "2024_1_TeaStealers/internal/pkg/adverts/repo" | ||
advertsUc "2024_1_TeaStealers/internal/pkg/adverts/usecase" | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
|
||
"database/sql" | ||
"fmt" | ||
"log" | ||
"net" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/joho/godotenv" | ||
_ "github.com/lib/pq" | ||
"go.uber.org/zap" | ||
|
||
grpcAdverts "2024_1_TeaStealers/internal/pkg/adverts/delivery/grpc" | ||
metricsMw "2024_1_TeaStealers/internal/pkg/metrics/middleware" | ||
|
||
"google.golang.org/grpc" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run() (err error) { | ||
_ = godotenv.Load() | ||
logger := zap.Must(zap.NewDevelopment()) | ||
|
||
db, err := sql.Open("postgres", fmt.Sprintf("postgres://%v:%v@%v:%v/%v?sslmode=disable", | ||
os.Getenv("DB_USER"), | ||
os.Getenv("DB_PASS"), | ||
os.Getenv("DB_HOST"), | ||
os.Getenv("DB_PORT"), | ||
os.Getenv("DB_NAME"))) | ||
if err != nil { | ||
panic("failed to connect database" + err.Error()) | ||
} | ||
|
||
if err = db.Ping(); err != nil { | ||
log.Println("fail ping postgres") | ||
err = fmt.Errorf("error happened in db.Ping: %w", err) | ||
log.Println(err) | ||
} | ||
|
||
http.Handle("/metrics", promhttp.Handler()) | ||
|
||
advertsRepo := advertsR.NewRepository(db, logger) | ||
advertsUsecase := advertsUc.NewAdvertUsecase(advertsRepo, logger) | ||
authHandler := grpcAdverts.NewServerAdvertsHandler(advertsUsecase, logger) | ||
metricMw := metricsMw.Create() | ||
gRPCServer := grpc.NewServer(grpc.UnaryInterceptor(metricMw.ServerMetricsInterceptor)) | ||
genAdverts.RegisterAdvertsServer(gRPCServer, authHandler) | ||
|
||
go func() { | ||
logger.Info(fmt.Sprintf("Start server on %s\n", ":8083")) | ||
listener, err := net.Listen("tcp", ":8083") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if err := gRPCServer.Serve(listener); err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
|
||
stop := make(chan os.Signal, 1) | ||
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) | ||
|
||
<-stop | ||
gRPCServer.GracefulStop() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
genAuth "2024_1_TeaStealers/internal/pkg/auth/delivery/grpc/gen" | ||
authR "2024_1_TeaStealers/internal/pkg/auth/repo" | ||
authUc "2024_1_TeaStealers/internal/pkg/auth/usecase" | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
|
||
"database/sql" | ||
"fmt" | ||
"log" | ||
"net" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/joho/godotenv" | ||
_ "github.com/lib/pq" | ||
"go.uber.org/zap" | ||
|
||
grpcAuth "2024_1_TeaStealers/internal/pkg/auth/delivery/grpc" | ||
metricsMw "2024_1_TeaStealers/internal/pkg/metrics/middleware" | ||
|
||
"google.golang.org/grpc" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run() (err error) { | ||
_ = godotenv.Load() | ||
logger := zap.Must(zap.NewDevelopment()) | ||
|
||
db, err := sql.Open("postgres", fmt.Sprintf("postgres://%v:%v@%v:%v/%v?sslmode=disable", | ||
os.Getenv("DB_USER"), | ||
os.Getenv("DB_PASS"), | ||
os.Getenv("DB_HOST"), | ||
os.Getenv("DB_PORT"), | ||
os.Getenv("DB_NAME"))) | ||
if err != nil { | ||
panic("failed to connect database" + err.Error()) | ||
} | ||
|
||
if err = db.Ping(); err != nil { | ||
log.Println("fail ping postgres") | ||
err = fmt.Errorf("error happened in db.Ping: %w", err) | ||
log.Println(err) | ||
} | ||
|
||
http.Handle("/metrics", promhttp.Handler()) | ||
|
||
authRepo := authR.NewRepository(db, logger) | ||
authUsecase := authUc.NewAuthUsecase(authRepo, logger) | ||
authHandler := grpcAuth.NewServerAuthHandler(authUsecase, logger) | ||
metricMw := metricsMw.Create() | ||
gRPCServer := grpc.NewServer(grpc.UnaryInterceptor(metricMw.ServerMetricsInterceptor)) | ||
genAuth.RegisterAuthServer(gRPCServer, authHandler) | ||
|
||
go func() { | ||
logger.Info(fmt.Sprintf("Start server on %s\n", ":8081")) | ||
listener, err := net.Listen("tcp", ":8081") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if err := gRPCServer.Serve(listener); err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
|
||
stop := make(chan os.Signal, 1) | ||
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) | ||
|
||
<-stop | ||
gRPCServer.GracefulStop() | ||
return nil | ||
} |
Oops, something went wrong.