name: Deploy to Production, build images and push to Gitea Registry on: pull_request: types: [closed] branches: - prod jobs: build_and_push: if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Install Docker run: | sudo apt-get update sudo apt-get install -y docker.io - name: Debug context variables run: | echo "Actor: ${{ gitea.actor }}" echo "Repository: ${{ gitea.repository_name }}" echo "Repository owner: ${{ gitea.repository_owner }}" echo "Event repository name: ${{ gitea.event.repository.name }}" echo "Event repository full name: ${{ gitea.event.repository.full_name }}" - name: Build and push backend image env: GITEA_USERNAME: ${{ secrets.ME_USERNAME }} GITEA_PASSWORD: ${{ secrets.ME_PASSWORD }} run: | echo $GITEA_PASSWORD | docker login git.vinylnostalgia.com -u $GITEA_USERNAME --password-stdin # Try different context variable combinations REPO_NAME="${{ gitea.repository_name }}" ACTOR="${{ gitea.actor }}" OWNER="${{ gitea.repository_owner }}" # Use fallback if variables are empty if [ -z "$REPO_NAME" ]; then REPO_NAME="${{ gitea.event.repository.name }}" fi if [ -z "$ACTOR" ]; then ACTOR="${{ gitea.event.repository.owner.login }}" fi echo "Using ACTOR: $ACTOR" echo "Using REPO_NAME: $REPO_NAME" # Build with compression and smaller layers docker build --compress --no-cache -t git.vinylnostalgia.com/$ACTOR/$REPO_NAME-backend:latest ./be -f ./be/Dockerfile.prod # Push with retries max_retries=3 retry_count=0 while [ $retry_count -lt $max_retries ]; do if docker push git.vinylnostalgia.com/$ACTOR/$REPO_NAME-backend:latest; then break fi retry_count=$((retry_count + 1)) if [ $retry_count -lt $max_retries ]; then echo "Push failed, retrying in 10 seconds... (Attempt $retry_count of $max_retries)" sleep 10 fi done if [ $retry_count -eq $max_retries ]; then echo "Failed to push after $max_retries attempts" exit 1 fi - name: Build and push frontend image env: GITEA_USERNAME: ${{ secrets.ME_USERNAME }} GITEA_PASSWORD: ${{ secrets.ME_PASSWORD }} run: | echo $GITEA_PASSWORD | docker login git.vinylnostalgia.com -u $GITEA_USERNAME --password-stdin # Try different context variable combinations REPO_NAME="${{ gitea.repository_name }}" ACTOR="${{ gitea.actor }}" OWNER="${{ gitea.repository_owner }}" # Use fallback if variables are empty if [ -z "$REPO_NAME" ]; then REPO_NAME="${{ gitea.event.repository.name }}" fi if [ -z "$ACTOR" ]; then ACTOR="${{ gitea.event.repository.owner.login }}" fi echo "Using ACTOR: $ACTOR" echo "Using REPO_NAME: $REPO_NAME" # Build with compression and smaller layers docker build --compress --no-cache -t git.vinylnostalgia.com/$ACTOR/$REPO_NAME-frontend:latest ./fe -f ./fe/Dockerfile.prod # Push with retries max_retries=3 retry_count=0 while [ $retry_count -lt $max_retries ]; do if docker push git.vinylnostalgia.com/$ACTOR/$REPO_NAME-frontend:latest; then break fi retry_count=$((retry_count + 1)) if [ $retry_count -lt $max_retries ]; then echo "Push failed, retrying in 10 seconds... (Attempt $retry_count of $max_retries)" sleep 10 fi done if [ $retry_count -eq $max_retries ]; then echo "Failed to push after $max_retries attempts" exit 1 fi