commit 2a5e4e8984c763818991f29f079130fef812cea4 Author: Andreas Rocznik Date: Fri Nov 15 13:23:38 2024 +0200 Add action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..297732a --- /dev/null +++ b/action.yml @@ -0,0 +1,84 @@ +name: 'Tag Build and Push Docker image' +description: 'Tags verion in current repo, builds docker image and pushes it to registry' +inputs: + registry: # id of input + description: 'docker regisry host name' + required: true + default: 'gitea.phadric.de' + image_name: + description: 'name of the dockerimage' + required: true + default: ${{ github.repository }} + + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: gitea.phadric.de + # github.repository as / + IMAGE_NAME: ${{ github.repository }} +runs: + using: "composite" + steps: + - name: Checkout repository + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + with: + fetch-depth: '0' + + - name: Bump version and push tag + id: tag + uses: phadric/github-tag-action@a5250a59655e9f4b0350407380a92c73948f2aec # master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token + DEFAULT_BUMP: patch + GIT_API_TAGGING: false # dont use API + WITH_V: true + PRERELEASE: true + PRERELEASE_SUFFIX: ${{ github.ref_name }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 + with: + flavor: | + latest=${{ github.ref == 'refs/heads/main' }} + tags: | + type=sha + type=semver,pattern={{version}},value=${{steps.tag.outputs.tag}} + # output 0.1 + type=semver,pattern={{major}}.{{minor}},value=${{steps.tag.outputs.tag}} + # disabled if major zero + type=semver,pattern={{major}},value=${{steps.tag.outputs.tag}},enable=${{ !startsWith(steps.tag.outputs.tag, 'v0.') }} + images: ${{ inputs.registry }}/${{ inputs.image_name }} + + - uses: int128/docker-build-cache-config-action@34bb1b5886d06c161bf0dd9e169f03a52ff858fb # v1.35.0 + id: cache + with: + image: ${{ inputs.registry }}/${{ inputs.image_name }}-cache + extra-cache-to: image-manifest=true + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 + + - name: Log into registry ${{ inputs.registry }} + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + registry: ${{ inputs.registry }} + username: ${{ github.actor }} + password: ${{ secrets.TOKEN }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + platforms: linux/amd64 + labels: ${{ steps.meta.outputs.labels }} + cache-from: | + type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}-cache:latest + type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}-cache:main + ${{ steps.cache.outputs.cache-from }} + cache-to: | + ${{ steps.cache.outputs.cache-to }} + type=registry,ref=${{ inputs.registry }}/${{ inputs.image_name }}-cache:latest,mode=max,image-manifest=true