From f8f4f6bfe5f22af3a9000c36a97fe8040241da5d Mon Sep 17 00:00:00 2001 From: Lucie Delestre Date: Wed, 28 May 2025 16:00:27 +0200 Subject: [PATCH 1/2] #4: support Docker Compose --- Dockerfile | 17 +++++++++++++++++ compose.yml | 29 ++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3600162 --- /dev/null +++ b/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/compose.yml b/compose.yml index 66e604e..89b84b8 100644 --- a/compose.yml +++ b/compose.yml @@ -8,10 +8,37 @@ 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 + ports: + - "${PORT}:3000" + depends_on: + - db + environment: + - DB_HOST=db + - DB_PORT=${DB_PORT} + - DB_NAME=${DB_NAME} + - DB_USER=${DB_USER} + - DB_PASS=${DB_PASS} + develop: + watch: + - path: . + action: sync+restart + target: /app + ignore: + - .env + - .git + - .gitignore + - .DS_Store + - .idea + volumes: postgres_data: driver: local \ No newline at end of file From 28bb09ef1d4a23b29fbc19dcf0e024fb3e9595ec Mon Sep 17 00:00:00 2001 From: Lucie Delestre Date: Wed, 28 May 2025 16:30:56 +0200 Subject: [PATCH 2/2] lapin --- compose.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compose.yml b/compose.yml index 89b84b8..7ad126b 100644 --- a/compose.yml +++ b/compose.yml @@ -23,10 +23,6 @@ services: - db environment: - DB_HOST=db - - DB_PORT=${DB_PORT} - - DB_NAME=${DB_NAME} - - DB_USER=${DB_USER} - - DB_PASS=${DB_PASS} develop: watch: - path: . @@ -36,7 +32,6 @@ services: - .env - .git - .gitignore - - .DS_Store - .idea volumes: