From d53583c469060e9e45e7fba15174486539bda732 Mon Sep 17 00:00:00 2001 From: Miao Wang Date: Sun, 13 Sep 2020 14:53:22 +0800 Subject: [PATCH] add github actions workflow to build docker images --- .github/workflows/docker-images.yml | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/docker-images.yml diff --git a/.github/workflows/docker-images.yml b/.github/workflows/docker-images.yml new file mode 100644 index 0000000..563f12d --- /dev/null +++ b/.github/workflows/docker-images.yml @@ -0,0 +1,82 @@ +name: docker-images + +on: + push: + branches: + - master + - docker-test + pull_request: + branches: + - master + - docker-test + +jobs: + multi: + + runs-on: ubuntu-latest + steps: + - + name: Determin docker tag + env: + TAG_NAME: ${{ github.ref }} + run: | + if [ "${TAG_NAME##*/}" = "master" ]; then + tag=latest + else + tag=build-test + fi + echo "::set-env name=docker_tag::${tag}" + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: arm64 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Cache Docker layers + uses: actions/cache@v2 + if: github.event_name == 'push' + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-mirrorweb-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-mirrorweb- + - + name: Cache Docker layers + uses: actions/cache@v2 + if: github.event_name == 'pull_request' + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-mirrorweb-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-mirrorweb- + ${{ runner.os }}-buildx-mirrorweb- + - + name: Cache Docker layers + if: github.event_name != 'push' && github.event_name != 'pull_request' + run: | + echo "I do not know how to setup cache" + exit -1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + if: github.event_name == 'push' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.build + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name == 'push' }} + tags: tunathu/mirror-web:${{ env.docker_tag }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache