Skip to content

Commit 8eccee7

Browse files
committed
remove main.go from cmd/server, add compose.yaml and dockerfile
1 parent 53bb99b commit 8eccee7

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Build the application from source
4+
FROM golang:1.23-alpine3.21 AS build-stage
5+
6+
WORKDIR /application
7+
8+
COPY go.mod go.sum ./
9+
RUN go mod download
10+
11+
COPY . ./
12+
13+
RUN CGO_ENABLED=0 GOOS=linux go build -o /pulsar-products-service
14+
15+
# Run the tests in the container
16+
FROM build-stage AS run-test-stage
17+
RUN go test -v ./...
18+
19+
# Deploy the application binary into a lean image
20+
FROM gcr.io/distroless/base-debian11 AS build-release-stage
21+
22+
WORKDIR /
23+
24+
COPY --from=build-stage /pulsar-products-service /pulsar-products-service
25+
26+
EXPOSE 8080
27+
28+
USER nonroot:nonroot
29+
30+
ENTRYPOINT ["/pulsar-products-service"]

compose.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
pulsar-products-service:
3+
# image: yaninyzwitty/pulsar-products-service:latest
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
ports:
8+
- "3000:3000"
9+
env_file:
10+
- .env
11+
configs:
12+
- source: my_config
13+
target: ./my_config.yaml
14+
networks:
15+
- private_network
16+
17+
18+
19+
configs:
20+
my_config:
21+
file: config.yaml
22+
networks:
23+
private_network:
24+
driver: bridge
25+
ipam:
26+
config:
27+
- subnet: "10.0.0.0/19"
28+
gateway: "10.0.0.1"

cmd/server/main.go main.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"syscall"
1111
"time"
1212

13-
"github.com/joho/godotenv"
1413
"github.com/yaninyzwitty/pulsar-outbox-products-service/controller"
1514
"github.com/yaninyzwitty/pulsar-outbox-products-service/database"
1615
"github.com/yaninyzwitty/pulsar-outbox-products-service/helpers"
@@ -28,7 +27,7 @@ var (
2827

2928
func main() {
3029
// Load configuration
31-
file, err := os.Open("config.yaml")
30+
file, err := os.Open("my_config.yaml")
3231
if err != nil {
3332
slog.Error("failed to open config.yaml", "error", err)
3433
os.Exit(1)
@@ -40,10 +39,10 @@ func main() {
4039
os.Exit(1)
4140
}
4241

43-
if err := godotenv.Load(); err != nil {
44-
slog.Error("failed to load .env", "error", err)
45-
os.Exit(1)
46-
}
42+
// if err := godotenv.Load(); err != nil {
43+
// slog.Error("failed to load .env", "error", err)
44+
// os.Exit(1)
45+
// }
4746
password = os.Getenv("DB_PASSWORD")
4847
token = os.Getenv("PULSAR_TOKEN")
4948

0 commit comments

Comments
 (0)