release: v1.1.11 #316
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: Build and Push Docker Image | |
| on: | |
| push: | |
| branches: [ main, master, develop, dev ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main, master, develop, dev ] | |
| workflow_dispatch: | |
| inputs: | |
| tag_override: | |
| description: 'Override tag (e.g., beta, rc1)' | |
| required: false | |
| default: '' | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| runs-on: self-hosted | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| DOCKER_CONFIG: /tmp/docker-config-build-${{ github.run_id }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Docker login | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| mkdir -p "$DOCKER_CONFIG" | |
| echo "${{ secrets.CR_PAT || secrets.GITHUB_TOKEN }}" | docker --config "$DOCKER_CONFIG" login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin | |
| - name: Determine version info | |
| id: version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| VERSION="${{ github.ref_name }}" | |
| CHANNEL="stable" | |
| elif [[ "${{ github.ref }}" == refs/heads/main ]] || [[ "${{ github.ref }}" == refs/heads/master ]]; then | |
| VERSION="latest" | |
| CHANNEL="stable" | |
| elif [[ "${{ github.ref }}" == refs/heads/develop ]] || [[ "${{ github.ref }}" == refs/heads/dev ]]; then | |
| VERSION="dev" | |
| CHANNEL="development" | |
| else | |
| VERSION="${{ github.ref_name }}" | |
| CHANNEL="feature" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "channel=$CHANNEL" >> $GITHUB_OUTPUT | |
| echo "Building: $VERSION ($CHANNEL channel)" | |
| - name: Compute tags | |
| id: tags | |
| run: | | |
| REPO="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | |
| REPO=$(echo "$REPO" | tr '[:upper:]' '[:lower:]') | |
| SHA_SHORT=$(echo "${{ github.sha }}" | head -c 7) | |
| TAGS="" | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| VER="${{ github.ref_name }}" | |
| VER="${VER#v}" | |
| MAJOR=$(echo "$VER" | cut -d. -f1) | |
| MINOR=$(echo "$VER" | cut -d. -f1-2) | |
| TAGS="$REPO:$VER,$REPO:$MINOR,$REPO:latest,$REPO:stable,$REPO:sha-$SHA_SHORT" | |
| if [[ "$MAJOR" != "0" ]]; then | |
| TAGS="$TAGS,$REPO:$MAJOR" | |
| fi | |
| elif [[ "${{ github.ref }}" == refs/heads/main ]] || [[ "${{ github.ref }}" == refs/heads/master ]]; then | |
| TAGS="$REPO:main,$REPO:sha-$SHA_SHORT" | |
| elif [[ "${{ github.ref }}" == refs/heads/develop ]] || [[ "${{ github.ref }}" == refs/heads/dev ]]; then | |
| TAGS="$REPO:dev,$REPO:develop,$REPO:sha-$SHA_SHORT" | |
| elif [[ "${{ github.ref }}" == refs/heads/* ]]; then | |
| BRANCH="${{ github.ref_name }}" | |
| TAGS="$REPO:$BRANCH,$REPO:sha-$SHA_SHORT" | |
| else | |
| TAGS="$REPO:sha-$SHA_SHORT" | |
| fi | |
| if [[ -n "${{ github.event.inputs.tag_override }}" ]]; then | |
| TAGS="$TAGS,$REPO:${{ github.event.inputs.tag_override }}" | |
| fi | |
| echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
| echo "primary=$(echo $TAGS | cut -d, -f1)" >> $GITHUB_OUTPUT | |
| echo "Tags: $TAGS" | |
| - name: Build Docker image | |
| run: | | |
| IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" | |
| TAG_ARGS="" | |
| for tag in "${TAG_ARRAY[@]}"; do | |
| TAG_ARGS="$TAG_ARGS -t $tag" | |
| done | |
| docker build \ | |
| $TAG_ARGS \ | |
| --build-arg GIT_COMMIT=${{ github.sha }} \ | |
| --build-arg GIT_BRANCH=${{ github.ref_name }} \ | |
| --build-arg BUILD_TIME="$(date -u '+%Y-%m-%d %H:%M UTC')" \ | |
| . | |
| - name: Push Docker image | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" | |
| for tag in "${TAG_ARRAY[@]}"; do | |
| echo "Pushing $tag..." | |
| docker --config "$DOCKER_CONFIG" push "$tag" | |
| done | |
| - name: Cleanup | |
| if: always() | |
| run: | | |
| docker --config "$DOCKER_CONFIG" logout ${{ env.REGISTRY }} 2>/dev/null || true | |
| rm -rf "$DOCKER_CONFIG" | |
| - name: Summary | |
| run: | | |
| echo "## Docker Build Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Channel:** ${{ steps.version.outputs.channel }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Platform:** linux/amd64" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Tags pushed:" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.tags.outputs.tags }}" | tr ',' '\n' >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| # Build RunPod Exporter image | |
| build-runpod-exporter: | |
| runs-on: self-hosted | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| DOCKER_CONFIG: /tmp/docker-config-runpod-${{ github.run_id }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Docker login | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| mkdir -p "$DOCKER_CONFIG" | |
| echo "${{ secrets.CR_PAT || secrets.GITHUB_TOKEN }}" | docker --config "$DOCKER_CONFIG" login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin | |
| - name: Compute tags | |
| id: tags | |
| run: | | |
| REPO="${{ env.REGISTRY }}/cryptolabsza/runpod-exporter" | |
| SHA_SHORT=$(echo "${{ github.sha }}" | head -c 7) | |
| TAGS="" | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| VER="${{ github.ref_name }}" | |
| VER="${VER#v}" | |
| TAGS="$REPO:$VER,$REPO:latest,$REPO:sha-$SHA_SHORT" | |
| elif [[ "${{ github.ref }}" == refs/heads/main ]]; then | |
| TAGS="$REPO:main,$REPO:sha-$SHA_SHORT" | |
| elif [[ "${{ github.ref }}" == refs/heads/develop ]] || [[ "${{ github.ref }}" == refs/heads/dev ]]; then | |
| TAGS="$REPO:dev,$REPO:latest,$REPO:sha-$SHA_SHORT" | |
| else | |
| TAGS="$REPO:sha-$SHA_SHORT" | |
| fi | |
| echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
| echo "Tags: $TAGS" | |
| - name: Build RunPod Exporter | |
| run: | | |
| IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" | |
| TAG_ARGS="" | |
| for tag in "${TAG_ARRAY[@]}"; do | |
| TAG_ARGS="$TAG_ARGS -t $tag" | |
| done | |
| docker build \ | |
| $TAG_ARGS \ | |
| --build-arg GIT_COMMIT=${{ github.sha }} \ | |
| --build-arg GIT_BRANCH=${{ github.ref_name }} \ | |
| --build-arg BUILD_TIME="$(date -u '+%Y-%m-%d %H:%M UTC')" \ | |
| ./runpod-exporter | |
| - name: Push RunPod Exporter | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" | |
| for tag in "${TAG_ARRAY[@]}"; do | |
| echo "Pushing $tag..." | |
| docker --config "$DOCKER_CONFIG" push "$tag" | |
| done | |
| - name: Cleanup | |
| if: always() | |
| run: | | |
| docker --config "$DOCKER_CONFIG" logout ${{ env.REGISTRY }} 2>/dev/null || true | |
| rm -rf "$DOCKER_CONFIG" | |
| - name: Summary | |
| run: | | |
| echo "## RunPod Exporter Build Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Tags pushed:" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.tags.outputs.tags }}" | tr ',' '\n' >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| # Build Vast.ai Exporter image | |
| build-vastai-exporter: | |
| runs-on: self-hosted | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| DOCKER_CONFIG: /tmp/docker-config-vastai-${{ github.run_id }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Docker login | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| mkdir -p "$DOCKER_CONFIG" | |
| echo "${{ secrets.CR_PAT || secrets.GITHUB_TOKEN }}" | docker --config "$DOCKER_CONFIG" login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin | |
| - name: Compute tags | |
| id: tags | |
| run: | | |
| REPO="${{ env.REGISTRY }}/cryptolabsza/vastai-exporter" | |
| SHA_SHORT=$(echo "${{ github.sha }}" | head -c 7) | |
| TAGS="" | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| VER="${{ github.ref_name }}" | |
| VER="${VER#v}" | |
| TAGS="$REPO:$VER,$REPO:latest,$REPO:sha-$SHA_SHORT" | |
| elif [[ "${{ github.ref }}" == refs/heads/main ]]; then | |
| TAGS="$REPO:main,$REPO:sha-$SHA_SHORT" | |
| elif [[ "${{ github.ref }}" == refs/heads/develop ]] || [[ "${{ github.ref }}" == refs/heads/dev ]]; then | |
| TAGS="$REPO:dev,$REPO:latest,$REPO:sha-$SHA_SHORT" | |
| else | |
| TAGS="$REPO:sha-$SHA_SHORT" | |
| fi | |
| echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
| echo "Tags: $TAGS" | |
| - name: Build Vast.ai Exporter | |
| run: | | |
| IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" | |
| TAG_ARGS="" | |
| for tag in "${TAG_ARRAY[@]}"; do | |
| TAG_ARGS="$TAG_ARGS -t $tag" | |
| done | |
| docker build \ | |
| $TAG_ARGS \ | |
| --build-arg GIT_COMMIT=${{ github.sha }} \ | |
| --build-arg GIT_BRANCH=${{ github.ref_name }} \ | |
| --build-arg BUILD_TIME="$(date -u '+%Y-%m-%d %H:%M UTC')" \ | |
| ./vastai-exporter | |
| - name: Push Vast.ai Exporter | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" | |
| for tag in "${TAG_ARRAY[@]}"; do | |
| echo "Pushing $tag..." | |
| docker --config "$DOCKER_CONFIG" push "$tag" | |
| done | |
| - name: Cleanup | |
| if: always() | |
| run: | | |
| docker --config "$DOCKER_CONFIG" logout ${{ env.REGISTRY }} 2>/dev/null || true | |
| rm -rf "$DOCKER_CONFIG" | |
| - name: Summary | |
| run: | | |
| echo "## Vast.ai Exporter Build Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Tags pushed:" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.tags.outputs.tags }}" | tr ',' '\n' >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY |