Skip to content

Commit ae5ac3e

Browse files
committed
added Dockerfile
1 parent b4c9e53 commit ae5ac3e

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Stage 1: Build the Go application
2+
FROM golang:1.22 as builder
3+
4+
# Set the Current Working Directory inside the container
5+
WORKDIR /app
6+
7+
# Copy go mod and sum files
8+
COPY go.mod go.sum ./
9+
10+
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
11+
RUN go mod download
12+
13+
# Copy the source code into the container
14+
COPY . .
15+
16+
# Build the Go app
17+
RUN go build -o main .
18+
19+
# Stage 2: Run the Go application
20+
FROM golang:1.22
21+
22+
# Set the Current Working Directory inside the container
23+
WORKDIR /app
24+
25+
# Copy the binary and config file from the builder stage
26+
COPY --from=builder /app/config.toml .
27+
COPY --from=builder /app/main .
28+
29+
# Expose port 9090 to the outside world
30+
EXPOSE 9090
31+
32+
# Command to run the executable
33+
CMD ["./main"]

config/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ func NewConfig() *Config {
4646
// then override the configuration from environment variables
4747
OverrideConfigFromEnv(&cfg)
4848

49+
if cfg.Origin == "" {
50+
log.Print("origin url is required, you can configure it in the config.toml file or pass it as an environment variable ORBIT_ORIGIN=http://localhost:8080/graphql")
51+
os.Exit(1)
52+
}
53+
54+
if cfg.CacheBackend == "" {
55+
cfg.CacheBackend = "in_memory"
56+
}
57+
58+
if cfg.CacheBackend == "redis" {
59+
if cfg.RedisHost == "" {
60+
log.Print("redis host is required when using redis cache backend")
61+
os.Exit(1)
62+
}
63+
if cfg.RedisPort == 0 {
64+
log.Print("redis port is required when using redis cache backend")
65+
os.Exit(1)
66+
}
67+
}
68+
69+
if cfg.Port == 0 {
70+
cfg.Port = 9090
71+
}
72+
4973
if cfg.HandlersGraphQLPath == "" {
5074
cfg.HandlersGraphQLPath = "/graphql"
5175
}

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func main() {
2323
fmt.Println("🛠️ initializing configuration...")
2424
cfg := config.NewConfig()
2525
fmt.Println("🛠️ configuration initalized")
26-
fmt.Println("⚙️ configuration: ", "cache_backend=", cfg.CacheBackend, "cache_header_name=", cfg.CacheHeaderName, "origin=", cfg.Origin, "port=", cfg.Port, "scope_headers=", cfg.ScopeHeaders, "primary_key_field=", cfg.PrimaryKeyField, "log_level=", cfg.LogLevel, "log_format=", cfg.LogFormat, "redis_host=", cfg.RedisHost, "redis_port=", cfg.RedisPort, "cache_ttl=", cfg.CacheTTL, "handlers_graphql_path=", cfg.HandlersGraphQLPath, "handlers_flush_all_path=", cfg.HandlersFlushAllPath, "handlers_flush_by_type_path=", cfg.HandlersFlushByTypePath, "handlers_debug_path=", cfg.HandlersDebugPath, "handlers_health_path=", cfg.HandlersHealthPath)
26+
fmt.Println("⚙️ configuration: ")
27+
fmt.Print("→ cache_backend=", cfg.CacheBackend, "\n→ cache_header_name=", cfg.CacheHeaderName, "\n→ origin=", cfg.Origin, "\n→ port=", cfg.Port, "\n→ scope_headers=", cfg.ScopeHeaders, "\n→ primary_key_field=", cfg.PrimaryKeyField, "\n→ log_level=", cfg.LogLevel, "\n→ log_format=", cfg.LogFormat, "\n→ redis_host=", cfg.RedisHost, "\n→ redis_port=", cfg.RedisPort, "\n→ cache_ttl=", cfg.CacheTTL, "\n→ handlers_graphql_path=", cfg.HandlersGraphQLPath, "\n→ handlers_flush_all_path=", cfg.HandlersFlushAllPath, "\n→ handlers_flush_by_type_path=", cfg.HandlersFlushByTypePath, "\n→ handlers_debug_path=", cfg.HandlersDebugPath, "\n→ handlers_health_path=", cfg.HandlersHealthPath, "\n\n")
2728

2829
logger.Configure(&logger.Config{
2930
Format: string(cfg.LogFormat),

0 commit comments

Comments
 (0)