|
| 1 | +name: Build Mock Login Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - master |
| 12 | + workflow_dispatch: # Manually triggered |
| 13 | + |
| 14 | +env: |
| 15 | + CONTAINER_REGISTRY: ghcr.io |
| 16 | + IMAGE_NAME: mock-login |
| 17 | + BRANCH_NAME: ${{ github.head_ref || github.ref }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: 📦 Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: 🧰 Get branch name |
| 31 | + run: | # Get the branch name from the ref and replace non-alphanumeric characters with hyphens |
| 32 | + BRANCH=$(echo "${BRANCH_NAME#refs/heads/}" | sed -e 's/[^a-zA-Z0-9]/-/g') |
| 33 | + echo "BRANCH=$BRANCH" >> $GITHUB_ENV |
| 34 | +
|
| 35 | + - name: 🏷️ Generate Docker metadata |
| 36 | + id: meta |
| 37 | + uses: docker/metadata-action@v5 |
| 38 | + with: |
| 39 | + images: | |
| 40 | + ${{ env.CONTAINER_REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} |
| 41 | + tags: | |
| 42 | + type=ref,event=branch,priority=610 |
| 43 | + type=ref,event=pr |
| 44 | + type=semver,pattern={{raw}} |
| 45 | + type=semver,pattern={{version}} |
| 46 | + type=semver,pattern={{major}}.{{minor}} |
| 47 | + type=semver,pattern={{major}} |
| 48 | + type=semver,pattern=v{{major}} |
| 49 | + type=sha,format=long |
| 50 | + type=raw,value=latest,enable={{is_default_branch}} |
| 51 | + type=raw,value=${{ env.BRANCH_NAME }},priority=10 |
| 52 | + annotations: | |
| 53 | + runnumber=${{ github.run_id }} |
| 54 | + sha=${{ github.sha }} |
| 55 | + ref=${{ github.ref }} |
| 56 | +
|
| 57 | + - name: 🔐 Log in to GitHub Container Registry |
| 58 | + uses: docker/login-action@v3 |
| 59 | + with: |
| 60 | + registry: ${{ env.CONTAINER_REGISTRY }} |
| 61 | + username: ${{ github.repository_owner }} |
| 62 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + |
| 64 | + - name: 🛠️ Set up Docker Buildx |
| 65 | + uses: docker/setup-buildx-action@v3 |
| 66 | + |
| 67 | + - name: 🚀 Build and push image |
| 68 | + uses: docker/build-push-action@v6 |
| 69 | + with: |
| 70 | + context: . |
| 71 | + file: Dockerfile |
| 72 | + push: true |
| 73 | + tags: ${{ steps.meta.outputs.tags }} |
| 74 | + labels: ${{ steps.meta.outputs.labels }} |
| 75 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 76 | + cache-from: type=gha |
| 77 | + cache-to: type=gha,mode=max |
0 commit comments