Skip to content

Commit 38ec828

Browse files
committed
Using InterSystems IRIS
1 parent 134a498 commit 38ec828

File tree

13 files changed

+399
-103
lines changed

13 files changed

+399
-103
lines changed

.travis.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

Dockerfile

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
FROM golang:1.24.5-alpine3.22 AS builder
1+
FROM golang:1.24-trixie AS builder
22

3-
RUN apk add --update gcc musl-dev
3+
# RUN apk add --update gcc musl-dev
44
RUN mkdir -p /myapp
55
ADD . /myapp
66
WORKDIR /myapp
77

8-
RUN adduser -u 10001 -D myapp
8+
RUN go install github.com/swaggo/swag/cmd/swag@latest && go generate . && GOOS=linux CGO_ENABLED=1 go build -ldflags='-extldflags=-static' -o myapp
99

10-
RUN go install github.com/swaggo/swag/cmd/swag@latest && go generate . && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags='-extldflags=-static' -o myapp .
1110

12-
#RUN make build-static
13-
RUN chown myapp: ./database
11+
FROM containers.intersystems.com/intersystems/iris-community:latest-cd
1412

13+
COPY --from=builder /myapp/myapp /myapp
14+
COPY health.sh /health.sh
15+
COPY irisinit.sh /irisinit.sh
1516

16-
FROM scratch
17-
18-
COPY --from=builder /etc/passwd /etc/passwd
19-
USER myapp
20-
21-
WORKDIR /myapp
22-
23-
#COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/
24-
COPY --from=builder /myapp/myapp ./myapp
25-
COPY --from=builder /myapp/database ./database
26-
VOLUME ./database
27-
CMD ["./myapp"]
17+
HEALTHCHECK --interval=30s --timeout=30s --start-period=20s --retries=3 CMD [ "/health.sh" ]
2818

19+
CMD [ "--after", "/irisinit.sh" ]

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export APIURL=http://$(HOST):$(PORT)/api
99

1010
#export ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))
1111
GOOS=linux
12-
GOARCH=amd64
12+
GOARCH=arm64
1313
APP=fiber-rw
1414
APP_STATIC=$(APP)-static
1515
LDFLAGS="-w -s -extldflags=-static"
@@ -40,10 +40,10 @@ generate: ## Generate swagger docs. Required https://github.com/gofiber/swagger
4040
go generate .
4141

4242
build: ## Build project with dynamic library(see shared lib with "ldd <your_file>")
43-
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -race -o $(APP) .
43+
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -race -o $(APP) .
4444

4545
build-static: ## Build project as single static linked executable file
46-
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) -o $(APP_STATIC) .
46+
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) -o $(APP_STATIC) .
4747

4848
build-image: ## Build docker image. Required https://www.docker.com
4949
docker build -t fiber-rw .

database/.dir4db

Whitespace-only changes.

db/db.go

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package db
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"os"
78
"time"
89

910
"github.com/alpody/fiber-realworld/model"
10-
"gorm.io/driver/sqlite"
11+
iris "github.com/caretdev/gorm-iris"
12+
iriscontainer "github.com/caretdev/testcontainers-iris-go"
13+
"github.com/testcontainers/testcontainers-go"
1114
"gorm.io/gorm"
1215
"gorm.io/gorm/logger"
1316
)
1417

