Update .gitea/workflows/build-image.yml
This commit is contained in:
		| @@ -1,92 +1,47 @@ | ||||
| name: Image Build | ||||
|  | ||||
| on: | ||||
|   push: | ||||
|     branches: | ||||
|       - main | ||||
|   # Manueel starte | ||||
|   workflow_dispatch: | ||||
| # on: | ||||
| #   push: | ||||
| #     branches: | ||||
| #       - main | ||||
| #   workflow_dispatch: | ||||
| #     inputs: | ||||
| #       force_build: | ||||
| #         description: Force new build? | ||||
| #         required: false | ||||
| #         default: "false" | ||||
| #         type: string | ||||
| #   schedule: # run daily | ||||
| #     - cron: '0 0 * * *' | ||||
|   schedule: | ||||
|     - cron: '0 0 * * *' # run daily | ||||
|  | ||||
| jobs: | ||||
|   init: | ||||
|     runs-on: ubuntu-latest | ||||
|      # Map a step output to a job output | ||||
|     outputs: | ||||
|       iventoy: ${{ steps.iventoy.outputs.version }} | ||||
|       buildOrNot: ${{ steps.buildOrNot.outputs.buildOrNot }} | ||||
|     steps: | ||||
|       -  | ||||
|         name: get latest versions | ||||
|       - name: get latest versions | ||||
|         id: iventoy | ||||
|         run: | | ||||
|           version=$(curl -s https://api.github.com/repos/ventoy/PXE/releases/latest | grep "tag_name" | cut -d'"' -f4) | ||||
|           echo "version=${version#'v'}" >> $GITHUB_OUTPUT | ||||
|       - # Check labels of the latest image on docker hub | ||||
|         name:  | ||||
|         id: buildOrNOt | ||||
|         env: # if [ -z $FORCE_BUILD ]; then echo "false"; else echo $FORCE_BUILD; fi -> ternary -> ${FORCE_BUILD:-false} | ||||
|           FORCE_BUILD: ${{ github.event.inputs.force_build }} | ||||
|           echo "version=${version#'v'}" >> $GITEA_OUTPUT | ||||
|       - name: Check labels of the latest image on Docker Hub | ||||
|         id: buildOrNot | ||||
|         run: | | ||||
|           repo=${1:-${{ github.repository }}} | ||||
|           repo=${1:-$GITEA_REPO} | ||||
|           tag=${2:-latest} | ||||
|           token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" | jq -r '.token') | ||||
|           digest=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer $token" -s "https://registry-1.docker.io/v2/${repo}/manifests/${tag}" | jq -r .config.digest) | ||||
|           latest=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer $token" -s -L "https://registry-1.docker.io/v2/${repo}/blobs/${digest}" | jq . | grep -Ew "IVENTOY" | cut -d'"' -f4) | ||||
|           echo "buildOrNot=$([ $latest != '${{ steps.iventoy.outputs.version }}' ] && echo "true" || echo "${FORCE_BUILD:-false}")" >> $GITHUB_OUTPUT | ||||
|       -  | ||||
|         name: print | ||||
|         run: |  | ||||
|           echo ${{ steps.iventoy.outputs.version }} | ||||
|           echo ${{ steps.buildOrNot.outputs.buildOrNot }} | ||||
|           echo "buildOrNot=$([ $latest != '$GITEA_IVENTOY' ] && echo "true" || echo "$GITEA_FORCE_BUILD")" >> $GITEA_OUTPUT | ||||
|  | ||||
|   docker: | ||||
|     name: iventoy image | ||||
|     runs-on: ubuntu-latest | ||||
|     needs:  | ||||
|     needs: | ||||
|       - init | ||||
|     if: | | ||||
|       needs.init.outputs.buildOrNot == 'true' | ||||
|     if: ${{ needs.init.outputs.buildOrNot == 'true' }} | ||||
|     steps: | ||||
|       - | ||||
|         name: init vars | ||||
|       - name: Checkout | ||||
|         run: | | ||||
|           echo "iventoy: ${{ needs.init.outputs.iventoy }}" | ||||
|       - | ||||
|         name: Checkout | ||||
|         uses: actions/checkout@v3 | ||||
|       - | ||||
|         name: Login to Docker Hub | ||||
|         uses: docker/login-action@v2 | ||||
|         with: | ||||
|           username: ${{ secrets.DOCKERHUB_USERNAME }} | ||||
|           password: ${{ secrets.DOCKERHUB_TOKEN }} | ||||
|       - | ||||
|         name: Set up Docker Buildx | ||||
|         uses: docker/setup-buildx-action@v2 | ||||
|       - | ||||
|         name: Build and push | ||||
|         uses: docker/build-push-action@v4 | ||||
|         with: | ||||
|           provenance: false # Breaking change introduced with 3.3.0 https://github.com/docker/build-push-action/releases/tag/v3.3.0, when an image is pushed since that version I can't retrieve the blob with labels anymore based on the digest via registry api, night have to look into an alternative way to do this  | ||||
|           context: . | ||||
|           file: ./Dockerfile | ||||
|           labels: | | ||||
|             IVENTOY=${{ needs.init.outputs.iventoy }} | ||||
|           build-args: | | ||||
|             IVENTOY=${{ needs.init.outputs.iventoy }} | ||||
|           push: true | ||||
|           tags: | | ||||
|             ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ needs.init.outputs.iventoy }} | ||||
|             ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest | ||||
|           echo "Checkout repository" | ||||
|       - name: Login to Docker Hub | ||||
|         run: | | ||||
|           docker login -u $GITEA_DOCKERHUB_USERNAME -p $GITEA_DOCKERHUB_TOKEN | ||||
|       - name: Build and push | ||||
|         run: | | ||||
|           docker build -t $GITEA_DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:${GITEA_IVENTOY} --build-arg IVENTOY=$GITEA_IVENTOY . | ||||
|           docker push $GITEA_DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:${GITEA_IVENTOY} | ||||
|           docker tag $GITEA_DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:${GITEA_IVENTOY} $GITEA_DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:latest | ||||
|           docker push $GITEA_DOCKERHUB_USERNAME/${GITEA_REPOSITORY_NAME}:latest | ||||
|   | ||||
		Reference in New Issue
	
	Block a user