Skip to content

perf: optimize Dockerfile to reduce build time #221

perf: optimize Dockerfile to reduce build time

perf: optimize Dockerfile to reduce build time #221

name: 'Build and Publish Images to Docker Hub'
on:
push:
branches:
- feature-docker-compose
tags:
- 'v*' # Only trigger on version tags
jobs:
docker:
runs-on: ubuntu-latest
timeout-minutes: 240 # Increased timeout for ARM64 builds
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Tag generation with latest and release handling
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: masaengineering/masa-bittensor
tags: |
# Always push latest
type=raw,value=latest
# Branch builds with timestamp
type=ref,event=branch,suffix=-{{date 'YYYYMMDDHHmmss'}}
# SHA with timestamp
type=sha,format=short,prefix=sha-,suffix=-{{date 'YYYYMMDDHHmmss'}}
# Version tags (v1.2.3 -> 1.2.3, latest)
type=semver,pattern={{version}},value=${{ github.ref_name }}
type=semver,pattern={{major}}.{{minor}},value=${{ github.ref_name }}
type=semver,pattern={{major}},value=${{ github.ref_name }}
# Debug step to see what tags will be used
- name: Debug Docker Tags
run: |
echo "Tags to be used:"
echo "${{ steps.meta.outputs.tags }}"
echo "Is this a release? ${{ startsWith(github.ref, 'refs/tags/v') }}"
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Verify the push was successful
- name: Verify Push
run: |
echo "Verifying pushed images..."
for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' '); do
echo "Checking tag: $tag"
docker pull $tag
done
# Announce the release in the logs
- name: Announce Release
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "🎉 Released version ${GITHUB_REF#refs/tags/v}"
echo "Published tags:"
echo "${{ steps.meta.outputs.tags }}"