Skip to content

Commit

Permalink
fix: dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
thuan2172001 committed May 19, 2024
1 parent 5309043 commit 609762c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
17 changes: 0 additions & 17 deletions Cargo.lock

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

28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ COPY . .
RUN cargo build --release --all
RUN mv target/${CARGO_BUILD_TARGET}/release /out

FROM alpine AS dev
FROM alpine AS public-dev
WORKDIR /user
COPY src/public/config/00-default.toml 00-default.toml
COPY --from=builder /out/cli /usr/local/bin/rust-server
COPY --from=builder /out/cli /usr/local/bin/rust-api-server
COPY --from=bunyan /root/.cargo/bin/bunyan /usr/local/bin/
ENTRYPOINT ["/bin/sh"]
CMD ["-c", "/usr/local/bin/rust-server --config-path=*.toml | bunyan"]
CMD ["-c", "/usr/local/bin/rust-api-server --config-path=*.toml | bunyan"]

FROM alpine AS dev
FROM alpine AS gpt-dev
WORKDIR /user
COPY src/public/config/00-default.toml 00-default.toml
COPY --from=builder /out/cli /usr/local/bin/rust-server
COPY src/gpt_answer_server/config/00-default.toml 00-default.toml
COPY --from=builder /out/gpt_answer_server /usr/local/bin/rust-grpc-server
COPY --from=bunyan /root/.cargo/bin/bunyan /usr/local/bin/
ENTRYPOINT ["/bin/sh"]
CMD ["-c", "/usr/local/bin/rust-server --config-path=*.toml | bunyan"]
CMD ["-c", "/usr/local/bin/rust-grpc-server --config-path=*.toml | bunyan"]

FROM scratch AS prod
FROM scratch AS public-prod
WORKDIR /user
COPY src/public/config/00-default.toml 00-default.toml
COPY --from=builder /out/cli /usr/local/bin/rust-server
ENTRYPOINT ["/usr/local/bin/rust-server", "--config-path=*.toml"]
COPY --from=builder /out/cli /usr/local/bin/rust-api-server
ENTRYPOINT ["/usr/local/bin/rust-api-server", "--config-path=*.toml"]

FROM scratch AS prod
FROM scratch AS gpt-prod
WORKDIR /user
COPY src/public/config/00-default.toml 00-default.toml
COPY --from=builder /out/cli /usr/local/bin/rust-server
ENTRYPOINT ["/usr/local/bin/rust-server", "--config-path=*.toml"]
COPY src/gpt_answer_server/config/00-default.toml 00-default.toml
COPY --from=builder /out/gpt_answer_server /usr/local/bin/rust-grpc-server
ENTRYPOINT ["/usr/local/bin/rust-grpc-server", "--config-path=*.toml"]
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ POSTGRES_DIR="./src/adapter/src/repositories/postgres"
DATABASE_URL="postgres://postgres:[email protected]:5432/postgres"

PKG_NAME=rust-api-server
PKG_NAME_GRPC=rust-grpc-server
BUILD_VERSION=$(shell git describe --long)
BUILD_RELEASE=$(shell git describe --tags --abbrev=0)


lint:
cargo clippy --fix --allow-dirty --allow-staged

Expand All @@ -26,16 +26,23 @@ migrate-redo:

build:
PKG_NAME=rust-api-server
PKG_NAME_GRPC=rust-grpc-server
BUILD_VERSION=$(shell git describe --long)
BUILD_RELEASE=$(shell git describe --tags --abbrev=0)
BUILDKIT_PROGRESS=plain
DOCKER_BUILDKIT=1
docker build -t $(PKG_NAME):$(BUILD_VERSION) --target=public-prod .
docker build -t $(PKG_NAME):$(BUILD_VERSION) --target=gpt-prod .
docker build -t $(PKG_NAME_GRPC):$(BUILD_VERSION) --target=gpt-prod .

build-dev:
BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker build -t $(PKG_NAME):$(BUILD_VERSION) --target=public-dev .
BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker build -t $(PKG_NAME):$(BUILD_VERSION) --target=gpt-dev .
BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker build -t $(PKG_NAME_GRPC):$(BUILD_VERSION) --target=gpt-dev .

profiling-public:
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --root -- -c ./src/public/config/* -c ./deploy/local/custom.toml
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --root -- -c ./src/public/config/* -c ./deploy/local/custom.toml

run-api-server:
docker run -it --rm $(PKG_NAME):$(BUILD_VERSION)

run-grpc-server:
docker run -it --rm $(PKG_NAME_GRPC):$(BUILD_VERSION)

0 comments on commit 609762c

Please sign in to comment.