-
Notifications
You must be signed in to change notification settings - Fork 0
#4: support Docker Compose #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| FROM golang:1.23.4-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY go.mod go.sum ./ | ||
|
|
||
| RUN go mod download && go mod verify | ||
|
|
||
| COPY . . | ||
|
|
||
| RUN go build -o transat-backend main.go | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| ENV PORT=3000 | ||
|
|
||
| ENTRYPOINT [ "./transat-backend" ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,32 @@ services: | |
| POSTGRES_USER: ${DB_USER} # Variable du fichier .env | ||
| POSTGRES_PASSWORD: ${DB_PASS} # Variable du fichier .env | ||
| ports: | ||
| - "5432:5432" # Mappe le port 5432 du conteneur au port 5432 de l'hôte | ||
| - "${DB_PORT}:5432" # Mappe le port 5432 du conteneur au port 5432 de l'hôte | ||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data # Persiste les données de la base de données | ||
|
|
||
| transat-backend: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| command: go run main.go | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Leverage the compiled binary instead of Overriding the Dockerfile’s - command: go run main.go
+ command: ["./transat-backend"]🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use go run main.go because I want the code to be compiled again at each code modification, with the watch. Is it correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @luclu7 You are absolutely correct! For your development setup with Docker Compose watch, using Here's why your setup works perfectly for development:
Your current setup gives you the hot reload development experience you want. The compiled binary approach I initially suggested would be more appropriate for production deployments where:
For production, you could consider a multi-stage Dockerfile that builds the binary and copies it to a minimal runtime image, but for development, your approach is spot on! |
||
| ports: | ||
| - "${PORT}:3000" | ||
| depends_on: | ||
| - db | ||
| environment: | ||
| - DB_HOST=db | ||
| develop: | ||
| watch: | ||
| - path: . | ||
| action: sync+restart | ||
| target: /app | ||
| ignore: | ||
| - .env | ||
| - .git | ||
| - .gitignore | ||
| - .idea | ||
|
|
||
| volumes: | ||
| postgres_data: | ||
| driver: local | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Reduce image size via multi-stage build
Right now, the final image still contains the Go toolchain and build artifacts. Introduce a second runtime stage that copies only the compiled binary into a minimal base image (e.g., Alpine or scratch). This will dramatically shrink image size and attack surface.
Add this after line 11 in your Dockerfile:
🤖 Prompt for AI Agents