From 4bff6e940560d04ed87abda846a203bded477689 Mon Sep 17 00:00:00 2001 From: yyasha Date: Mon, 29 Jan 2024 22:55:20 +0300 Subject: [PATCH] add Dockerfile --- Dockerfile | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5985379 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM golang:alpine AS builder +LABEL builder=true +WORKDIR /build + +ADD go.mod . + +COPY . . +RUN go mod download +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -o cmd/recipes/main cmd/recipes/main.go +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -o cmd/parser/main cmd/parser/main.go +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -o cmd/migrator/main cmd/migrator/main.go + +FROM alpine + +WORKDIR /build + +COPY --from=builder /build/cmd/recipes/main /build/cmd/recipes/main +COPY --from=builder /build/cmd/migrator/main /build/cmd/migrator/main +COPY --from=builder /build/cmd/parser/main /build/cmd/parser/main +COPY --from=builder /build/config/* /build/config/ +COPY --from=builder /build/migrations/* /build/migrations/ + +RUN touch start.sh +RUN echo "#!/bin/sh" >> start.sh +RUN echo "./cmd/migrator/main --migrations-path migrations" >> start.sh +RUN echo "./cmd/recipes/main" >> start.sh +RUN chmod +x start.sh + +CMD ["./start.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9131596..163935e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,28 +14,30 @@ services: # - ./conf/traefik_custom:/custom/:ro # - /var/run/docker.sock:/var/run/docker.sock:ro - # # rest api - # app: - # build: - # context: . - # dockerfile: Dockerfile - # container_name: app - # restart: unless-stopped - # env_file: .env - # environment: - # DB_ADDR: app_pg:5432 - # MINIO_ADDR: minio:9000 - # depends_on: - # - app_pg - # labels: - # - "traefik.enable=true" - # - "traefik.http.routers.app.entrypoints=websecure" - # - "traefik.http.routers.app.tls=true" - # - "traefik.http.routers.app.tls.certresolver=production" - # - "traefik.http.routers.app.rule=Host(`$API_HOST`) && PathPrefix(`/api/v1/`)" - # networks: - # microservicesnet: - # ipv4_address: 192.168.4.3 + # rest api + app: + # build: + # context: . + # dockerfile: Dockerfile + image: recipes:latest + container_name: app + restart: unless-stopped + env_file: .env + environment: + CONFIG_PATH: ./config/local.yaml + depends_on: + - app_pg + - redis + - minio + # labels: + # - "traefik.enable=true" + # - "traefik.http.routers.app.entrypoints=websecure" + # - "traefik.http.routers.app.tls=true" + # - "traefik.http.routers.app.tls.certresolver=production" + # - "traefik.http.routers.app.rule=Host(`$API_HOST`)" + networks: + microservicesnet: + ipv4_address: 192.168.4.3 # postgresql database for app app_pg: