Skip to content

Commit 4440da9

Browse files
authored
improve building docker image (#50)
1 parent f4cf126 commit 4440da9

4 files changed

Lines changed: 29 additions & 11 deletions

File tree

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23-alpine AS builder
1+
FROM golang:1.25-alpine AS builder
22

33
WORKDIR /app
44

@@ -8,10 +8,11 @@ RUN go mod verify
88

99
COPY . .
1010

11-
RUN cd server && go build -o /app/main .
11+
RUN CGO_ENABLED=0 go build -o /app/main ./server
1212

1313
FROM scratch
1414

15+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
1516
COPY --from=builder /app/main /app/main
1617

1718
ENTRYPOINT ["/app/main"]

server/mongo/db.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mongo
33
import (
44
"context"
55
"errors"
6+
"strings"
67

78
"github.com/botsman/tppVerifier/app/cert"
89
"github.com/botsman/tppVerifier/app/db"
@@ -22,10 +23,29 @@ func NewMongoRepo(ctx context.Context, connStr string) (db.TppRepository, error)
2223
if err != nil {
2324
return nil, err
2425
}
25-
db := client.Database(opts.Auth.AuthSource)
26+
dbName, err := extractDatabaseName(connStr)
27+
if err != nil {
28+
return nil, err
29+
}
30+
if dbName == "" {
31+
return nil, errors.New("database name is required in connection string")
32+
}
33+
db := client.Database(dbName)
2634
return &TppMongoRepository{db: db}, nil
2735
}
2836

37+
func extractDatabaseName(connStr string) (string, error) {
38+
opts := options.Client().ApplyURI(connStr)
39+
if opts.Auth != nil && opts.Auth.AuthSource != "" {
40+
return opts.Auth.AuthSource, nil
41+
}
42+
connStrParts := strings.Split(connStr, "/")
43+
if len(connStrParts) < 2 {
44+
return "", errors.New("database name not found in connection string")
45+
}
46+
return connStrParts[len(connStrParts)-1], nil
47+
}
48+
2949
type TppMongoRepository struct {
3050
db *mongo.Database
3151
}

tools/tppdb/parse.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,12 @@ func parseRegistry() (<-chan models.TPP, error) {
392392
for _, tpps := range registry {
393393
for _, rawTpp := range tpps {
394394
if rawTpp.CA_OwnerID == "" || rawTpp.Code == "" {
395-
// log.Printf("Skipping TPP with missing CA_OwnerID or Code: %+v\n", rawTpp)
396395
continue
397396
}
398397
if rawTpp.Type == "" {
399-
// log.Printf("Skipping TPP with missing Type: %+v\n", rawTpp)
400398
continue
401399
}
402400
if rawTpp.AuthorizedAt == nil || rawTpp.AuthorizedAt.IsZero() {
403-
// log.Printf("Skipping TPP with missing AuthorizedAt: %+v\n", rawTpp)
404401
continue
405402
}
406403
if !slices.Contains([]string{"PSD_AISP", "PSD_PI", "PSD_EMI"}, rawTpp.Type) {

tools/tppdb/run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func Run(ctx context.Context, connStr string) error {
1919
// 3. Unzip the file
2020
// 4. Parse the file
2121
// 5. Save the parsed data to the DB
22+
client, err := setupMongoDb(ctx, connStr)
23+
// client, err := setupSqliteDb(ctx, connStr)
24+
if err != nil {
25+
return err
26+
}
2227

2328
getRegistry()
2429
defer deleteRegistry()
@@ -27,11 +32,6 @@ func Run(ctx context.Context, connStr string) error {
2732
if err != nil {
2833
return err
2934
}
30-
client, err := setupMongoDb(ctx, connStr)
31-
// client, err := setupSqliteDb(ctx, connStr)
32-
if err != nil {
33-
return err
34-
}
3535
defer client.Disconnect(ctx)
3636
return saveTPPs(client, tppChan)
3737
}

0 commit comments

Comments
 (0)