update #123
This file contains hidden or 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 Docker Images | |
on: | |
push: | |
branches: | |
- dev | |
paths: | |
- 'backend/**' | |
- 'frontend/**' | |
- '.github/workflows/**' | |
tags: | |
- 'v*' | |
workflow_dispatch: | |
env: | |
DOCKERHUB_USERNAME_VAR: ${{ secrets.DOCKERHUB_USERNAME }} | |
jobs: | |
build-backend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Debug trigger | |
run: | | |
echo "Event: ${{ github.event_name }}" | |
echo "Ref: ${{ github.ref }}" | |
echo "Ref name: ${{ github.ref_name }}" | |
echo "Service: backend" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get current date | |
id: date | |
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT | |
- name: Prepare Docker tags | |
id: docker_tags | |
run: | | |
IMAGE_NAME="${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-backend" | |
TAGS="" | |
# Add branch-specific tags | |
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then | |
TAGS="$TAGS $IMAGE_NAME:latest" | |
elif [[ "${{ github.ref_name }}" == "dev" ]]; then | |
TAGS="$TAGS $IMAGE_NAME:dev" | |
elif [[ "${{ github.ref_type }}" == "branch" ]]; then | |
TAGS="$TAGS $IMAGE_NAME:${{ github.ref_name }}" | |
fi | |
# Add sha tag for branches | |
if [[ "${{ github.ref_type }}" == "branch" ]]; then | |
TAGS="$TAGS,$IMAGE_NAME:sha-${GITHUB_SHA::7}" | |
fi | |
# Add version tag for tagged releases | |
if [[ "${{ github.ref_type }}" == "tag" && "${{ github.ref }}" == refs/tags/v* ]]; then | |
VERSION="${{ github.ref_name }}" | |
TAGS="$TAGS,$IMAGE_NAME:$VERSION" | |
TAGS="$TAGS,$IMAGE_NAME:latest" | |
fi | |
# Add date tag | |
TAGS="$TAGS,$IMAGE_NAME:${{ steps.date.outputs.date }}" | |
# Clean up tags | |
TAGS=$(echo "$TAGS" | sed 's/^[ ,]*//') | |
echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
echo "Backend Docker tags: $TAGS" | |
- name: Build and push backend | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./backend | |
push: true | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
tags: ${{ steps.docker_tags.outputs.tags }} | |
cache-from: type=gha,scope=backend | |
cache-to: type=gha,mode=max,scope=backend | |
build-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Debug trigger | |
run: | | |
echo "Event: ${{ github.event_name }}" | |
echo "Ref: ${{ github.ref }}" | |
echo "Ref name: ${{ github.ref_name }}" | |
echo "Service: frontend" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get current date | |
id: date | |
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT | |
- name: Prepare Docker tags | |
id: docker_tags | |
run: | | |
IMAGE_NAME="${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-frontend" | |
TAGS="" | |
# Add branch-specific tags | |
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then | |
TAGS="$TAGS $IMAGE_NAME:latest" | |
elif [[ "${{ github.ref_name }}" == "dev" ]]; then | |
TAGS="$TAGS $IMAGE_NAME:dev" | |
elif [[ "${{ github.ref_type }}" == "branch" ]]; then | |
TAGS="$TAGS $IMAGE_NAME:${{ github.ref_name }}" | |
fi | |
# Add sha tag for branches | |
if [[ "${{ github.ref_type }}" == "branch" ]]; then | |
TAGS="$TAGS,$IMAGE_NAME:sha-${GITHUB_SHA::7}" | |
fi | |
# Add version tag for tagged releases | |
if [[ "${{ github.ref_type }}" == "tag" && "${{ github.ref }}" == refs/tags/v* ]]; then | |
VERSION="${{ github.ref_name }}" | |
TAGS="$TAGS,$IMAGE_NAME:$VERSION" | |
TAGS="$TAGS,$IMAGE_NAME:latest" | |
fi | |
# Add date tag | |
TAGS="$TAGS,$IMAGE_NAME:${{ steps.date.outputs.date }}" | |
# Clean up tags | |
TAGS=$(echo "$TAGS" | sed 's/^[ ,]*//') | |
echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
echo "Frontend Docker tags: $TAGS" | |
- name: Build and push frontend | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./frontend | |
push: true | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
tags: ${{ steps.docker_tags.outputs.tags }} | |
cache-from: type=gha,scope=frontend | |
cache-to: type=gha,mode=max,scope=frontend | |
build-summary: | |
runs-on: ubuntu-latest | |
needs: [build-backend, build-frontend] | |
if: always() | |
steps: | |
- name: Build Summary | |
run: | | |
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "**Event:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY | |
echo "**Branch/Tag:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY | |
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "**Images pushed:**" >> $GITHUB_STEP_SUMMARY | |
echo "- \`${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-backend\`" >> $GITHUB_STEP_SUMMARY | |
echo "- \`${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-frontend\`" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "**Platforms:** linux/amd64, linux/arm64, linux/arm/v7" >> $GITHUB_STEP_SUMMARY | |
if [ "${{ needs.build-backend.result }}" == "success" ] && [ "${{ needs.build-frontend.result }}" == "success" ]; then | |
echo "✅ All builds completed successfully!" >> $GITHUB_STEP_SUMMARY | |
else | |
echo "❌ Some builds failed. Check the logs above." >> $GITHUB_STEP_SUMMARY | |
fi |