|
28 | 28 | docker-publish: |
29 | 29 | runs-on: ubuntu-latest |
30 | 30 | needs: docker-test |
31 | | - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/stable' }} |
| 31 | + if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/stable' || github.ref == 'refs/heads/dev') }} |
32 | 32 |
|
33 | 33 | steps: |
34 | 34 | - name: Checkout code |
@@ -61,39 +61,46 @@ jobs: |
61 | 61 | images: blacklanternsecurity/bbot-server |
62 | 62 | tags: | |
63 | 63 | type=ref,event=branch |
64 | | - type=ref,event=pr |
65 | 64 | type=sha,prefix=sha- |
66 | | - type=raw,value=latest,enable={{is_default_branch}} |
67 | | - type=raw,value=v${{ steps.version.outputs.major }} |
68 | | - type=raw,value=v${{ steps.version.outputs.minor }} |
69 | | - type=raw,value=v${{ steps.version.outputs.version }} |
| 65 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/stable' }} |
| 66 | + type=raw,value=v${{ steps.version.outputs.major }},enable=${{ github.ref == 'refs/heads/stable' }} |
| 67 | + type=raw,value=v${{ steps.version.outputs.minor }},enable=${{ github.ref == 'refs/heads/stable' }} |
| 68 | + type=raw,value=v${{ steps.version.outputs.version }},enable=${{ github.ref == 'refs/heads/stable' }} |
70 | 69 |
|
71 | 70 | - name: Build and push Docker image |
72 | 71 | uses: docker/build-push-action@v6 |
73 | 72 | with: |
| 73 | + context: . |
74 | 74 | push: true |
75 | 75 | tags: ${{ steps.meta.outputs.tags }} |
76 | 76 | labels: ${{ steps.meta.outputs.labels }} |
77 | 77 | cache-from: type=gha |
78 | 78 | cache-to: type=gha,mode=max |
79 | 79 |
|
80 | | - - name: Clean up old Docker Hub tags (up to 50 most recent tags plus 'latest') |
| 80 | + - name: Clean up old Docker Hub tags (keep 50 most recent plus protected tags) |
81 | 81 | run: | |
82 | 82 | # Install jq for JSON processing |
83 | 83 | sudo apt-get update && sudo apt-get install -y jq |
84 | 84 |
|
85 | 85 | echo "Cleaning up bbot-server tags..." |
86 | 86 |
|
| 87 | + # Protected tags that should never be deleted |
| 88 | + PROTECTED="latest stable dev v${{ steps.version.outputs.major }} v${{ steps.version.outputs.minor }} v${{ steps.version.outputs.version }}" |
| 89 | +
|
87 | 90 | tags_response=$(curl -s -H "Authorization: Bearer ${{ secrets.DOCKER_TOKEN }}" \ |
88 | | - "https://hub.docker.com/v2/repositories/bbot-server}/tags/?page_size=100") |
| 91 | + "https://hub.docker.com/v2/repositories/blacklanternsecurity/bbot-server/tags/?page_size=100") |
89 | 92 |
|
90 | | - tags_to_delete=$(echo "$tags_response" | jq -r '.results[] | select(.name != "latest") | [.last_updated, .name] | @tsv' | \ |
91 | | - sort -r | tail -n +51 | cut -f2) |
| 93 | + tags_to_delete=$(echo "$tags_response" | jq -r '.results[].name' | sort -r | tail -n +51) |
92 | 94 |
|
93 | 95 | for tag in $tags_to_delete; do |
| 96 | + # Skip protected tags |
| 97 | + if echo "$PROTECTED" | grep -qw "$tag"; then |
| 98 | + echo "Skipping protected tag: $tag" |
| 99 | + continue |
| 100 | + fi |
94 | 101 | echo "Deleting bbot-server tag: $tag" |
95 | 102 | curl -X DELETE -H "Authorization: Bearer ${{ secrets.DOCKER_TOKEN }}" \ |
96 | | - "https://hub.docker.com/v2/repositories/bbot-server/tags/$tag/" |
| 103 | + "https://hub.docker.com/v2/repositories/blacklanternsecurity/bbot-server/tags/$tag/" |
97 | 104 | done |
98 | 105 |
|
99 | | - echo "Cleanup completed for bbot-server. Kept 50 most recent tags plus 'latest'." |
| 106 | + echo "Cleanup completed for bbot-server." |
0 commit comments