Skip to content

Commit 4b21ec5

Browse files
authored
Build and push docker images in Parallel
1. Add a new actions that builds and pushes images in parallel 2. Disable other actions on push and run only on workflow dispatch (Samagra-Development#257)
1 parent a9f8ca9 commit 4b21ec5

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

.github/workflows/build-and-push.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
name: Build and Push Docker Image
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- restructure
4+
workflow_dispatch:
85

96
env:
107
DOCKER_USERNAME: ${{ github.actor }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+

.github/workflows/gh-packages.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Push Docker Images
22

33
on:
4-
push:
5-
branches: ['restructure', 'main']
4+
workflow_dispatch:
65

76
env:
87
REGISTRY: ghcr.io

0 commit comments

Comments
 (0)