Create & Publish jetthoughts/cimg-ruby to DockerHub & GitHubCR #221
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: Create & Publish jetthoughts/cimg-ruby to DockerHub & GitHubCR | |
| # This workflow builds and publishes the cimg-ruby Docker image to DockerHub and GitHub Container Registry. | |
| # It runs on PRs, pushes to specific branches, manual triggers, and on a schedule. | |
| on: | |
| pull_request: | |
| paths: | |
| - 'cimg-ruby/**' | |
| workflow_dispatch: | |
| push: | |
| paths: | |
| - 'cimg-ruby/**' | |
| branches: | |
| - master | |
| - support-more-rubies | |
| schedule: | |
| - cron: "0 0 */5 * *" | |
| env: | |
| IMAGE_NAME: jetthoughts/cimg-ruby | |
| jobs: | |
| build-and-push-image: | |
| timeout-minutes: 30 # Prevent jobs from running indefinitely | |
| strategy: | |
| fail-fast: false # Allow all matrix jobs to complete even if one fails | |
| matrix: | |
| version: [ "3.4", "3.3", "3.2" ] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Ensure DockerHub credentials are present | |
| - name: Check DockerHub credentials | |
| run: | | |
| if [ -z "${{ secrets.DOCKERHUB_USERNAME }}" ] || [ -z "${{ secrets.DOCKERHUB_TOKEN }}" ]; then | |
| echo "DockerHub credentials are missing!" | |
| exit 1 | |
| fi | |
| shell: bash | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./cimg-ruby/ | |
| build-args: RUBY_VERSION=${{ matrix.version }} | |
| push: true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| labels: ${{ steps.meta.outputs.labels }} | |
| tags: | | |
| ${{ env.IMAGE_NAME }}:${{ matrix.version }}-chrome | |
| ghcr.io/${{ env.IMAGE_NAME }}:${{ matrix.version }}-chrome | |
| # Optional: Verify image exists after push | |
| - name: Verify Docker image | |
| run: | | |
| docker pull ${{ env.IMAGE_NAME }}:${{ matrix.version }}-chrome | |
| shell: bash | |
| # Security: Logout from registries | |
| - name: Logout from DockerHub | |
| run: docker logout | |
| shell: bash | |
| - name: Logout from GitHub Container Registry | |
| run: docker logout ghcr.io | |
| shell: bash | |