From a1d97013af9a7fdd64e9564cb7204ca9cd7eb9ad Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 13 Dec 2023 18:30:06 +0000 Subject: [PATCH] docker-compose file added --- Dockerfile | 9 ++++++--- docker-compose.yml | 28 ++++++++++++++++++++++++++++ main.go | 2 +- 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 35ed867..a2e7ba4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,3 @@ -# syntax=docker/dockerfile:1 - -# Build the application from source FROM golang:1.19 AS build-stage WORKDIR /app @@ -17,6 +14,12 @@ FROM gcr.io/distroless/base-debian11 AS build-release-stage WORKDIR / +COPY ./sql/schema ./ + +CMD ["go", "install", "github.com/pressly/goose/v3/cmd/goose@latest"] + +CMD ["goose", "postgres", "$GO_FEED_DB_URL", "up"] + COPY --from=build-stage /docker-gs-ping /docker-gs-ping EXPOSE 8080 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..43ed68a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +services: + gofeed: + build: + context: . + dockerfile: Dockerfile + ports: + - 8080:80 + depends_on: + - goose + environment: + - GO_FEED_DB_URL=postgres://gofeed:gofeed@postgres:5432/gofeed?sslmode=disable + - PORT=8080 + postgres: + image: postgres:15.4 + restart: always + environment: + - POSTGRES_USER=gofeed + - POSTGRES_PASSWORD=gofeed + - POSTGRES_DB=gofeed + ports: + - "15432:5432" + volumes: + - /sql/.nocode + healthcheck: + test: ["CMD-SHELL", "pg_isready -d gofeed -U gofeed"] + interval: 10s + timeout: 5s + retries: 5 \ No newline at end of file diff --git a/main.go b/main.go index af00ddb..e88acc2 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ func main() { log.Fatal("E#1OLYW6 - PORT is not found in the env variables") } - dbUrl := os.Getenv("DB_URL") + dbUrl := os.Getenv("GO_FEED_DB_URL") if dbUrl == "" { log.Fatal("E#1ORGYA - DB_URL is not found in the env variables") }