Skip to content

Commit

Permalink
feat: simplify building
Browse files Browse the repository at this point in the history
  • Loading branch information
lennoxlotl committed Oct 21, 2024
1 parent c455d7f commit 8966797
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
25 changes: 3 additions & 22 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
16 changes: 12 additions & 4 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
CMD ["api"]

0 comments on commit 8966797

Please sign in to comment.