add github workflow

This commit is contained in:
Masato Imai
2024-10-07 04:45:24 +00:00
parent c9ba37b505
commit baa08c7598
2 changed files with 72 additions and 0 deletions

53
.github/workflows/build.yml vendored Normal file
View File

@ -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

19
Dockerfile Normal file
View File

@ -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"]