From 833cb4d05526111d842ba37a201d264562784045 Mon Sep 17 00:00:00 2001 From: Jetsung Chan Date: Fri, 18 Jul 2025 09:27:22 +0000 Subject: [PATCH] feat: Support Docker builds using GitHub Action --- .github/workflows/docker-dev.yml | 85 +++++++++++++++++++++++++++++++ .github/workflows/docker.yml | 86 ++++++++++++++++++++++++++++++++ docker/Dockerfile | 26 ++++++++++ 3 files changed, 197 insertions(+) create mode 100644 .github/workflows/docker-dev.yml create mode 100644 .github/workflows/docker.yml create mode 100644 docker/Dockerfile diff --git a/.github/workflows/docker-dev.yml b/.github/workflows/docker-dev.yml new file mode 100644 index 0000000..53effcd --- /dev/null +++ b/.github/workflows/docker-dev.yml @@ -0,0 +1,85 @@ +name: Docker-Dev + +on: + push: + branches: + - dev + paths: + - ".github/workflows/docker-dev.yml" + - "docker/Dockerfile" + - "src/**" + - "Cargo.toml" + +env: + package_name: simple-http-server + GHCR_SLUG: ghcr.io/${{ github.repository }} + +jobs: + build: + strategy: + matrix: + arch: [amd64, arm64] + include: + - arch: amd64 + runner: ubuntu-24.04 + tag: dev-amd64 + - arch: arm64 + runner: ubuntu-24.04-arm + tag: dev-arm64 + runs-on: ${{ matrix.runner }} + steps: + - name: Checkout Source Code + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry (ghcr.io) + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.GHCR_SLUG }} + tags: ${{ matrix.tag }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/Dockerfile + platforms: linux/${{ matrix.arch }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ env.GHCR_SLUG }}:${{ matrix.tag }} + + manifest: + needs: build + runs-on: ubuntu-24.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create and push multi-arch manifest + run: | + docker manifest create ${{ env.GHCR_SLUG }}:dev \ + --amend ${{ env.GHCR_SLUG }}:dev-amd64 \ + --amend ${{ env.GHCR_SLUG }}:dev-arm64 + docker manifest push ${{ env.GHCR_SLUG }}:dev + shell: bash + + - uses: actions/delete-package-versions@v5 + continue-on-error: true + with: + package-name: ${{ env.package_name }} + package-type: 'container' + min-versions-to-keep: 2 + delete-only-untagged-versions: 'true' \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..2071a68 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,86 @@ +name: Docker + +on: + push: + branches: + - main + - master + paths: + - ".github/workflows/docker.yml" + - "docker/Dockerfile" + - "src/**" + - "Cargo.toml" + +env: + package_name: simple-http-server + GHCR_SLUG: ghcr.io/${{ github.repository }} + +jobs: + build: + strategy: + matrix: + arch: [amd64, arm64] + include: + - arch: amd64 + runner: ubuntu-24.04 + tag: amd64 + - arch: arm64 + runner: ubuntu-24.04-arm + tag: arm64 + runs-on: ${{ matrix.runner }} + steps: + - name: Checkout Source Code + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry (ghcr.io) + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.GHCR_SLUG }} + tags: ${{ matrix.tag }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/Dockerfile + platforms: linux/${{ matrix.arch }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ env.GHCR_SLUG }}:${{ matrix.tag }} + + manifest: + needs: build + runs-on: ubuntu-24.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create and push multi-arch manifest + run: | + docker manifest create ${{ env.GHCR_SLUG }}:latest \ + --amend ${{ env.GHCR_SLUG }}:amd64 \ + --amend ${{ env.GHCR_SLUG }}:arm64 + docker manifest push ${{ env.GHCR_SLUG }}:latest + shell: bash + + - uses: actions/delete-package-versions@v5 + continue-on-error: true + with: + package-name: ${{ env.package_name }} + package-type: 'container' + min-versions-to-keep: 2 + delete-only-untagged-versions: 'true' \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..9064abd --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,26 @@ +# This file is copied from: https://github.com/k4yt3x/simple-http-server/blob/master/Dockerfile +# LICENS: BSD 2-Clause "Simplified" License +# please see https://github.com/k4yt3x/simple-http-server/blob/master/LICENSE for more details + +FROM rust:1.88-alpine AS builder +WORKDIR /build +COPY . . +RUN <