Skip to content

Build and Deploy

Build and Deploy #610

name: Build and Deploy
on:
push:
branches: [ master, cicd ]
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'test'
type: choice
options:
- 'test'
- 'production'
branch:
description: 'Branch to deploy'
required: true
default: 'master'
jobs:
build:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.image_tag.outputs.tag }}
strategy:
matrix:
service: [
"datastore",
"docs",
"frontend",
"model-manager",
"model-inference-transformer",
"model-inference-onnx",
"model-inference-sentence-transformer",
"model-inference-graph-transformer",
"skill-manager",
"skill-boolq",
"skill-commonsense-qa",
"skill-extractive-qa",
"skill-generative-qa",
"skill-information-retrieval",
"skill-multiple-choice-qa",
"skill-open-extractive-qa",
"skill-qa-gnn",
"skill-tweac",
"skill-metaqa",
"skill-extractive-metaqa",
"skill-multiple-choice-metaqa",
"skill-kgqa-kqapro",
"evaluator",
"sensitivity",
]
include:
- build-args: ""
- service: datastore
context: ./datastore-api
- service: docs
context: ./docs
- service: frontend
context: ./frontend
build-args: "mode=${{ github.event.inputs.environment || 'test' }}"
- service: model-manager
context: ./model-manager
- service: model-inference-transformer
context: ./model-inference
build-args: "MODEL_TYPE=transformer"
- service: model-inference-onnx
context: ./model-inference
build-args: "MODEL_TYPE=onnx"
- service: model-inference-sentence-transformer
context: ./model-inference
build-args: "MODEL_TYPE=sentence_transformer"
- service: model-inference-graph-transformer
context: ./model-inference
build-args: "MODEL_TYPE=graph_transformer"
- service: skill-manager
context: ./skill-manager
- service: skill-boolq
context: ./skills
build-args: "skill=boolq"
- service: skill-commonsense-qa
context: ./skills
build-args: "skill=commonsense-qa"
- service: skill-extractive-qa
context: ./skills
build-args: "skill=extractive-qa"
- service: skill-generative-qa
context: ./skills
build-args: "skill=generative-qa"
- service: skill-information-retrieval
context: ./skills
build-args: "skill=information-retrieval"
- service: skill-multiple-choice-qa
context: ./skills
build-args: "skill=multiple-choice-qa"
- service: skill-open-extractive-qa
context: ./skills
build-args: "skill=open-extractive-qa"
- service: skill-qa-gnn
context: ./skills
build-args: "skill=qa-gnn"
- service: skill-tweac
context: ./skills
build-args: "skill=tweac"
- service: skill-extractive-metaqa
context: ./skills
build-args: "skill=extractive-metaqa"
- service: skill-multiple-choice-metaqa
context: ./skills
build-args: "skill=multiple-choice-metaqa"
- service: skill-metaqa
context: ./skills
build-args: "skill=metaqa"
- service: "skill-kgqa-kqapro"
context: ./skills
build-args: "skill=kgqa-kqapro"
- service: evaluator
context: ./evaluator
- service: sensitivity
context: ./sensitivity
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.service }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.service }}-
${{ runner.os }}-buildx-
- name: Set Image Tag
id: image_tag
run: |
SHORT_SHA=$(git rev-parse --short ${{ github.sha }})
echo $SHORT_SHA
TAG="${{ github.event.inputs.environment || 'build' }}-$SHORT_SHA"
echo $TAG
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Add latest tag if deploying to prod
uses: haya14busa/action-cond@v1
id: latest_tag_str
with:
cond: ${{ github.event.inputs.environment == 'production' }}
if_true: "ukpsquare/${{matrix.service}}:latest"
if_false: ""
- name: Build deployable image
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: ${{ matrix.context }}
file: ${{ matrix.file }}
target: build
build-args: ${{ matrix.build-args }}
push: ${{ github.event.inputs.environment == 'production' || github.event.inputs.environment == 'test' }}
tags: |
ukpsquare/${{ matrix.service }}:${{ steps.image_tag.outputs.tag }}
${{ steps.latest_tag_str.outputs.value }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
deploy:
needs: build
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
steps:
- name: Trigger Deployment on ${{ github.event.inputs.environment }}
uses: distributhor/workflow-webhook@v2
env:
webhook_url: ${{ secrets.WEBHOOK_URL }}
webhook_secret: ${{ secrets.WEBHOOK_SECRET }}
data: '{"environment": "${{ github.event.inputs.environment }}", "branch": "${{ github.event.inputs.branch }}", "tag": "${{ needs.build.outputs.tag }}"}'
verify_ssl: false