1518
func New() *gorm.DB {
16-
//dsn := "host=/tmp user=realworld dbname=realworld"
17-
dsn := "./database/realworld.db"
19+
// dsn := "iris://_SYSTEM:SYS@iris:1972/USER"
20+
connectionString := os.Getenv("GORM_DSN")
1821

1922
newLogger := logger.New(
2023
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
@@ -26,20 +29,12 @@ func New() *gorm.DB {
2629
},
2730
)
2831

29-
// Globally mode
30-
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{
32+
db, err := gorm.Open(iris.New(iris.Config{
33+
DSN: connectionString,
34+
}), &gorm.Config{
3135
Logger: newLogger,
3236
})
3337

34-
/*
35-
*db, err := gorm.Open(postgres.New(postgres.Config{
36-
* DSN: dsn,
37-
* //PreferSimpleProtocol: true, // disables implicit prepared statement usage
38-
*}), &gorm.Config{})
39-
*/
40-
41-
//db, err := gorm.Open("postgresql", "postgresql://realworld@/realworld?host=/tmp")
42-
//db, err := gorm.Open("sqlite3", "./database/realworld.db")
4338
if err != nil {
4439
fmt.Println("storage err: ", err)
4540
}
@@ -50,37 +45,65 @@ func New() *gorm.DB {
5045
}
5146

5247
sqlDB.SetMaxIdleConns(3)
53-
sqlDB.SetMaxOpenConns(100)
48+
sqlDB.SetMaxOpenConns(5)
5449
sqlDB.SetConnMaxLifetime(time.Hour)
5550

5651
return db
5752
}
5853

59-
func TestDB() *gorm.DB {
60-
dsn := "./../database/realworld_test.db"
61-
//newLogger := logger.New(
62-
//log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
63-
//logger.Config{
64-
//SlowThreshold: time.Millisecond * 10, // Slow SQL threshold
65-
//LogLevel: logger.Info, // Log level
66-
//IgnoreRecordNotFoundError: false, // Ignore ErrRecordNotFound error for logger
67-
//Colorful: true, // Disable color
68-
//},
69-
//)
70-
71-
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{
72-
//Logger: newLogger,
54+
var container *iriscontainer.IRISContainer
55+
56+
func TestDB(useContainer bool) *gorm.DB {
57+
var err error
58+
var connectionString = "iris://_SYSTEM:SYS@localhost:1972/USER"
59+
60+
if useContainer {
61+
options := []testcontainers.ContainerCustomizer{
62+
iriscontainer.WithNamespace("TEST"),
63+
iriscontainer.WithUsername("testuser"),
64+
iriscontainer.WithPassword("testpassword"),
65+
}
66+
ctx := context.Background()
67+
container, err = iriscontainer.RunContainer(ctx, options...)
68+
if err != nil {
69+
log.Println("Failed to start container:", err)
70+
os.Exit(1)
71+
}
72+
connectionString = container.MustConnectionString(ctx)
73+
fmt.Println("Container started: ", connectionString)
74+
}
75+
76+
newLogger := logger.New(
77+
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
78+
logger.Config{
79+
SlowThreshold: time.Second, // Slow SQL threshold
80+
LogLevel: logger.Error, // Log level
81+
Colorful: true, // Disable color
82+
},
83+
)
84+
85+
db, err := gorm.Open(iris.New(iris.Config{
86+
DSN: connectionString,
87+
}), &gorm.Config{
88+
Logger: newLogger,
7389
})
90+
if !useContainer {
91+
_ = db.Exec("DROP DATABASE TEST").Error
92+
_ = db.Exec("CREATE DATABASE TEST").Error
93+
_ = db.Exec("USE DATABASE TEST").Error
94+
}
95+
7496
if err != nil {
7597
fmt.Println("storage err: ", err)
7698
}
7799
return db
78100
}
79101

80102
func DropTestDB() error {
81-
if err := os.Remove("./../database/realworld_test.db"); err != nil {
82-
return err
103+
if container != nil {
104+
container.Terminate(context.Background())
83105
}
106+
container = nil
84107
return nil
85108
}
86109

docker-compose.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
version: "2"
21
services:
3-
fiber-realworld:
2+
iris:
43
build: .
54
ports:
6-
- "8585:8585"
7-
volumes:
8-
- ./database:/myapp/database
5+
- 8872:1972
6+
- 8873:52773
7+
- 8585:8585
8+
environment:
9+
- IRIS_NAMESPACE=REALWORLD
10+
- IRIS_USERNAME=realworlduser
11+
- IRIS_PASSWORD=realworldpass
12+
- GORM_DSN=iris://realworlduser:realworldpass@localhost:1972/REALWORLD
913
newman-checker:
10-
image: postman/newman_alpine33
14+
image: postman/newman
15+
depends_on:
16+
iris:
17+
condition: service_healthy
1118
command:
1219
run https://github.com/gothinkster/realworld/raw/main/api/Conduit.postman_collection.json
13-
--global-var "APIURL=http://fiber-realworld:8585/api"
20+
--global-var "APIURL=http://iris:8585/api"
1421
--global-var "USERNAME=user2021"
1522
--global-var "EMAIL=user2021@example.com"
1623
--global-var "PASSWORD=password"

go.mod

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/alpody/fiber-realworld
22

3-
go 1.23.0
3+
go 1.24.4
44

55
toolchain go1.24.5
66

@@ -11,50 +11,104 @@ require (
1111
github.com/gofiber/swagger v1.1.1
1212
github.com/golang-jwt/jwt/v5 v5.2.3
1313
github.com/gosimple/slug v1.15.0
14-
github.com/stretchr/testify v1.10.0
14+
github.com/stretchr/testify v1.11.1
1515
github.com/swaggo/swag v1.16.5
1616
golang.org/x/crypto v0.40.0
1717
// gorm.io/driver/postgres v1.3.8
1818
gorm.io/driver/sqlite v1.6.0
19-
gorm.io/gorm v1.30.0
19+
gorm.io/gorm v1.31.0
2020
)
2121

2222
require (
23+
github.com/caretdev/gorm-iris v0.1.1
24+
github.com/caretdev/testcontainers-iris-go v0.1.1
25+
github.com/testcontainers/testcontainers-go v0.38.0
26+
)
27+
28+
require (
29+
dario.cat/mergo v1.0.1 // indirect
30+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
2331
github.com/KyleBanks/depth v1.2.1 // indirect
2432
github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect
33+
github.com/Microsoft/go-winio v0.6.2 // indirect
2534
github.com/andybalholm/brotli v1.1.0 // indirect
35+
github.com/caretdev/go-irisnative v0.2.1 // indirect
36+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
37+
github.com/containerd/errdefs v1.0.0 // indirect
38+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
39+
github.com/containerd/log v0.1.0 // indirect
40+
github.com/containerd/platforms v0.2.1 // indirect
41+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
2642
github.com/davecgh/go-spew v1.1.1 // indirect
43+
github.com/distribution/reference v0.6.0 // indirect
44+
github.com/docker/docker v28.2.2+incompatible // indirect
45+
github.com/docker/go-connections v0.5.0 // indirect
46+
github.com/docker/go-units v0.5.0 // indirect
47+
github.com/ebitengine/purego v0.8.4 // indirect
48+
github.com/felixge/httpsnoop v1.0.4 // indirect
2749
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
50+
github.com/go-logr/logr v1.4.3 // indirect
51+
github.com/go-logr/stdr v1.2.2 // indirect
52+
github.com/go-ole/go-ole v1.2.6 // indirect
2853
github.com/go-openapi/jsonpointer v0.19.5 // indirect
2954
github.com/go-openapi/jsonreference v0.20.0 // indirect
3055
github.com/go-openapi/spec v0.20.6 // indirect
3156
github.com/go-openapi/swag v0.21.1 // indirect
3257
github.com/go-playground/locales v0.14.1 // indirect
3358
github.com/go-playground/universal-translator v0.18.1 // indirect
59+
github.com/gogo/protobuf v1.3.2 // indirect
3460
github.com/google/uuid v1.6.0 // indirect
3561
github.com/gosimple/unidecode v1.0.1 // indirect
62+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
3663
github.com/jinzhu/inflection v1.0.0 // indirect
3764
github.com/jinzhu/now v1.1.5 // indirect
3865
github.com/josharian/intern v1.0.0 // indirect
39-
github.com/klauspost/compress v1.17.9 // indirect
66+
github.com/klauspost/compress v1.18.0 // indirect
4067
github.com/leodido/go-urn v1.4.0 // indirect
68+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
69+
github.com/magefile/mage v1.15.0 // indirect
70+
github.com/magiconair/properties v1.8.10 // indirect
4171
github.com/mailru/easyjson v0.7.7 // indirect
4272
github.com/mattn/go-colorable v0.1.13 // indirect
4373
github.com/mattn/go-isatty v0.0.20 // indirect
4474
github.com/mattn/go-runewidth v0.0.16 // indirect
4575
github.com/mattn/go-sqlite3 v1.14.22 // indirect
76+
github.com/moby/docker-image-spec v1.3.1 // indirect
77+
github.com/moby/go-archive v0.1.0 // indirect
78+
github.com/moby/patternmatcher v0.6.0 // indirect
79+
github.com/moby/sys/sequential v0.6.0 // indirect
80+
github.com/moby/sys/user v0.4.0 // indirect
81+
github.com/moby/sys/userns v0.1.0 // indirect
82+
github.com/moby/term v0.5.0 // indirect
83+
github.com/morikuni/aec v1.0.0 // indirect
84+
github.com/opencontainers/go-digest v1.0.0 // indirect
85+
github.com/opencontainers/image-spec v1.1.1 // indirect
86+
github.com/pkg/errors v0.9.1 // indirect
4687
github.com/pmezard/go-difflib v1.0.0 // indirect
88+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
4789
github.com/rivo/uniseg v0.4.4 // indirect
90+
github.com/shirou/gopsutil/v4 v4.25.5 // indirect
91+
github.com/shopspring/decimal v1.4.0 // indirect
92+
github.com/sirupsen/logrus v1.9.3 // indirect
4893
github.com/swaggo/files/v2 v2.0.2 // indirect
94+
github.com/tklauser/go-sysconf v0.3.12 // indirect
95+
github.com/tklauser/numcpus v0.6.1 // indirect
4996
github.com/valyala/bytebufferpool v1.0.0 // indirect
5097
github.com/valyala/fasthttp v1.51.0 // indirect
5198
github.com/valyala/tcplisten v1.0.0 // indirect
52-
golang.org/x/mod v0.25.0 // indirect
53-
golang.org/x/net v0.41.0 // indirect
99+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
100+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
101+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
102+
go.opentelemetry.io/otel v1.38.0 // indirect
103+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
104+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
105+
golang.org/x/mod v0.26.0 // indirect
106+
golang.org/x/net v0.42.0 // indirect
54107
golang.org/x/sync v0.16.0 // indirect
55-
golang.org/x/sys v0.34.0 // indirect
56-
golang.org/x/text v0.27.0 // indirect
57-
golang.org/x/tools v0.34.0 // indirect
108+
golang.org/x/sys v0.35.0 // indirect
109+
golang.org/x/text v0.28.0 // indirect
110+
golang.org/x/tools v0.35.0 // indirect
111+
google.golang.org/grpc v1.75.0 // indirect
58112
gopkg.in/yaml.v2 v2.4.0 // indirect
59113
gopkg.in/yaml.v3 v3.0.1 // indirect
60114
)

0 commit comments

Comments
 (0)