|
| 1 | +name: Build and Push (Parallel) |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: ['restructure', 'main'] |
| 5 | + |
| 6 | +env: |
| 7 | + REGISTRY: ghcr.io |
| 8 | + |
| 9 | +jobs: |
| 10 | + generate-job-strategy-matrix: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + job-strategy-matrix: ${{ steps.generate.outputs.job-strategy-matrix }} |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + fetch-depth: 2 |
| 19 | + |
| 20 | + - name: Log in to the Container registry |
| 21 | + id: login |
| 22 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 23 | + with: |
| 24 | + registry: ghcr.io |
| 25 | + username: ${{ github.actor }} |
| 26 | + password: ${{ secrets.PAT }} |
| 27 | + |
| 28 | + - id: generate |
| 29 | + run: | |
| 30 | + COUNT_MODELS=$(jq '.models | length' config.json) |
| 31 | + JOB_STRATEGY_MATRIX=$(node -e "let r=[]; for(let i = 1; i <= $COUNT_MODELS; i++) { r.push(i) }; console.log(JSON.stringify(r));") |
| 32 | + |
| 33 | + echo "job-strategy-matrix=$JOB_STRATEGY_MATRIX" >> $GITHUB_OUTPUT |
| 34 | + build-and-push-image: |
| 35 | + needs: generate-job-strategy-matrix |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + contents: read |
| 39 | + packages: write |
| 40 | + timeout-minutes: 60 # 1 hour timeout |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + job: ${{ fromJson(needs.generate-job-strategy-matrix.outputs.job-strategy-matrix) }} |
| 44 | + max-parallel: 50 |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v3 |
| 48 | + with: |
| 49 | + fetch-depth: 2 |
| 50 | + |
| 51 | + - name: Log in to the Container registry |
| 52 | + id: login |
| 53 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 54 | + with: |
| 55 | + registry: ${{ env.REGISTRY }} |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.PAT }} |
| 58 | + |
| 59 | + - name: Build and push docker images |
| 60 | + run: | |
| 61 | + image_names=$(jq -r '.models[].serviceName' ./config.json) |
| 62 | + paths=$(jq -r '.models[].modelBasePath' ./config.json) |
| 63 | + readarray -t image_array <<< "$image_names" |
| 64 | + readarray -t paths_array <<< "$paths" |
| 65 | + lowercase_actor=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') |
| 66 | + job=${{ matrix.job }} |
| 67 | + image="${image_array[job-1]}" |
| 68 | + path="${paths_array[job-1]}" |
| 69 | + docker build "./$path" -t "${{ env.REGISTRY }}/$lowercase_actor/$image:latest" |
| 70 | + docker push "${{ env.REGISTRY }}/$lowercase_actor/$image:latest" |
| 71 | + |
| 72 | + |
| 73 | + |
0 commit comments