Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 57 additions & 32 deletions .github/workflows/build_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ on:
secrets:
AZURE_CREDENTIALS:
required: true
REGISTRY_LOGIN_SERVER:
required: true
REGISTRY_USERNAME:
required: true
REGISTRY_PASSWORD:
Expand All @@ -22,15 +24,61 @@ on:
required: true

jobs:
build-and-deploy:
get-version:
runs-on: ubuntu-latest
env:
# replaced progamatically if deploying to production
VERSION: dev
outputs:
version: ${{ steps.set-outputs.outputs.VERSION }}
steps:
- name: Update version (production)
if: ${{ inputs.latest }}
run: |
VERSION=`echo ${{ inputs.app-version }} | awk 'BEGIN { FS="."; } { print ""$1"."$2; }'`
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Set outputs
id: set-outputs
run: echo VERSION=$VERSION >> $GITHUB_OUTPUTS

build-and-deploy-ghcr:
runs-on: ubuntu-latest
needs: [get-version]
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4


- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: 'Build and push image (GHCR)'
run: |
# pull latest container, if some steps haven't changed this will speed things up
docker pull ghcr.io/the-strategy-unit/nhp_model:dev
# build and push to GitHub Container Registry
docker build . -t ghcr.io/the-strategy-unit/nhp_model:${{ needs.get-version.outputs.version }} \
--build-arg app_version=${{ inputs.app-version }} \
--build-arg data_version=${{ inputs.data-version }}
docker push ghcr.io/the-strategy-unit/nhp_model:${{ needs.get-version.outputs.version }}

- name: 'Push latest (GHCR)'
if: ${{ inputs.latest }}
run: |
docker tag ghcr.io/the-strategy-unit/nhp_model:${{ needs.get-version.outputs.version }} ghcr.io/the-strategy-unit/nhp_model:latest
docker push ghcr.io/the-strategy-unit/nhp_model:latest

build-and-deploy-acr:
runs-on: ubuntu-latest
needs: [get-version]
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: 'Login via Azure CLI'
uses: azure/login@v2
with:
Expand All @@ -42,42 +90,19 @@ jobs:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Update version (production)
if: ${{ inputs.latest }}
run: |
VERSION=`echo ${{ github.ref_name }} | awk 'BEGIN { FS="."; } { print ""$1"."$2; }'`
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: 'Build and push image'
- name: 'Build and push image (ACR)'
run: |
# pull latest container, if some steps haven't changed this will speed things up
docker pull ghcr.io/the-strategy-unit/nhp_model:latest
# build and push to GitHub Container Registry
docker build . -t ghcr.io/the-strategy-unit/nhp_model:${{ env.VERSION }} \
--build-arg app_version=${{ inputs.app-version }} \
--build-arg data_version=${{ inputs.data-version }}
docker push ghcr.io/the-strategy-unit/nhp_model:${{ env.VERSION }}
# build and dpush to Azure Container Registry (where the app currently run from)
# build and push to Azure Container Registry (where the app currently run from)
# (include the storage account env var for the data)
docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ env.VERSION }} \
docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ needs.get-version.outputs.version }} \
--build-arg app_version=${{ inputs.app-version }} \
--build-arg data_version=${{ inputs.data-version }} \
--build-arg storage_account=${{ secrets.NHP_STORAGE_ACCOUNT }}
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ env.VERSION }}
- name: 'Push latest'
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ needs.get-version.outputs.version }}

- name: 'Push latest (ACR)'
if: ${{ inputs.latest }}
run: |
docker tag ghcr.io/the-strategy-unit/nhp_model:${{ env.VERSION }} ghcr.io/the-strategy-unit/nhp_model:latest
docker push ghcr.io/the-strategy-unit/nhp_model:latest

docker tag ${{ secrets.REGISTRY_LOGIN_SERVER }}:${{ env.VERSION }} ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:latest
docker tag ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:${{ needs.get-version.outputs.version }} ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:latest
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/nhp_model:latest
1 change: 1 addition & 0 deletions .github/workflows/deploy_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
push:
branches:
- main
workflow_dispatch:

name: Deploy Dev

Expand Down
Loading