Skip to content

[Adhoc] Migrate d2e-base to d2e-plugins #176

[Adhoc] Migrate d2e-base to d2e-plugins

[Adhoc] Migrate d2e-base to d2e-plugins #176

name: Docker Build
on:
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
push:
branches:
- main
- trex
jobs:
bld:
runs-on: ubuntu-latest
env:
AZ_REG_FQDN: ${{ vars.AZ_REGISTRY_NAME }}.azurecr.io
AZ_REG_NAME: ${{ vars.AZ_REGISTRY_NAME }}
AZ_REG_PASSWORD: ${{ secrets.AZ_REGISTRY_PASSWORD }}
AZ_REG_PRUNE_DAYS: ${{ vars.AZ_REG_PRUNE_DAYS || '20' }}
AZ_REG_PRUNE_ENABLE_DELETE: ${{ vars.AZ_REG_PRUNE_ENABLE_DELETE || 'false' }}
AZ_REG_PRUNE_FORCE_ANALYZE: ${{ vars.AZ_REG_PRUNE_FORCE_ANALYZE || 'false' }}
AZ_REG_PRUNE_KEEP_REGEX: ${{ vars.AZ_REG_PRUNE_KEEP_REGEX }}
AZ_REG_USERNAME: ${{ vars.AZ_REGISTRY_USERNAME }}
DOCKER_BUILD_DISABLE: ${{ vars.DOCKER_BUILD_DISABLE || 'false' }}
DOCKER_BUILD_PUSH_BOOL_OVERRIDE: ${{ vars.DOCKER_BUILD_PUSH_BOOL_OVERRIDE || 'false' }}
GIT_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
strategy:
fail-fast: false
matrix:
include:
- AZ_REG_REPOSITORY: d2e-flow/base
DOCKER_BUILD_CONTEXT_PATH: .
DOCKER_BUILD_FILE_PATH: Dockerfile
- AZ_REG_REPOSITORY: d2e-flow/nlp
DOCKER_BUILD_CONTEXT_PATH: .
DOCKER_BUILD_FILE_PATH: Dockerfile_NLP
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: true
swap-storage: true
- name: Check out repository code
uses: actions/checkout@v4
- name: Setting up variables
id: setup
env:
DOCKER_BUILD_PUSH_BOOL_OVERRIDE: ${{ vars.DOCKER_BUILD_PUSH_BOOL_OVERRIDE || false }}
run: |
GITHUB_SHA_SHORT=$(git rev-parse --short HEAD)
DOCKER_IMG_TAG_NAME=$GITHUB_SHA_SHORT
DOCKER_BUILD_PUSH_BOOL_STR=false
if [[ $GITHUB_EVENT_NAME == "push" ]] || [ $GITHUB_EVENT_NAME = "workflow_dispatch" ] || [ $DOCKER_BUILD_PUSH_BOOL_OVERRIDE = true]; then
DOCKER_BUILD_PUSH_BOOL_STR=true
fi
echo DOCKER_BUILD_PUSH_BOOL_STR=$DOCKER_BUILD_PUSH_BOOL_STR | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
echo DOCKER_IMG_TAG_NAME=$DOCKER_IMG_TAG_NAME | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
echo GIT_BRANCH_NAME="${GIT_BRANCH_NAME}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
echo AZ_REG_REPOSITORY=${{ matrix.AZ_REG_REPOSITORY }} | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
echo DOCKER_BUILD_CONTEXT_PATH=${{ matrix.DOCKER_BUILD_CONTEXT_PATH }} | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
echo DOCKER_BUILD_FILE_PATH=${{ matrix.DOCKER_BUILD_FILE_PATH }} | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
echo GITHUB_SHA=$GITHUB_SHA | tee -a $GITHUB_STEP_SUMMARY
echo GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
- name: Login to ACR
uses: docker/login-action@v3
with:
registry: ${{ env.AZ_REG_FQDN }}
username: ${{ env.AZ_REG_USERNAME }}
password: ${{ env.AZ_REG_PASSWORD }}
- name: Build and Push
id: build-push
if: env.DOCKER_BUILD_DISABLE == 'false'
uses: docker/build-push-action@v6
with:
context: ${{ env.DOCKER_BUILD_CONTEXT_PATH }}
file: ${{ env.DOCKER_BUILD_FILE_PATH }}
platforms: "linux/amd64"
push: ${{ env.DOCKER_BUILD_PUSH_BOOL_STR == 'true' }}
tags: ${{ env.AZ_REG_FQDN }}/${{ env.AZ_REG_REPOSITORY }}:${{ env.DOCKER_IMG_TAG_NAME }}, ${{ env.AZ_REG_FQDN }}/${{ env.AZ_REG_REPOSITORY }}:main
- name: Prune ACR Images created before vars.AZ_REG_PRUNE_DAYS_TAGGED
if: env.AZ_REG_PRUNE_FORCE_ANALYZE == 'true' || env.GIT_BRANCH_NAME == 'develop'
id: prune
continue-on-error: true
run: |
npx --suppess-warnings zx scripts/analyze-acr.mjs
if [ $AZ_REG_PRUNE_ENABLE_DELETE = true ]; then
echo "INFO . manifests delete ..."
sh "private-acr-manifests-delete.sh"
else
echo "INFO . manifests delete skipped"
fi
echo AZ_REG_ARTIFACTS_NAME=${AZ_REG_REPOSITORY/\//--} | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT | tee -a $GITHUB_STEP_SUMMARY
- name: Upload ACR manifests artifacts
if: steps.prune.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: ${{ env.AZ_REG_ARTIFACTS_NAME }}
retention-days: 30
path: |
private*manifests*