diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..d59ffad --- /dev/null +++ b/Justfile @@ -0,0 +1,8 @@ +run *ARGS: build + docker compose up {{ARGS}} + +stop: + docker compose down + +build: + docker compose build diff --git a/backend/.gitignore b/backend/.gitignore index 2f7896d..f222c24 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1 +1,2 @@ target/ +vendor/busybox_WGET diff --git a/backend/Dockerfile b/backend/Dockerfile index 7d1b991..f72c57f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -21,7 +21,10 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ cargo build --release --bin nuchat --target-dir=/app/target FROM gcr.io/distroless/cc AS runtime -WORKDIR /app -COPY --from=builder /app/target/release/nuchat ./nuchat -ENTRYPOINT [ "./nuchat", "--host 0.0.0.0" ] +ADD --chmod=a+x vendor/busybox_WGET /usr/bin/wget +COPY --from=builder /app/target/release/nuchat /usr/bin/ + +# HEALTHCHECK --interval=5s --retries=1 --timeout=5s CMD ["wget", "-q", "--spider", "http://localhost:7000/healthcheck + +ENTRYPOINT [ "nuchat", "--host", "0.0.0.0" ] diff --git a/docker-compose.yml b/docker-compose.yml index b7afaec..f5f17ea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,28 @@ services: build: ./ui ports: - "3000:3000" + depends_on: + backend: + condition: service_started + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://0.0.0.0:3000"] + interval: 1s + retries: 3 + timeout: 5s + backend: build: ./backend ports: - "7000:7000" + depends_on: + db: + condition: service_healthy + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://localhost:7000/healthcheck"] + interval: 1s + retries: 3 + timeout: 5s + db: image: postgres:17-alpine restart: unless-stopped @@ -14,8 +32,11 @@ services: - "5432:5432" environment: POSTGRES_DB: nuchat - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d nuchat"] + interval: 1s + retries: 3 + timeout: 5s volumes: - db-data:/var/lib/postgresql/data diff --git a/ui/Dockerfile b/ui/Dockerfile index b7ad638..e003372 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -1,4 +1,4 @@ -FROM node:24-slim AS base +FROM node:24-alpine AS base ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" @@ -24,8 +24,9 @@ FROM base AS runner COPY --from=prod /app/node_modules /app/node_modules COPY --from=build /app/build build/ -EXPOSE 3000 +ENV PORT=3000 ENV NODE_ENV=production +EXPOSE $PORT CMD ["node", "build"]