Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove main.go from cmd/server, add compose.yaml and dockerfile #12

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
28 changes: 28 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 5 additions & 6 deletions cmd/server/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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")

Expand Down