Skip to content

Commit

Permalink
simplify production workflow for amd64
Browse files Browse the repository at this point in the history
  • Loading branch information
eberrigan committed Nov 22, 2024
1 parent abdeba1 commit 70a9ef3
Showing 1 changed file with 31 additions and 52 deletions.
83 changes: 31 additions & 52 deletions .github/workflows/docker-build-production.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
name: Build and Push Multi-Arch Docker Image
name: Build and Push Docker Image (Production Workflow)

# Run on push to main branch
# Run on push to main branch after testing is complete
on:
push:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest # Only build on Ubuntu for now since Docker is not available on macOS runners
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
platform: [linux/arm64, linux/amd64]
max-parallel: 2
platform: [linux/amd64] # Only build amd64 for now
max-parallel: 2 # Build both architectures in parallel (if more than one)
outputs:
git_sha: ${{ steps.git_info.outputs.sha }}
git_sha: ${{ steps.get_sha.outputs.sha }}
sanitized_platform: ${{ steps.sanitize_platform.outputs.sanitized_platform }}
steps:
- name: Checkout code
# https://github.com/actions/checkout
uses: actions/checkout@v4

- name: Get Git SHA
id: git_info
id: get_sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: Debug Git SHA
run: echo "Git SHA ${{ steps.get_sha.outputs.sha }}"

# Generate a sanitized platform string with slashes replaced by dashes
- name: Sanitize platform name
id: sanitize_platform
run: |
sanitized_platform="${{ matrix.platform }}" # Copy platform value
sanitized_platform="${sanitized_platform/\//-}" # Replace / with -
echo "sanitized_platform=$sanitized_platform" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
# https://github.com/docker/setup-buildx-action
uses: docker/setup-buildx-action@v3
with:
driver: docker-container # Use a container driver for Buildx (default)

- name: Log in to Docker Hub
# https://github.com/docker/login-action
Expand All @@ -37,51 +50,17 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
# https://github.com/docker/build-push-action
# https://github.com/docker/build-push-action
uses: docker/build-push-action@v6
with:
context: ./docker
file: ./docker/Dockerfile
context: ./docker # Build context
file: ./docker/Dockerfile # Path to Dockerfile
platforms: ${{ matrix.platform }}
push: true
push: true # Push the image to Docker Hub
# Tags for the production images, including the "latest" tag
tags: |
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ matrix.platform }}-latest
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ matrix.platform }}-nvidia-cuda-11.3.1-cudnn8-runtime-ubuntu20.04
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ matrix.platform }}-sleap-1.3.4
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ matrix.platform }}-${{ steps.git_info.outputs.sha }}
- name: Clean up Docker resources
run: docker system prune -af

combine-manifest:
needs: build
runs-on: ubuntu-latest
steps:
- name: Log in to Docker Hub
# https://github.com/docker/login-action
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create multi-arch manifest
run: |
docker manifest create ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:latest \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/amd64-latest \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/arm64-latest
docker manifest push ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:latest
- name: Push additional multi-arch tags
run: |
docker manifest create ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:nvidia-cuda-11.3.1-cudnn8-runtime-ubuntu20.04 \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/amd64-latest \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/arm64-latest
docker manifest create ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:sleap-1.3.4 \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/amd64-latest \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/arm64-latest
docker manifest create ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ needs.build.outputs.git_sha }} \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/amd64-latest \
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:linux/arm64-latest
docker manifest push ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:nvidia-cuda-11.3.1-cudnn8-runtime-ubuntu20.04
docker manifest push ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:sleap-1.3.4
docker manifest push ${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ needs.build.outputs.git_sha }}
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:latest
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ steps.sanitize_platform.outputs.sanitized_platform }}
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ steps.sanitize_platform.outputs.sanitized_platform }}-nvidia-cuda-11.3.1-cudnn8-runtime-ubuntu20.04
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ steps.sanitize_platform.outputs.sanitized_platform }}-sleap-1.3.4
${{ vars.DOCKERHUB_USERNAME }}/sleap-cuda:${{ steps.sanitize_platform.outputs.sanitized_platform }}-${{ steps.get_sha.outputs.sha }}

0 comments on commit 70a9ef3

Please sign in to comment.