From 2995dc66ae8025ebb29683b1d586b16ccdb1c6e3 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Thu, 2 Jun 2022 16:26:55 +1000 Subject: [PATCH] Add GitHub Actions - docker.yaml (#1977) * Add GitHub Actions via docker.yaml to build Docker images and push these to Docker Hub driveone/onedrive * Builds Fedora 36 linux/amd64 * Build Debian Bullseye linux/amd64,linux/arm64,linux/arm/v7 * Builds Alpine linux/amd64,linux/arm64 --- .github/workflows/docker.yaml | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/docker.yaml diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 00000000..d263da63 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,85 @@ +name: Build Docker Images + +on: + push: + branches: [ master ] + tags: [ 'v*' ] + pull_request: + +env: + DOCKER_HUB_SLUG: driveone/onedrive + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + flavor: [ fedora, debian, alpine ] + include: + - flavor: fedora + dockerfile: ./contrib/docker/Dockerfile + platforms: linux/amd64 + - flavor: debian + dockerfile: ./contrib/docker/Dockerfile-debian + platforms: linux/amd64,linux/arm64,linux/arm/v7 + - flavor: alpine + dockerfile: ./contrib/docker/Dockerfile-alpine + platforms: linux/amd64,linux/arm64 + + steps: + - name: Check out code from GitHub + uses: actions/checkout@v3 + with: + submodules: recursive + fetch-depth: 0 + + - name: Docker meta + id: docker_meta + uses: marcelcoding/ghaction-docker-meta@v1 + with: + tag-edge: true + images: | + ${{ env.DOCKER_HUB_SLUG }} + tag-semver: | + {{version}} + {{major}}.{{minor}} + flavor: ${{ matrix.flavor }} + main-flavor: ${{ matrix.flavor == 'debian' }} + + - uses: docker/setup-qemu-action@v2 + if: matrix.platforms != 'linux/amd64' + + - uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ matrix.flavor }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-${{ matrix.flavor }} + + - name: Login to Docker Hub + uses: docker/login-action@v2 + if: github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and Push to Docker + uses: docker/build-push-action@v3 + with: + context: . + file: ${{ matrix.dockerfile }} + platforms: ${{ matrix.platforms }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache \ No newline at end of file