You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.4 KiB

4 years ago
4 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. name: Build DockerHub
  2. on:
  3. push:
  4. branches:
  5. - '*'
  6. tags:
  7. - '*'
  8. paths:
  9. - '**.sh'
  10. - "Dockerfile"
  11. - '.github/workflows/dockerhub.yml'
  12. concurrency:
  13. group: ${{ github.workflow }}-${{ github.ref }}
  14. cancel-in-progress: true
  15. env:
  16. DOCKER_IMAGE: neilpang/acme.sh
  17. jobs:
  18. CheckToken:
  19. runs-on: ubuntu-latest
  20. outputs:
  21. hasToken: ${{ steps.step_one.outputs.hasToken }}
  22. env:
  23. DOCKER_PASSWORD : ${{ secrets.DOCKER_PASSWORD }}
  24. steps:
  25. - name: Set the value
  26. id: step_one
  27. run: |
  28. if [ "$DOCKER_PASSWORD" ] ; then
  29. echo "hasToken=true" >>$GITHUB_OUTPUT
  30. else
  31. echo "hasToken=false" >>$GITHUB_OUTPUT
  32. fi
  33. - name: Check the value
  34. run: echo ${{ steps.step_one.outputs.hasToken }}
  35. build:
  36. runs-on: ubuntu-latest
  37. needs: CheckToken
  38. if: "contains(needs.CheckToken.outputs.hasToken, 'true')"
  39. steps:
  40. - name: checkout code
  41. uses: actions/checkout@v4
  42. - name: Set up QEMU
  43. uses: docker/setup-qemu-action@v2
  44. - name: Extract Docker metadata
  45. id: meta
  46. uses: docker/metadata-action@v5.5.1
  47. with:
  48. images: ${DOCKER_IMAGE}
  49. - name: Set up Docker Buildx
  50. uses: docker/setup-buildx-action@v2
  51. - name: login to docker hub
  52. run: |
  53. echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
  54. - name: build and push the image
  55. run: |
  56. if [[ $GITHUB_REF == refs/tags/* ]]; then
  57. DOCKER_IMAGE_TAG=${GITHUB_REF#refs/tags/}
  58. fi
  59. if [[ $GITHUB_REF == refs/heads/* ]]; then
  60. DOCKER_IMAGE_TAG=${GITHUB_REF#refs/heads/}
  61. if [[ $DOCKER_IMAGE_TAG == master ]]; then
  62. DOCKER_IMAGE_TAG=latest
  63. AUTO_UPGRADE=1
  64. fi
  65. fi
  66. DOCKER_LABELS=()
  67. while read -r label; do
  68. DOCKER_LABELS+=(--label "${label}")
  69. done <<<"${DOCKER_METADATA_OUTPUT_LABELS}"
  70. docker buildx build \
  71. --tag ${DOCKER_IMAGE}:${DOCKER_IMAGE_TAG} \
  72. "${DOCKER_LABELS[@]}" \
  73. --output "type=image,push=true" \
  74. --build-arg AUTO_UPGRADE=${AUTO_UPGRADE} \
  75. --platform linux/arm64/v8,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386,linux/ppc64le,linux/s390x .