chroe: add readme headline #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI - Staged Build and Push Docker Image | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*" | |
| jobs: | |
| pre_checks: | |
| name: Pre-checks | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tags: ${{ steps.generate_info.outputs.tags }} | |
| image_name: ${{ steps.generate_info.outputs.image_name }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Calculate Commit Count | |
| id: commit_count | |
| run: | | |
| echo "COUNT=$(git rev-list --count HEAD)" >> "$GITHUB_OUTPUT" | |
| - name: Generate Image Name and Tags | |
| id: generate_info | |
| env: | |
| REPOSITORY: ${{ github.repository }} | |
| SHA_SHORT: ${{ github.sha }} | |
| REF: ${{ github.ref }} | |
| COMMIT_COUNT: ${{ steps.commit_count.outputs.COUNT }} | |
| run: | | |
| IMAGE_NAME="ghcr.io/${REPOSITORY,,}" | |
| CUSTOM_VERSION_TAG="1.0.${COMMIT_COUNT}" | |
| TAG_LIST="$IMAGE_NAME:$CUSTOM_VERSION_TAG" | |
| if [[ "$REF" == "refs/heads/main" ]]; then | |
| TAG_LIST="${TAG_LIST},$IMAGE_NAME:latest" | |
| fi | |
| TAG_LIST="${TAG_LIST},$IMAGE_NAME:$(echo $SHA_SHORT | cut -c1-7)" | |
| case "$REF" in | |
| refs/tags/v*) | |
| GIT_TAG_VERSION="${REF#refs/tags/}" | |
| TAG_LIST="${TAG_LIST},$IMAGE_NAME:${GIT_TAG_VERSION}" | |
| ;; | |
| esac | |
| echo "Generated tags: $TAG_LIST" | |
| echo "tags=$TAG_LIST" >> "$GITHUB_OUTPUT" | |
| echo "image_name=$IMAGE_NAME" >> "$GITHUB_OUTPUT" | |
| build_and_publish: | |
| name: Build and Publish | |
| runs-on: ubuntu-latest | |
| needs: pre_checks | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to the Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ github.token }} | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| push: true | |
| tags: ${{ needs.pre_checks.outputs.tags }} | |
| cache-from: type=registry,ref=${{ needs.pre_checks.outputs.image_name }}:buildcache | |
| cache-to: type=registry,ref=${{ needs.pre_checks.outputs.image_name }}:buildcache,mode=max |