From 896679765bdd7d3b027674aedeb545ef22e7766a Mon Sep 17 00:00:00 2001 From: lennoxlotl Date: Mon, 21 Oct 2024 20:05:49 +0200 Subject: [PATCH] feat: simplify building --- .github/workflows/api.yml | 25 +++---------------------- api/Dockerfile | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index 10a562f..2ba5544 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -12,10 +12,7 @@ env: jobs: build: name: Build binary and push (api) - runs-on: ubuntu-22.04 - strategy: - matrix: - platform: [linux/amd64, linux/arm64] + runs-on: ubuntu-latest permissions: contents: read packages: write @@ -24,12 +21,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Setup environment - run: echo "ARCH=$(uname -m)" >> $GITHUB_ENV - - name: Build binary - run: cargo build --release - - name: Copy binary - run: mv target/release/api api/api - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx @@ -40,21 +31,11 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ env.ARCH }} - name: Build and push uses: docker/build-push-action@v3 with: push: true - platforms: linux/arm64 + platforms: linux/arm64, linux/amd64 context: api file: api/Dockerfile - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - # combine: - # name: Combine docker manifests - # runs-on: ubuntu-22.04 - # steps: + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} diff --git a/api/Dockerfile b/api/Dockerfile index 0376df0..c619004 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,10 +1,18 @@ +# Build the binary file +FROM rust:1.82.0-bullseye AS builder + +WORKDIR /api +COPY . . + +RUN cargo build --release + +# Run the binary file FROM debian:bullseye-slim -WORKDIR /opt/api -COPY ./api . +WORKDIR /api +COPY --from=builder /api/target/release/api ./api RUN apt update && apt install -y ca-certificates -RUN chmod +x /opt/api/api EXPOSE 8000 -CMD ["/opt/api/api"] \ No newline at end of file +CMD ["api"] \ No newline at end of file