Skip to content

Build and deploy

Build and deploy #11

name: Build and deploy
on:
workflow_run:
workflows: ["test"]
types:
- completed
jobs:
build-and-push:
name: Build and push from ${{ github.ref_name }}/${{ github.sha }}
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
env:
CPU_IMAGE_NAME: ghcr.io/${{ github.repository }}/cpu
CUDA_IMAGE_NAME: ghcr.io/${{ github.repository }}/cuda
IMAGE_TAG: ${{ github.sha }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push cpu
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.cpu
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.CPU_IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.CPU_IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.CPU_IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.CPU_IMAGE_NAME }}:buildcache,mode=max
- name: Build and push cuda
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.cuda
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.CUDA_IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.CUDA_IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.CUDA_IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.CUDA_IMAGE_NAME }}:buildcache,mode=max
deploy-prod:
name: Deploy from ${{ github.ref_name }}/${{ github.sha }}
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Trigger prod deployment
run: |
RESPONSE="$(curl --request POST \
--form token=${{ secrets.GITLAB_CI_TOKEN }} \
--form ref=main \
--form 'variables[pipeline_name]=${{ github.event.repository.name }} - ${{ github.event.head_commit.message }}' \
--form 'variables[docker_image_tag]=latest' \
--form 'variables[application_to_deploy]=models' \
--form 'variables[deployment_environment]=prod' \
'https://gitlab.com/api/v4/projects/58117805/trigger/pipeline')"
if echo "$RESPONSE" | grep -q '"status":"created"'; then
echo $RESPONSE
else
echo $RESPONSE
exit 1
fi