diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5028433 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# syntax=docker/dockerfile:1 + +# Build the application from source +FROM golang:1.23-alpine3.21 AS build-stage + +WORKDIR /application + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . ./ + +RUN CGO_ENABLED=0 GOOS=linux go build -o /pulsar-products-service + +# Run the tests in the container +FROM build-stage AS run-test-stage +RUN go test -v ./... + +# Deploy the application binary into a lean image +FROM gcr.io/distroless/base-debian11 AS build-release-stage + +WORKDIR / + +COPY --from=build-stage /pulsar-products-service /pulsar-products-service + +EXPOSE 8080 + +USER nonroot:nonroot + +ENTRYPOINT ["/pulsar-products-service"] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..436bd03 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,28 @@ +services: + pulsar-products-service: + # image: yaninyzwitty/pulsar-products-service:latest + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + env_file: + - .env + configs: + - source: my_config + target: ./my_config.yaml + networks: + - private_network + + + +configs: + my_config: + file: config.yaml +networks: + private_network: + driver: bridge + ipam: + config: + - subnet: "10.0.0.0/19" + gateway: "10.0.0.1" \ No newline at end of file diff --git a/cmd/server/main.go b/main.go similarity index 95% rename from cmd/server/main.go rename to main.go index b0bdcea..0f5efb0 100644 --- a/cmd/server/main.go +++ b/main.go @@ -10,7 +10,6 @@ import ( "syscall" "time" - "github.com/joho/godotenv" "github.com/yaninyzwitty/pulsar-outbox-products-service/controller" "github.com/yaninyzwitty/pulsar-outbox-products-service/database" "github.com/yaninyzwitty/pulsar-outbox-products-service/helpers" @@ -28,7 +27,7 @@ var ( func main() { // Load configuration - file, err := os.Open("config.yaml") + file, err := os.Open("my_config.yaml") if err != nil { slog.Error("failed to open config.yaml", "error", err) os.Exit(1) @@ -40,10 +39,10 @@ func main() { os.Exit(1) } - if err := godotenv.Load(); err != nil { - slog.Error("failed to load .env", "error", err) - os.Exit(1) - } + // if err := godotenv.Load(); err != nil { + // slog.Error("failed to load .env", "error", err) + // os.Exit(1) + // } password = os.Getenv("DB_PASSWORD") token = os.Getenv("PULSAR_TOKEN")