3030 required : true
3131
3232jobs :
33- build-and-deploy-ghcr :
33+
34+ build-container :
3435 runs-on : ubuntu-latest
36+ steps :
37+ - name : " Checkout GitHub Action"
38+ uses : actions/checkout@v4
39+
40+ - name : " Login to GitHub Container Registry"
41+ uses : docker/login-action@v3
42+ with :
43+ registry : ghcr.io
44+ username : ${{github.actor}}
45+ password : ${{secrets.GITHUB_TOKEN}}
46+
47+ - name : Set up Docker Buildx
48+ uses : docker/setup-buildx-action@v3
49+
50+ - name : " Build image"
51+ uses : docker/build-push-action@v6
52+ with :
53+ context : .
54+ tags : ghcr.io/the-strategy-unit/nhp_model:pr-${{ github.event.number }}
55+ push : true
56+ cache-from : type=gha
57+ cache-to : type=gha,mode=max
58+ build-args : |
59+ app_version=${{ inputs.app-version }}
60+ data_version=${{ inputs.data-version }}
61+
62+ add-comment-to-pr :
63+ runs-on : ubuntu-latest
64+ if : github.event_name == 'pull_request'
65+ needs : ["build-container"]
66+ steps :
67+ - name : Find Comment
68+ uses : peter-evans/find-comment@v3
69+ id : fc
70+ with :
71+ issue-number : ${{ github.event.pull_request.number }}
72+ comment-author : ' github-actions[bot]'
73+ body-includes : " ## ✅ A new build is available"
74+
75+ - name : Comment with container image link
76+ if : github.event_name == 'pull_request'
77+ uses : peter-evans/create-or-update-comment@v4
78+ with :
79+ token : ${{ secrets.GITHUB_TOKEN }}
80+ comment-id : ${{ steps.fc.outputs.comment-id }}
81+ issue-number : ${{ github.event.pull_request.number }}
82+ body : |
83+ ## ✅ A new build is available.
84+
85+ You can use the following to use pull the image into your local environment:
86+
87+ ``` bash
88+ docker pull ghcr.io/the-strategy-unit/nhp_model:pr-${{ github.event.number }}
89+ ```
90+
91+ [Download Artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
92+ edit-mode : replace
93+
94+ deploy-ghcr :
95+ runs-on : ubuntu-latest
96+ if : github.event_name != 'pull_request'
97+ needs : ["build-container"]
3598 steps :
3699 - name : ' Checkout GitHub Action'
37100 uses : actions/checkout@v4
@@ -42,29 +105,30 @@ jobs:
42105 registry : ghcr.io
43106 username : ${{github.actor}}
44107 password : ${{secrets.GITHUB_TOKEN}}
108+ - name : Set up Docker Buildx
109+ uses : docker/setup-buildx-action@v3
45110
46- - name : ' Pull latest dev container'
47- run : |
48- docker pull ghcr.io/the-strategy-unit/nhp_model:dev
49-
50- - name : ' Build image'
51- run : |
52- docker build . -t ghcr.io/the-strategy-unit/nhp_model:${{ inputs.docker-tag }} \
53- --build-arg app_version=${{ inputs.app-version }} \
54- --build-arg data_version=${{ inputs.data-version }}
55-
56- - name : ' Push image'
57- run : |
58- docker push ghcr.io/the-strategy-unit/nhp_model:${{ inputs.docker-tag }}
111+ - name : " Build image"
112+ uses : docker/build-push-action@v6
113+ with :
114+ context : .
115+ tags : ghcr.io/the-strategy-unit/nhp_model:${{ inputs.docker-tag }}
116+ push : true
117+ cache-from : type=gha
118+ build-args : |
119+ app_version=${{ inputs.app-version }}
120+ data_version=${{ inputs.data-version }}
59121
60122 - name : ' Push latest'
61123 if : ${{ inputs.latest }}
62124 run : |
63125 docker tag ghcr.io/the-strategy-unit/nhp_model:${{ inputs.docker-tag }} ghcr.io/the-strategy-unit/nhp_model:latest
64126 docker push ghcr.io/the-strategy-unit/nhp_model:latest
65127
66- build-and- deploy-acr :
128+ deploy-acr :
67129 runs-on : ubuntu-latest
130+ if : github.event_name != 'pull_request'
131+ needs : ["build-container"]
68132 steps :
69133 - name : ' Checkout GitHub Action'
70134 uses : actions/checkout@v4
@@ -81,22 +145,20 @@ jobs:
81145 username : ${{ secrets.REGISTRY_USERNAME }}
82146 password : ${{ secrets.REGISTRY_PASSWORD }}
83147
84- - name : ' Pull latest dev container'
85- run : |
86- docker pull ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:dev
87-
88- - name : ' Build and push image'
89- run : |
90- # include the storage account env var for the data for acr
91- docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ inputs.docker-tag }} \
92- --build-arg app_version=${{ inputs.app-version }} \
93- --build-arg data_version=${{ inputs.data-version }} \
94- --build-arg storage_account=${{ secrets.NHP_STORAGE_ACCOUNT }}
95-
96- - name : ' Push image'
97- run : |
98- docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ inputs.docker-tag }}
148+ - name : Set up Docker Buildx
149+ uses : docker/setup-buildx-action@v3
99150
151+ - name : " Build image"
152+ uses : docker/build-push-action@v6
153+ with :
154+ context : .
155+ tags : ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ inputs.docker-tag }}
156+ push : true
157+ cache-from : type=gha
158+ build-args : |
159+ app_version=${{ inputs.app-version }}
160+ data_version=${{ inputs.data-version }}
161+ storage_account=${{ secrets.NHP_STORAGE_ACCOUNT }}
100162 - name : ' Push latest'
101163 if : ${{ inputs.latest }}
102164 run : |
0 commit comments