From 615516eedc95502e14443906f615e014c8b541f3 Mon Sep 17 00:00:00 2001 From: Gaius Date: Tue, 26 Dec 2023 22:24:14 +0800 Subject: [PATCH] feat: add dfdameon Dockerfile and push docker actions (#166) Signed-off-by: Gaius --- .github/workflows/docker.yml | 74 ++++++++++++++++++++++++++++++++++++ Dockerfile | 32 ++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..c68de70d --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,74 @@ +name: Docker + +on: + push: + branches: + - main + tags: + - v* + +jobs: + push_image_to_registry: + name: Push Image + runs-on: ubuntu-latest + timeout-minutes: 120 + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Get Version + id: get_version + run: | + VERSION=${GITHUB_REF#refs/tags/} + if [[ ${GITHUB_REF} == "refs/heads/main" ]]; then + VERSION=latest + fi + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + + - name: Get Git Revision + id: vars + shell: bash + run: | + echo "git_revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: PrepareReg Names + run: | + echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login Docker Hub + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push to Registry + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + labels: |- + org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.revision=${{ github.sha }} + build-args: | + GITVERSION=git-${{ steps.vars.outputs.git_revision }} + VERSION=${{ steps.get_version.outputs.VERSION }} + tags: | + dragonflyoss/dfdaemon-rs:${{ steps.get_version.outputs.VERSION }} + ghcr.io/${{ env.IMAGE_REPOSITORY }}/dfdaemon-rs:${{ steps.get_version.outputs.VERSION }} + push: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..95ba026d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +ARG BASE_IMAGE=alpine:3.17 + +FROM rust:alpine as builder + +RUN apk add --no-cache build-base + +WORKDIR /app/client +COPY Cargo.toml Cargo.lock ./ +COPY src/ src/ +RUN cargo build --release + +FROM ${BASE_IMAGE} as health + +ENV GRPC_HEALTH_PROBE_VERSION v0.4.24 + +RUN if [ "$(uname -m)" = "ppc64le" ]; then \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-ppc64le; \ + elif [ "$(uname -m)" = "aarch64" ]; then \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-arm64; \ + else \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64; \ + fi && \ + chmod +x /bin/grpc_health_probe + +FROM ${BASE_IMAGE} + +COPY --from=builder /app/client/target/release/dfget /usr/local/bin/dfget +COPY --from=builder /app/client/target/release/dfdaemon /usr/local/bin/dfdaemon +COPY --from=builder /app/client/target/release/dfstore /usr/local/bin/dfstore +COPY --from=health /bin/grpc_health_probe /bin/grpc_health_probe + +ENTRYPOINT ["dfdaemon"]