diff --git a/api_gateway.Dockerfile b/api_gateway.Dockerfile new file mode 100644 index 0000000..39d2bb4 --- /dev/null +++ b/api_gateway.Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.22-alpine as server +WORKDIR /app + +COPY ../go.mod . +RUN go mod download + +COPY .. . + +RUN go build -o /app/main ./api_gateway/cmd/api_gateway + +CMD [ "/app/main" ] diff --git a/api_gateway/Makefile b/api_gateway/Makefile index 0a97e7e..140a506 100644 --- a/api_gateway/Makefile +++ b/api_gateway/Makefile @@ -2,4 +2,4 @@ include .env export run: - go run ./cmd/gateway/main.go + go run ./cmd/api_gateway/main.go diff --git a/api_gateway/cmd/gateway/main.go b/api_gateway/cmd/api_gateway/main.go similarity index 100% rename from api_gateway/cmd/gateway/main.go rename to api_gateway/cmd/api_gateway/main.go diff --git a/bookback/Dockerfile b/auth.Dockerfile similarity index 73% rename from bookback/Dockerfile rename to auth.Dockerfile index c432073..e49af6f 100644 --- a/bookback/Dockerfile +++ b/auth.Dockerfile @@ -6,6 +6,6 @@ RUN go mod download COPY .. . -RUN go build -o /app/main ./cmd/bookback +RUN go build -o /app/main ./auth/cmd/auth CMD [ "/app/main" ] diff --git a/auth/.dockerignore b/auth/.dockerignore deleted file mode 100644 index 3aae539..0000000 --- a/auth/.dockerignore +++ /dev/null @@ -1,32 +0,0 @@ -# Include any files or directories that you don't want to be copied to your -# container here (e.g., local build artifacts, temporary files, etc.). -# -# For more help, visit the .dockerignore file reference guide at -# https://docs.docker.com/engine/reference/builder/#dockerignore-file - -**/.DS_Store -**/.classpath -**/.dockerignore -**/.env -**/.git -**/.gitignore -**/.project -**/.settings -**/.toolstarget -**/.vs -**/.vscode -**/*.*proj.user -**/*.dbmdl -**/*.jfm -**/bin -**/charts -**/docker-compose* -**/compose* -**/Dockerfile* -**/node_modules -**/npm-debug.log -**/obj -**/secrets.dev.yaml -**/values.dev.yaml -LICENSE -README.md diff --git a/auth/Dockerfile b/auth/Dockerfile deleted file mode 100644 index bb2d263..0000000 --- a/auth/Dockerfile +++ /dev/null @@ -1,72 +0,0 @@ -# syntax=docker/dockerfile:1 - -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Dockerfile reference guide at -# https://docs.docker.com/engine/reference/builder/ - -################################################################################ -# Create a stage for building the application. -ARG GO_VERSION=1.22 -FROM golang:${GO_VERSION} AS build -WORKDIR /src - -# Download dependencies as a separate step to take advantage of Docker's caching. -# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. -# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into -# the container. -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=bind,source=go.sum,target=go.sum \ - --mount=type=bind,source=go.mod,target=go.mod \ - go mod download -x - -# Build the application. -# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. -# Leverage a bind mount to the current directory to avoid having to copy the -# source code into the container. -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=bind,target=. \ - CGO_ENABLED=0 go build -o /bin/server . - -################################################################################ -# Create a new stage for running the application that contains the minimal -# runtime dependencies for the application. This often uses a different base -# image from the build stage where the necessary files are copied from the build -# stage. -# -# The example below uses the alpine image as the foundation for running the app. -# By specifying the "latest" tag, it will also use whatever happens to be the -# most recent version of that image when you build your Dockerfile. If -# reproducability is important, consider using a versioned tag -# (e.g., alpine:3.17.2) or SHA (e.g., alpine:sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff). -FROM alpine:latest AS final - -# Install any runtime dependencies that are needed to run your application. -# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds. -RUN --mount=type=cache,target=/var/cache/apk \ - apk --update add \ - ca-certificates \ - tzdata \ - && \ - update-ca-certificates - -# Create a non-privileged user that the app will run under. -# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user -ARG UID=10001 -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/nonexistent" \ - --shell "/sbin/nologin" \ - --no-create-home \ - --uid "${UID}" \ - appuser -USER appuser - -# Copy the executable from the "build" stage. -COPY --from=build /bin/server /bin/ - -# Expose the port that the application listens on. -EXPOSE 13245 - -# What the container should run when it is started. -ENTRYPOINT [ "/bin/server" ] diff --git a/auth/compose.yaml b/auth/compose.yaml deleted file mode 100644 index 7a64957..0000000 --- a/auth/compose.yaml +++ /dev/null @@ -1,50 +0,0 @@ -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Docker compose reference guide at -# https://docs.docker.com/compose/compose-file/ - -# Here the instructions define your application as a service called "server". -# This service is built from the Dockerfile in the current directory. -# You can add other services your application may depend on here, such as a -# database or a cache. For examples, see the Awesome Compose repository: -# https://github.com/docker/awesome-compose -services: - server: - build: - context: . - target: final - ports: - - 13245:13245 - -# The commented out section below is an example of how to define a PostgreSQL -# database that your application can use. `depends_on` tells Docker Compose to -# start the database before your application. The `db-data` volume persists the -# database data between container restarts. The `db-password` secret is used -# to set the database password. You must create `db/password.txt` and add -# a password of your choosing to it before running `docker compose up`. -# depends_on: -# db: -# condition: service_healthy -# db: -# image: postgres -# restart: always -# user: postgres -# secrets: -# - db-password -# volumes: -# - db-data:/var/lib/postgresql/data -# environment: -# - POSTGRES_DB=example -# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password -# expose: -# - 5432 -# healthcheck: -# test: [ "CMD", "pg_isready" ] -# interval: 10s -# timeout: 5s -# retries: 5 -# volumes: -# db-data: -# secrets: -# db-password: -# file: db/password.txt - diff --git a/auth/pkg/grpc/user_v1/user_v1.pb.gw.go b/auth/pkg/grpc/user_v1/user_v1.pb.gw.go index cfd0924..4880a13 100644 --- a/auth/pkg/grpc/user_v1/user_v1.pb.gw.go +++ b/auth/pkg/grpc/user_v1/user_v1.pb.gw.go @@ -1,4 +1,4 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// Code generated by protoc-gen-grpc-api_gateway. DO NOT EDIT. // source: user_v1.proto /* diff --git a/bookback.Dockerfile b/bookback.Dockerfile new file mode 100644 index 0000000..1a6b9c9 --- /dev/null +++ b/bookback.Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.22-alpine as builder +WORKDIR /app + +COPY ./api_gateway ./api_gateway +COPY ./auth ./auth +COPY ./bookback ./bookback +COPY ./logger ./logger +COPY ./metrics ./metrics +COPY ./postgres ./postgres +COPY ./scripts ./scripts +COPY ./go.work ./go.work + +RUN go build -o /app/main ./bookback/cmd/bookback + +FROM alpine:3.12 +WORKDIR /app + +COPY --from=builder /app/main /app/main +COPY --from=builder /app/bookback/config /app/config + +CMD [ "/app/main" ] diff --git a/deployments/docker-compose.yml b/deployments/docker-compose.yml deleted file mode 100644 index 549512d..0000000 --- a/deployments/docker-compose.yml +++ /dev/null @@ -1 +0,0 @@ -version: "3.8" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3b0f406 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,78 @@ +version: "3.8" + + +services: +# auth: +# build: +# dockerfile: auth.Dockerfile +# container_name: auth +# restart: always +# hostname: auth +# env_file: +# - ./auth/.env +# deploy: +# resources: +# limits: +# cpus: '2' +# memory: 250M +# logging: +# driver: "json-file" +# options: +# max-size: "50m" +# healthcheck: +# test: [ "CMD", "curl", "-f", "http://localhost:" ] +# interval: 1m30s +# timeout: 10s +# retries: 3 +# start_period: 2m + + bookback: + build: + context: . + dockerfile: bookback.Dockerfile + container_name: bookback + restart: always + hostname: bookback + env_file: + - ./bookback/.env + deploy: + resources: + limits: + cpus: '2' + memory: 250M + logging: + driver: "json-file" + options: + max-size: "50m" +# healthcheck: +# test: [ "CMD", "curl", "-f", "http://localhost:" ] +# interval: 3s +# retries: 5 +# start_period: 30s + +# api_gateway: +# build: +# dockerfile: api_gateway.Dockerfile +# container_name: api_gateway +# restart: always +# hostname: api_gateway +# env_file: +# - ./api_gateway/.env +# deploy: +# resources: +# limits: +# cpus: '2' +# memory: 250M +# logging: +# driver: "json-file" +# options: +# max-size: "50m" +# healthcheck: +# test: [ "CMD", "curl", "-f", "http://localhost:" ] +# interval: 3s +# retries: 5 +# start_period: 30s + +networks: + backnet: + driver: bridge \ No newline at end of file