|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 2 | + |
| 3 | +name: Build & Publish Containers |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - next |
| 11 | + - main |
| 12 | + |
| 13 | +env: |
| 14 | + USER: alwatr |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build & Publish Containers |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - name: hybrid-ui-demo-app |
| 26 | + path: ./demo/ |
| 27 | + context: . |
| 28 | + |
| 29 | + permissions: |
| 30 | + contents: read |
| 31 | + packages: write |
| 32 | + id-token: write |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: ⤵️ Checkout repository |
| 36 | + |
| 37 | + |
| 38 | + - name: ❔ Check Container files changed |
| 39 | + id: file_change |
| 40 | + if: ${{ github.event_name != 'release' && github.event_name != 'workflow_dispatch' }} |
| 41 | + |
| 42 | + with: |
| 43 | + filters: | |
| 44 | + container_folder: |
| 45 | + ${{ matrix.context }}/** |
| 46 | +
|
| 47 | + - name: 🏗 Install cosign |
| 48 | + if: ${{ github.event_name != 'pull_request' && steps.file_change.outputs.container_folder != 'false' }} |
| 49 | + |
| 50 | + |
| 51 | + - name: 🏗 Setup Docker Buildx |
| 52 | + if: ${{ steps.file_change.outputs.container_folder != 'false' }} |
| 53 | + |
| 54 | + |
| 55 | + - name: 🏗 Cache Docker Layers |
| 56 | + if: ${{ steps.file_change.outputs.container_folder != 'false' }} |
| 57 | + |
| 58 | + with: |
| 59 | + path: /tmp/.buildx-cache |
| 60 | + key: container/${{ matrix.name }} |
| 61 | + |
| 62 | + # - name: 🏗 Log into docker hub registry |
| 63 | + # if: ${{ github.event_name != 'pull_request' && steps.file_change.outputs.container_folder != 'false' }} |
| 64 | + |
| 65 | + # with: |
| 66 | + # username: ${{env.USER}} |
| 67 | + # password: ${{secrets.DOCKER_HUB_TOKEN}} |
| 68 | + |
| 69 | + - name: 🏗 Log into ghcr.io registry |
| 70 | + if: ${{ github.event_name != 'pull_request' && steps.file_change.outputs.container_folder != 'false' }} |
| 71 | + |
| 72 | + with: |
| 73 | + registry: ghcr.io |
| 74 | + username: ${{env.USER}} |
| 75 | + password: ${{secrets.GITHUB_TOKEN}} |
| 76 | + |
| 77 | + - name: 🏗 Extract metadata |
| 78 | + if: ${{ steps.file_change.outputs.container_folder != 'false' }} |
| 79 | + id: meta |
| 80 | + |
| 81 | + with: |
| 82 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 83 | + images: | |
| 84 | + name=ghcr.io/${{env.USER}}/${{matrix.name}},enable=true |
| 85 | + name=docker.io/${{env.USER}}/${{matrix.name}},enable=false |
| 86 | + tags: | |
| 87 | + type=semver,enable=true,pattern={{major}} |
| 88 | + type=semver,enable=true,pattern={{major}}.{{minor}} |
| 89 | + type=semver,enable=true,pattern={{version}} |
| 90 | + type=ref,enable=true,event=branch |
| 91 | + labels: | |
| 92 | + org.opencontainers.image.title="gecut/${{matrix.name}}" |
| 93 | + org.opencontainers.image.vendor="Gecut" |
| 94 | + org.opencontainers.image.documentation="https://github.com/gecut/hybrid-ui" |
| 95 | + org.opencontainers.image.authors="S. MohammadMahdi Zamanian <[email protected]> (https://mm25zamanian.ir)" |
| 96 | +
|
| 97 | + - name: 🚀 Build and push container image |
| 98 | + if: ${{ steps.file_change.outputs.container_folder != 'false' }} |
| 99 | + id: build_and_push |
| 100 | + |
| 101 | + with: |
| 102 | + context: ${{matrix.context}} |
| 103 | + file: ${{matrix.path}}/Dockerfile |
| 104 | + push: ${{ github.event_name != 'pull_request' }} |
| 105 | + tags: ${{ steps.meta.outputs.tags }} |
| 106 | + labels: ${{ steps.meta.outputs.labels }} |
| 107 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 108 | + cache-to: type=local,dest=/tmp/.buildx-cache |
| 109 | + |
| 110 | + # - name: 🏗 Sign the image with GitHub OIDC Token |
| 111 | + # if: ${{ github.event_name != 'pull_request' && steps.file_change.outputs.container_folder != 'false' }} |
| 112 | + # env: |
| 113 | + # COSIGN_EXPERIMENTAL: 'true' |
| 114 | + # run: echo "${{steps.meta.outputs.tags}}" | xargs -I {} cosign sign --yes {}@${{steps.build_and_push.outputs.digest}} |
0 commit comments