Gothic Framework G symbol

Docker Setup

Gothic apps compile to a single Go binary, which means they can run anywhere — on any cloud, any VPS, or any container platform. Combined with the pluggable cache system (REDIS or IN_MEMORY) and self-served static files, you can deploy to any provider using Docker.

First, configure your main.go to use the REDIS cache strategy and serve static files in all environments:

package  main

 import  (
	 "net/http" 
	 "os" 

	 "github.com/go-chi/chi/v5" 
	 gothicRoutes  "github.com/felipegenef/gothicframework/v2/pkg/helpers/routes" 
	 routes  "your-project/src/routes" 
)

 func  main() {
	 router := chi. NewRouter ()
	 gothicRoutes. Setup (router, gothicRoutes. AppConfig {
		 CacheStrategy:    gothicRoutes. REDIS ,
		 ServeStaticFiles: gothicRoutes. ALL_ENVS ,
		 CacheConfig: &gothicRoutes. CacheConfig {
			 RedisURL: os. Getenv ( "REDIS_URL" ),
		},
	}, routes.RegisterFileBasedRoutes)

	 http. ListenAndServe ( ":8080" , router)
} 

Next, create a multi-stage Dockerfile for an optimized production image:

# Build binary 
 FROM  golang:alpine  AS  build

 WORKDIR  /build

 COPY  go.mod go.sum ./
 COPY  . .

 RUN  apk add --no-cache ca-certificates

 RUN  GOOS=linux go build -ldflags= "\"-w -s\""  -o ./server main.go

 # Minimal production image 
 FROM  scratch

 WORKDIR  /app
 COPY  --from=build /build/server /app/
 COPY  --from=build /build/public /app/public
 COPY  --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

 EXPOSE  8080
 CMD  [ "/app/server" ] 

Finally, use Docker Compose to run your app with Redis locally:

version :  "3.8" 
 services :
   app :
     build: .
     ports:
      -  "8080:8080" 
     environment:
      -  REDIS_URL=redis:6379
     depends_on:
      - redis
   redis :
     image: redis:7-alpine
     ports:
      -  "6379:6379" 

Ready to deploy? Let's start with Google Cloud Platform!