switch to mongodb uri instead of host/username/password
This commit is contained in:
parent
3d61f9b542
commit
1ba7fef3ef
|
@ -0,0 +1,27 @@
|
|||
FROM golang:alpine as builder
|
||||
|
||||
ARG ACCESS_TOKEN_USR="nothing"
|
||||
ARG ACCESS_TOKEN_PWD="nothing"
|
||||
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
|
||||
WORKDIR /
|
||||
|
||||
# Create a netrc file using the credentials specified using --build-arg
|
||||
RUN printf "machine git.coopgo.io\n\
|
||||
login ${ACCESS_TOKEN_USR}\n\
|
||||
password ${ACCESS_TOKEN_PWD}\n"\
|
||||
>> ~/.netrc
|
||||
RUN chmod 600 ~/.netrc
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN go mod download && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY --from=builder /server /
|
||||
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/server"]
|
|
@ -2,12 +2,11 @@ package grpcserver
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/carpool-incentives/grpc/proto"
|
||||
"git.coopgo.io/coopgo-platform/carpool-incentives/handlers/incentives"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
@ -78,13 +77,13 @@ func Run(done chan error, cfg *viper.Viper, incentivesHandler *incentives.Incent
|
|||
dev_env = cfg.GetBool("dev_env")
|
||||
address = ":" + cfg.GetString("services.grpc.port")
|
||||
)
|
||||
//fmt.Println("-> GRPC server on", address)
|
||||
|
||||
server := grpc.NewServer()
|
||||
proto.RegisterCarpoolIncentivesServer(server, NewCarpoolIncentivesServer(incentivesHandler))
|
||||
l, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal().Err(err).Msg("could not create grpc server")
|
||||
return
|
||||
}
|
||||
|
||||
if dev_env {
|
||||
|
@ -92,7 +91,7 @@ func Run(done chan error, cfg *viper.Viper, incentivesHandler *incentives.Incent
|
|||
}
|
||||
|
||||
if err := server.Serve(l); err != nil {
|
||||
fmt.Println("gRPC service ended")
|
||||
log.Error().Err(err).Msg("grpc service ended")
|
||||
done <- err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package storage
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
|
@ -17,6 +18,7 @@ type MongoDBStorage struct {
|
|||
|
||||
func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
|
||||
var (
|
||||
mongodb_uri = cfg.GetString("storage.db.mongodb.uri")
|
||||
mongodb_host = cfg.GetString("storage.db.mongodb.host")
|
||||
mongodb_port = cfg.GetString("storage.db.mongodb.port")
|
||||
mongodb_dbname = cfg.GetString("storage.db.mongodb.db_name")
|
||||
|
@ -24,7 +26,11 @@ func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
|
|||
mongodb_proofs = cfg.GetString("storage.db.mongodb.collections.proofs")
|
||||
)
|
||||
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://" + mongodb_host + ":" + mongodb_port))
|
||||
if mongodb_uri == "" {
|
||||
mongodb_uri = fmt.Sprintf("mongodb://%s:%s/%s", mongodb_host, mongodb_port, mongodb_dbname)
|
||||
}
|
||||
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(mongodb_uri))
|
||||
if err != nil {
|
||||
return MongoDBStorage{}, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue