|
| 1 | +name: Build and Push docker image |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: master |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - '*' |
| 8 | + tags: |
| 9 | + - v* |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'wahyd4/aria2-ariang-docker' |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@master |
| 16 | + - |
| 17 | + name: Update APP VERSION |
| 18 | + if: contains(github.ref, '/tags/v') |
| 19 | + run: | |
| 20 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 21 | + echo $VERSION > APP_VERSION |
| 22 | + - |
| 23 | + name: Prepare |
| 24 | + id: prepare |
| 25 | + run: | |
| 26 | + DOCKER_IMAGE=wahyd4/aria2-ui |
| 27 | + DOCKER_PLATFORMS=linux/amd64,linux/arm/v7,linux/arm64 |
| 28 | + VERSION=edge |
| 29 | +
|
| 30 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 31 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 32 | + fi |
| 33 | + TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" |
| 34 | + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then |
| 35 | + TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" |
| 36 | + fi |
| 37 | +
|
| 38 | + echo ::set-output name=docker_image::${DOCKER_IMAGE} |
| 39 | + echo ::set-output name=version::${VERSION} |
| 40 | + echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ |
| 41 | + --build-arg VERSION=${VERSION} \ |
| 42 | + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ |
| 43 | + --build-arg VCS_REF=${GITHUB_SHA::8} \ |
| 44 | + ${TAGS} --file Dockerfile . |
| 45 | + - |
| 46 | + name: Set up QEMU |
| 47 | + uses: docker/setup-qemu-action@v1 |
| 48 | + - |
| 49 | + name: Set up Docker Buildx |
| 50 | + uses: docker/setup-buildx-action@v1 |
| 51 | + - |
| 52 | + name: Cache Docker layers |
| 53 | + uses: actions/cache@v2 |
| 54 | + id: cache |
| 55 | + with: |
| 56 | + path: /tmp/.buildx-cache |
| 57 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-buildx- |
| 60 | + - |
| 61 | + name: Docker Buildx (build) |
| 62 | + run: | |
| 63 | + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} |
| 64 | + - |
| 65 | + name: Login to DockerHub |
| 66 | + if: contains(github.ref, '/heads/master') || contains(github.ref, '/tags/v') |
| 67 | + uses: docker/login-action@v1 |
| 68 | + with: |
| 69 | + username: ${{ secrets.DOCKER_HUB_USER }} |
| 70 | + password: ${{ secrets.DOCKER_HUB_PASS }} |
| 71 | + - |
| 72 | + name: Push docker images to Dockerhub |
| 73 | + if: contains(github.ref, '/heads/master') || contains(github.ref, '/tags/v') |
| 74 | + run: | |
| 75 | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} |
| 76 | + - |
| 77 | + name: Inspect image |
| 78 | + if: contains(github.ref, '/heads/master') || contains(github.ref, '/tags/v') |
| 79 | + run: | |
| 80 | + docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} |
| 81 | + - |
| 82 | + name: Commit changes |
| 83 | + if: contains(github.ref, '/tags/v') |
| 84 | + uses: EndBug/add-and-commit@v7 |
| 85 | + with: |
| 86 | + author_name: junv-repo-bot |
| 87 | + |
| 88 | + message: 'Update version' |
| 89 | + add: 'APP_VERSION' |
| 90 | + push: true |
| 91 | + branch: master |
| 92 | + - |
| 93 | + name: Update tag |
| 94 | + if: contains(github.ref, '/tags/v') |
| 95 | + env: |
| 96 | + API_KEY: ${{ secrets.BadgeAPIKey }} |
| 97 | + run: | |
| 98 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 99 | + curl --max-time 6 -XPUT -D- 'https://badges.toozhao.com/val/aria2-ui-docker' \ |
| 100 | + -H 'Content-Type: application/json' \ |
| 101 | + -H 'API_KEY': ${API_KEY} \ |
| 102 | + -d '{"value": "'${VERSION}'"}' || true |
0 commit comments