name: Profile Linker Docker Build on: push: branches: [dev, main] pull_request: branches: [dev, main] env: APP_NAME: NEW_APP_NAME REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME }} REGISTRY_PASSWORD: ${{ secrets.REGISTRY_TOKEN }} jobs: deploy: runs-on: ubuntu-latest env: BRANCH_NAME: ${{ gitea.ref_name }} name: Build and push Docker image steps: - name: Install required packages run: | if command -v apk >/dev/null 2>&1; then apk add --no-cache nodejs npm git docker elif command -v apt-get >/dev/null 2>&1; then apt-get update && apt-get install -y nodejs npm git docker.io fi - name: Checkout code uses: actions/checkout@v4 - name: Set deployment variables id: vars run: | BRANCH="$BRANCH_NAME" if [[ "$BRANCH" == "main" ]]; then tag="latest" elif [[ "$BRANCH" == "dev" ]]; then tag="dev" else tag="test" fi # Extract APP_NAME from .env file if it exists if [ -f .env ]; then APP_NAME=$(grep APP_NAME .env | cut -d '=' -f2) fi echo "tag=$tag" >> $GITEA_OUTPUT echo "app_name=$APP_NAME" >> $GITEA_OUTPUT # Login to Docker Hub before building to allow pulling base images - name: Login to Docker Hub run: | echo "$REGISTRY_PASSWORD" | docker login -u "$REGISTRY_USERNAME" --password-stdin # Pull base images explicitly before building - name: Pull base images run: | docker pull node:20-alpine docker pull python:3.11-alpine - name: Build Docker image run: | APP_NAME="${{ steps.vars.outputs.app_name }}" TAG="${{ steps.vars.outputs.tag }}" # Build with no-cache to avoid authentication issues docker build --no-cache -t docker.io/$REGISTRY_USERNAME/$APP_NAME:$TAG \ -t docker.io/$REGISTRY_USERNAME/$APP_NAME:${{ gitea.sha }} \ -f ./backend/Dockerfile \ . - name: Push Docker image if: gitea.event_name != 'pull_request' run: | APP_NAME="${{ steps.vars.outputs.app_name }}" TAG="${{ steps.vars.outputs.tag }}" docker push docker.io/$REGISTRY_USERNAME/$APP_NAME:$TAG docker push docker.io/$REGISTRY_USERNAME/$APP_NAME:${{ gitea.sha }} echo "=== 🏗️ Build Summary ===" echo "📦 Image Built: docker.io/$REGISTRY_USERNAME/$APP_NAME:${{ gitea.sha }}" echo "====================="