Skip to content

Commit

Permalink
feat: add news service to deployment
Browse files Browse the repository at this point in the history
* rename api service to users service
  • Loading branch information
fabioDMFerreira committed Sep 21, 2023
1 parent d762c37 commit 59a406a
Show file tree
Hide file tree
Showing 59 changed files with 258 additions and 83 deletions.
60 changes: 30 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]

members = [
"api",
"users",
"consumer",
"utils",
"news"
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ test:


build-prod:
docker build -t ffff/rust-api-prod -f ./docker.prod/Dockerfile.api .
docker build -t ffff/rust-users-prod -f ./docker.prod/Dockerfile.users .
docker build -t ffff/rust-news-prod -f ./docker.prod/Dockerfile.news .
docker build -t ffff/rust-fe-prod -f ./docker.prod/Dockerfile.fe .
docker build -t ffff/rust-migrations-prod -f ./docker.prod/Dockerfile.migrations .
docker build -t ffff/rust-users-migrations-prod -f ./docker.prod/Dockerfile.users-migrations .
docker build -t ffff/rust-news-migrations-prod -f ./docker.prod/Dockerfile.news-migrations .
docker build -t ffff/rust-consumer-prod -f ./docker.prod/Dockerfile.consumer .

deploy-k8s:
Expand Down
18 changes: 9 additions & 9 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ services:
volumes:
- ./data/kafka:/var/lib/kafka/data

api:
users:
build:
context: .
dockerfile: ./api/Dockerfile.dev
dockerfile: ./users/Dockerfile.dev
ports:
- 8000:8000
volumes:
- ./api/src:/app/api/src
- ./users/src:/app/users/src
- ./utils/src:/app/utils/src
- ./logs/api:/var/log/app
- ./logs/users:/var/log/app
environment:
CORS_ORIGIN: http://localhost:3000
DATABASE_URL: "postgres://myuser:mypassword@postgres:5432/mydb?options=-c%20search_path%3Dusers"
JWT_EXPIRED_IN: 60
JWT_MAX_AGE: 3600
JWT_SECRET: api-secret-1234
JWT_SECRET: users-secret-1234
KAFKA_URL: kafka:29092
LOGS_PATH: /var/log/app/stdout.log
PORT: 8000
Expand All @@ -80,12 +80,12 @@ services:
condition: service_healthy
kafka:
condition: service_healthy
api-migrations:
users-migrations:
condition: service_completed_successfully

api-migrations:
users-migrations:
build:
context: ./api
context: ./users
dockerfile: Dockerfile.migrations
environment:
RUST_LOG: info
Expand Down Expand Up @@ -156,5 +156,5 @@ services:
ports:
- 3000:3000
depends_on:
- api
- users
- news
56 changes: 56 additions & 0 deletions docker.prod/Dockerfile.news
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ARG RUST_VERSION=1.72.0
ARG APP_NAME=news
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
WORKDIR /app

# dependencies to compile the Kafka client
RUN apt-get update && apt-get install -y build-essential \
curl \
openssl libssl-dev \
pkg-config \
python \
valgrind \
zlib1g-dev

# dependencies to compile diesel client
RUN apt-get install -y \
libpq-dev

RUN echo "[workspace]\n\
members = [\n\
\"news\",\n\
\"utils\"\n\
]" > ./Cargo.toml

COPY ./news/Cargo.toml ./news/
COPY ./utils/Cargo.toml ./utils/

RUN mkdir news/src
RUN echo "fn main() {}" > ./news/src/main.rs

RUN mkdir utils/src
RUN echo "fn main() {}" > ./utils/src/main.rs

RUN cargo build --release

COPY ./utils/src ./utils/src
COPY ./news/src ./news/src

RUN cargo build --release

RUN cp ./target/release/$APP_NAME /bin/server


FROM debian:bullseye-slim AS final

RUN apt-get update && apt-get install -y \
libpq-dev \
openssl libssl-dev \
ca-certificates

COPY --from=build /bin/server /bin/

EXPOSE 8001

CMD ["/bin/server"]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG RUST_VERSION=1.72.0
ARG APP_NAME=api
ARG APP_NAME=news
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
WORKDIR /app
Expand All @@ -9,6 +9,6 @@ RUN apt-get update && apt-get install -y \

RUN cargo install diesel_cli --no-default-features --features postgres

COPY ./api/migrations /app/migrations
COPY ./news/migrations /app/migrations

CMD ["diesel","migration","run"]
12 changes: 6 additions & 6 deletions docker.prod/Dockerfile.api → docker.prod/Dockerfile.users
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG RUST_VERSION=1.72.0
ARG APP_NAME=api
ARG APP_NAME=users
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
WORKDIR /app
Expand All @@ -19,23 +19,23 @@ RUN apt-get install -y \

RUN echo "[workspace]\n\
members = [\n\
\"api\",\n\
\"users\",\n\
\"utils\"\n\
]" > ./Cargo.toml

COPY ./api/Cargo.toml ./api/Cargo.lock ./api/
COPY ./users/Cargo.toml ./users/Cargo.lock ./users/
COPY ./utils/Cargo.toml ./utils/

RUN mkdir api/src
RUN echo "fn main() {}" > ./api/src/main.rs
RUN mkdir users/src
RUN echo "fn main() {}" > ./users/src/main.rs

RUN mkdir utils/src
RUN echo "fn main() {}" > ./utils/src/main.rs

RUN cargo build --release

COPY ./utils/src ./utils/src
COPY ./api/src ./api/src
COPY ./users/src ./users/src

RUN cargo build --release

Expand Down
14 changes: 14 additions & 0 deletions docker.prod/Dockerfile.users-migrations
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG RUST_VERSION=1.72.0
ARG APP_NAME=users
FROM rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
WORKDIR /app

RUN apt-get update && apt-get install -y \
libpq-dev

RUN cargo install diesel_cli --no-default-features --features postgres

COPY ./users/migrations /app/migrations

CMD ["diesel","migration","run"]
4 changes: 2 additions & 2 deletions frontend/src/setupProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function (app) {
.use(
'/api/auth',
createProxyMiddleware({
target: 'http://api:8000',
target: 'http://users:8000',
changeOrigin: true,
pathRewrite: {
'^/api/': '/',
Expand All @@ -45,7 +45,7 @@ module.exports = function (app) {
.use(
'/ws',
createProxyMiddleware({
target: 'ws://api:8000',
target: 'ws://users:8000',
changeOrigin: true,
})
);
Expand Down
Loading

0 comments on commit 59a406a

Please sign in to comment.