From 0726b11fe25b8577f5872848e2d57c3e11f6a9d3 Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Wed, 23 Jul 2025 00:59:18 +0800 Subject: [PATCH] BLOG-59 Enhance deployment workflow and backend server configuration (#60) ### Description - Updated deployment.yaml to specify separate build and push steps for frontend and backend. - Added Dockerfile for backend service to define build process. - Modified main.rs to bind the server to all network interfaces (0.0.0.0) instead of localhost. ### Package Changes _No response_ ### Screenshots _No response_ ### Reference Resolves #59 ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch Reviewed-on: https://git.squidspirit.com/squid/blog/pulls/60 Co-authored-by: SquidSpirit Co-committed-by: SquidSpirit --- .gitea/workflows/deployment.yaml | 12 +++++++++++- backend/Dockerfile | 15 +++++++++++++++ backend/server/src/main.rs | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 backend/Dockerfile diff --git a/.gitea/workflows/deployment.yaml b/.gitea/workflows/deployment.yaml index 6d83f9e..1f61d0d 100644 --- a/.gitea/workflows/deployment.yaml +++ b/.gitea/workflows/deployment.yaml @@ -24,7 +24,7 @@ jobs: username: ${{ vars.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build and push + - name: Build and push (Frontend) uses: docker/build-push-action@v6 with: push: true @@ -33,3 +33,13 @@ jobs: tags: | ${{ vars.REGISTRY }}/${{ vars.IMAGE_REPO_FRONTEND }}:latest ${{ vars.REGISTRY }}/${{ vars.IMAGE_REPO_FRONTEND }}:${{ gitea.event.release.tag_name }} + + - name: Build and push (Backend) + uses: docker/build-push-action@v6 + with: + push: true + provenance: false + context: ./backend + tags: | + ${{ vars.REGISTRY }}/${{ vars.IMAGE_REPO_BACKEND }}:latest + ${{ vars.REGISTRY }}/${{ vars.IMAGE_REPO_BACKEND }}:${{ gitea.event.release.tag_name }} diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..7693420 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,15 @@ +FROM rust:1-slim AS base +RUN apt update -qq && apt install -y -qq --no-install-recommends musl-tools +RUN rustup target add x86_64-unknown-linux-musl + +FROM base AS builder +WORKDIR /app +COPY . . +RUN cargo build --release --target x86_64-unknown-linux-musl + +FROM alpine:latest AS runner +WORKDIR /app +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/server . +EXPOSE 8080 +ENV DATABASE_URL=postgres://postgres@localhost:5432/postgres +CMD ["./server"] diff --git a/backend/server/src/main.rs b/backend/server/src/main.rs index 42d7c02..134e230 100644 --- a/backend/server/src/main.rs +++ b/backend/server/src/main.rs @@ -17,7 +17,7 @@ async fn main() -> std::io::Result<()> { let db_pool = init_database().await; HttpServer::new(move || create_app(db_pool.clone())) - .bind(("127.0.0.1", 8080))? + .bind(("0.0.0.0", 8080))? .run() .await }