|
| 1 | +name: Docker Build and Push |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-push: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Docker Buildx |
| 17 | + uses: docker/setup-buildx-action@v3 |
| 18 | + |
| 19 | + - name: Log in to Docker Hub |
| 20 | + uses: docker/login-action@v3 |
| 21 | + with: |
| 22 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 23 | + password: ${{ secrets.DOCKER_HUB_TOKEN }} |
| 24 | + |
| 25 | + - name: Get short commit SHA |
| 26 | + id: commit |
| 27 | + run: echo "SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT |
| 28 | + |
| 29 | + - name: Extract metadata |
| 30 | + id: meta |
| 31 | + uses: docker/metadata-action@v5 |
| 32 | + with: |
| 33 | + images: ${{ secrets.DOCKER_HUB_USERNAME }}/faucet |
| 34 | + tags: | |
| 35 | + type=raw,value=latest |
| 36 | + type=raw,value=latest-${{ steps.commit.outputs.SHORT_SHA }} |
| 37 | + |
| 38 | + - name: Build and push Docker image |
| 39 | + uses: docker/build-push-action@v5 |
| 40 | + with: |
| 41 | + context: . |
| 42 | + push: true |
| 43 | + tags: ${{ steps.meta.outputs.tags }} |
| 44 | + cache-from: type=registry,image=${{ secrets.DOCKER_HUB_USERNAME }}/faucet:latest |
| 45 | + cache-to: type=inline |
| 46 | + |
| 47 | + - name: Display Docker image tags |
| 48 | + run: | |
| 49 | + echo "==========================================" |
| 50 | + echo "✅ Docker image built and pushed successfully!" |
| 51 | + echo "==========================================" |
| 52 | + echo "" |
| 53 | + echo "📦 Image: ${{ secrets.DOCKER_HUB_USERNAME }}/faucet" |
| 54 | + echo "" |
| 55 | + echo "🏷️ Available tags:" |
| 56 | + echo " • latest" |
| 57 | + echo " • latest-${{ steps.commit.outputs.SHORT_SHA }}" |
| 58 | + echo "" |
| 59 | + echo "📋 Pull commands:" |
| 60 | + echo " docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/faucet:latest" |
| 61 | + echo " docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/faucet:latest-${{ steps.commit.outputs.SHORT_SHA }}" |
| 62 | + echo "" |
| 63 | + echo "🔗 Commit: ${{ github.sha }}" |
| 64 | + echo " Short SHA: ${{ steps.commit.outputs.SHORT_SHA }}" |
| 65 | + echo "==========================================" |
0 commit comments