diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a2a1ea0 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,53 @@ +name: Docker Build and Push + +on: + release: + types: [created] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: | + type=gha,scope=planner + type=gha,scope=builder + type=gha,scope=runtime + cache-to: | + type=gha,mode=max,scope=planner + type=gha,mode=max,scope=builder + type=gha,mode=max,scope=runtime + target: runtime diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eb67dea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM lukemathwalker/cargo-chef:latest-rust-1.81.0 AS chef +WORKDIR app + +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +RUN apt-get update && apt-get install -y --no-install-recommends libssl-dev pkg-config gcc && apt-get -y clean +RUN cargo chef cook --release --recipe-path recipe.json +COPY . . +RUN cargo b -r + +FROM ubuntu:22.04 AS runtime +WORKDIR /fendbot +RUN apt-get update && apt-get install -y --no-install-recommends openssl ca-certificates libssl-dev && apt-get -y clean +COPY --from=builder /app/target/release/fendbot /usr/local/bin +ENTRYPOINT ["/usr/local/bin/fendbot"]