|
8 | 8 |
|
9 | 9 | env: |
10 | 10 | # GHCR image name: ghcr.io/owner/repo-name |
11 | | - IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/simple-rag |
| 11 | + # We use a specific env variable to ensure the name is lowercase |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
12 | 14 |
|
13 | 15 | jobs: |
14 | 16 | build-and-push: |
15 | 17 | runs-on: ubuntu-latest |
16 | 18 | permissions: |
17 | 19 | contents: read |
18 | | - packages: write # Required for pushing to GHCR |
| 20 | + packages: write |
19 | 21 | steps: |
20 | 22 | - name: Check out the repo |
21 | 23 | uses: actions/checkout@v4 |
22 | 24 |
|
23 | 25 | - name: Log in to GitHub Container Registry |
24 | 26 | uses: docker/login-action@v3 |
25 | 27 | with: |
26 | | - registry: ghcr.io |
| 28 | + registry: ${{ env.REGISTRY }} |
27 | 29 | username: ${{ github.actor }} |
28 | 30 | password: ${{ secrets.GITHUB_TOKEN }} |
29 | 31 |
|
| 32 | + - name: Extract metadata (tags, labels) for Docker |
| 33 | + id: meta |
| 34 | + uses: docker/metadata-action@v5 |
| 35 | + with: |
| 36 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 37 | + tags: | |
| 38 | + type=raw,value=latest |
| 39 | + type=sha |
| 40 | +
|
30 | 41 | - name: Build and push Docker image |
31 | 42 | uses: docker/build-push-action@v5 |
32 | 43 | with: |
33 | 44 | context: . |
34 | 45 | push: ${{ github.event_name != 'pull_request' }} |
35 | | - tags: | |
36 | | - ${{ env.IMAGE_NAME }}:latest |
37 | | - ${{ env.IMAGE_NAME }}:${{ github.sha }} |
38 | | - # Ensure image is lowered for GHCR if repository name contains uppercase |
39 | | - labels: | |
40 | | - org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 46 | + tags: ${{ steps.meta.outputs.tags }} |
| 47 | + labels: ${{ steps.meta.outputs.labels }} |
41 | 48 |
|
42 | 49 | # Optional job to automatically update kubernetes deployment. |
43 | 50 | # This requires a kubernetes cluster setup and kubeconfig secret. |
|
0 commit comments