Dev Docker Build #4
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: Dev Docker Build | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: "Branch to build from (defaults to main)" | |
| required: false | |
| type: string | |
| default: "main" | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| CARGO_INCREMENTAL: 0 | |
| jobs: | |
| docker: | |
| name: "Build and push ${{ inputs.branch }}" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.branch }} | |
| - name: Generate image tag | |
| id: tag | |
| run: | | |
| BRANCH="${{ inputs.branch }}" | |
| # Sanitize branch name: replace any non-alphanumeric chars with - | |
| SAFE_BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-\|-$//g') | |
| TIMESTAMP=$(date -u +%Y%m%d%H%M%S) | |
| echo "value=${SAFE_BRANCH}-test-img-${TIMESTAMP}" >> $GITHUB_OUTPUT | |
| - name: Free up disk space | |
| run: | | |
| sudo rm -rf /usr/share/dotnet | |
| sudo rm -rf /opt/ghc | |
| sudo rm -rf /usr/local/share/boost | |
| sudo rm -rf "$AGENT_TOOLSDIRECTORY" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64 | |
| provenance: false | |
| tags: ghcr.io/skardilabs/skardi/skardi-server:${{ steps.tag.outputs.value }} | |
| cache-from: type=gha,scope=dev-${{ inputs.branch }} | |
| cache-to: type=gha,mode=max,scope=dev-${{ inputs.branch }} | |
| - name: Summary | |
| run: | | |
| echo "### Docker image published" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "docker pull ghcr.io/skardilabs/skardi/skardi-server:${{ steps.tag.outputs.value }}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |