Refactored CICD to support multiplatform #29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push to Docker Hub | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
shared_steps: # Job for shared steps | ||
name: Prepare for Docker builds | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
- name: Upload repository as artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: repository | ||
path: . # Upload the entire current directory | ||
build_and_push_images: # Job for building and pushing the images | ||
name: Build and Push Images | ||
runs-on: ubuntu-latest | ||
needs: shared_steps # Dependency on the shared steps | ||
strategy: | ||
matrix: | ||
image: [ | ||
{ name: web-ui, context: ./services/web-ui, file: ./services/web-ui/Dockerfile }, | ||
{ name: training-service, context: ./services/training-service, file: ./services/training-service/Dockerfile }, | ||
{ name: data-producer, context: ./services/data-producer, file: ./services/data-producer/Dockerfile }, | ||
{ name: mlflow, context: ./services/mlflow, file: ./services/mlflow/Dockerfile }, | ||
{ name: airflow-spark, context: ./services/airflow, file: ./services/airflow/Dockerfile }, | ||
{ name: forecast-service, context: ./services/forecast-service, file: ./services/forecast-service/Dockerfile } | ||
] | ||
steps: | ||
- name: Download repository artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: repository | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Extract metadata (tags, labels) for ${{ matrix.image.name }} Docker | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ariya23156/sfmlops-${{ matrix.image.name }} | ||
- name: Build and push ${{ matrix.image.name }} Docker image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ${{ matrix.image.context }} | ||
file: ${{ matrix.image.file }} | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ariya23156/sfmlops-${{ matrix.image.name }}:latest | ||
labels: ${{ steps.meta.outputs.labels }} | ||
# Hardcoded all build-args here, couldn't find a proper way | ||
# to put this into matrix | ||
## for amd64 (x86_64) please leave ARCH_TRAILING_IMG_NAME empty like | ||
## ARCH_TRAILING_IMG_NAME= | ||
build-args: | | ||
AIRFLOW_HOME=/opt/airflow | ||
MLFLOW_ARTIFACT_ROOT=/storage/mlruns | ||
build_and_push_ray_images_only: # Job for building and pushing the images | ||
name: Build and Push Ray Images | ||
runs-on: ubuntu-latest | ||
needs: shared_steps # Dependency on the shared steps | ||
strategy: | ||
matrix: | ||
image: [ | ||
{ name: ray, context: ./services/ray, file: ./services/ray/Dockerfile, platform: linux/arm64 }, | ||
{ name: ray, context: ./services/ray, file: ./services/ray/Dockerfile, platform: linux/amd64 } | ||
] | ||
steps: | ||
- name: Download repository artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: repository | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Extract metadata (tags, labels) for ${{ matrix.image.name }} Docker | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ariya23156/sfmlops-${{ matrix.image.name }} | ||
- name: Build and push ${{ matrix.image.name }} Docker image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ${{ matrix.image.context }} | ||
file: ${{ matrix.image.file }} | ||
platforms: ${{ matrix.image.platform }} | ||
push: true | ||
tags: ariya23156/sfmlops-${{ matrix.image.name }}:latest-${{ matrix.image.platform }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
# Hardcoded all build-args here, couldn't find a proper way | ||
# to put this into matrix | ||
## for amd64 (x86_64) please leave ARCH_TRAILING_IMG_NAME empty like | ||
## ARCH_TRAILING_IMG_NAME= | ||
build-args: | | ||
Check failure on line 118 in .github/workflows/build_push_docker_hub.yaml GitHub Actions / Build and Push to Docker HubInvalid workflow file
|
||
ARCH_TRAILING_IMG_NAME=${{ matrix.platform == 'linux/amd64' ? '' : '-aarch64' }} |