Compare commits

...

9 Commits

Author SHA1 Message Date
5834afc648 Merge pull request 'Release/versao1' (#18) from Release/versao1 into main
All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 3s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 8m2s
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Has been skipped
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Successful in 1m32s
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/BCards/pulls/18
2025-09-22 18:37:52 +00:00
Ricardo Carneiro
dc00ea97a9 fix: ajuste de cache no codigo
All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 3s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Run Tests (pull_request) Successful in 2s
BCards Deployment Pipeline / Build and Push Image (pull_request) Has been skipped
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (pull_request) Has been skipped
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (pull_request) Has been skipped
BCards Deployment Pipeline / Cleanup Old Resources (pull_request) Has been skipped
BCards Deployment Pipeline / PR Validation (pull_request) Successful in 1s
BCards Deployment Pipeline / Deployment Summary (pull_request) Successful in 1s
BCards Deployment Pipeline / Build and Push Image (push) Successful in 10m2s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been skipped
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Successful in 7s
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 1s
2025-09-22 15:27:13 -03:00
Ricardo Carneiro
f20f136350 fix: ajuste de deploy para quantidade de replicas
All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 2s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 7m46s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been skipped
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Successful in 59s
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
2025-09-22 12:10:23 -03:00
Ricardo Carneiro
34503936dd fix: ajustes variaveis release
Some checks failed
BCards Deployment Pipeline / Run Tests (push) Successful in 2s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 10m17s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been skipped
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Failing after 2m40s
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
2025-09-22 11:46:57 -03:00
Ricardo Carneiro
cf9906bafe fix: envs de release
Some checks failed
BCards Deployment Pipeline / Run Tests (push) Successful in 2s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 7m34s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been skipped
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Failing after 2m39s
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
2025-09-22 09:33:47 -03:00
Ricardo Carneiro
caefa20110 fix: build de release com arquivo não encontrado
Some checks failed
BCards Deployment Pipeline / Run Tests (push) Successful in 2s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 8m24s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been skipped
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Failing after 5s
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
2025-09-22 09:22:50 -03:00
Ricardo Carneiro
ee4db7a910 fix: deploy de release
Some checks failed
BCards Deployment Pipeline / Run Tests (push) Successful in 4s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 6m48s
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Failing after 0s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been skipped
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
2025-09-22 08:05:53 -03:00
Ricardo Carneiro
a7e1677949 fix: builde de release
Some checks failed
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Blocked by required conditions
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Blocked by required conditions
BCards Deployment Pipeline / Cleanup Old Resources (push) Blocked by required conditions
BCards Deployment Pipeline / Deployment Summary (push) Blocked by required conditions
BCards Deployment Pipeline / Run Tests (push) Successful in 2s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Failing after 3h6m11s
2025-09-21 22:58:05 -03:00
Ricardo Carneiro
b0d164c8a9 fix: modo release
Some checks failed
BCards Deployment Pipeline / Run Tests (push) Successful in 2s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Has been cancelled
BCards Deployment Pipeline / Deploy to Release Swarm (ARM) (push) Has been cancelled
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been cancelled
BCards Deployment Pipeline / Build and Push Image (push) Has been cancelled
BCards Deployment Pipeline / Deployment Summary (push) Has been cancelled
2025-09-21 22:03:30 -03:00
5 changed files with 201 additions and 183 deletions

View File

@ -101,7 +101,7 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
with: with:
platforms: linux/amd64,linux/arm64 platforms: linux/arm64
- name: Determine build settings - name: Determine build settings
id: settings id: settings
@ -109,22 +109,23 @@ jobs:
BRANCH_NAME="${{ github.ref_name }}" BRANCH_NAME="${{ github.ref_name }}"
if [ "$BRANCH_NAME" = "main" ]; then if [ "$BRANCH_NAME" = "main" ]; then
# Main = Produção (ARM64) - usando Dockerfile da raiz como QRRapido # Main = Produção (ARM64) - usando Dockerfile simples
echo "tag=latest" >> $GITHUB_OUTPUT echo "tag=latest" >> $GITHUB_OUTPUT
echo "platform=linux/arm64" >> $GITHUB_OUTPUT echo "platform=linux/arm64" >> $GITHUB_OUTPUT
echo "environment=Production" >> $GITHUB_OUTPUT echo "environment=Production" >> $GITHUB_OUTPUT
echo "dockerfile=Dockerfile" >> $GITHUB_OUTPUT echo "dockerfile=Dockerfile" >> $GITHUB_OUTPUT
echo "deploy_target=production" >> $GITHUB_OUTPUT echo "deploy_target=production" >> $GITHUB_OUTPUT
elif [[ "$BRANCH_NAME" == Release/* ]]; then elif [[ "$BRANCH_NAME" == Release/* ]]; then
# Release = Staging (x86) # Release = Swarm tests (Orange Pi arm64) - usando Dockerfile simples também
VERSION_RAW=${BRANCH_NAME#Release/} VERSION_RAW=${BRANCH_NAME#Release/}
VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//') # Only remove V/v if it's at the start and followed by a number (like v1.0.0)
VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]\([0-9]\)/\1/')
[ -z "$VERSION" ] && VERSION="0.0.1" [ -z "$VERSION" ] && VERSION="0.0.1"
echo "tag=$VERSION" >> $GITHUB_OUTPUT echo "tag=$VERSION" >> $GITHUB_OUTPUT
echo "platform=linux/amd64" >> $GITHUB_OUTPUT echo "platform=linux/arm64" >> $GITHUB_OUTPUT
echo "environment=Testing" >> $GITHUB_OUTPUT echo "environment=Testing" >> $GITHUB_OUTPUT
echo "dockerfile=Dockerfile.release" >> $GITHUB_OUTPUT echo "dockerfile=Dockerfile" >> $GITHUB_OUTPUT
echo "deploy_target=testing" >> $GITHUB_OUTPUT echo "deploy_target=testing" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT
fi fi
@ -544,12 +545,16 @@ jobs:
if: startsWith(github.ref_name, 'Release/') if: startsWith(github.ref_name, 'Release/')
steps: steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version - name: Extract version
id: version id: version
run: | run: |
BRANCH_NAME="${{ github.ref_name }}" BRANCH_NAME="${{ github.ref_name }}"
VERSION_RAW=${BRANCH_NAME#Release/} VERSION_RAW=${BRANCH_NAME#Release/}
VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//') # Only remove V/v if it's at the start and followed by a number (like v1.0.0)
VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]\([0-9]\)/\1/')
[ -z "$VERSION" ] && VERSION="0.0.1" [ -z "$VERSION" ] && VERSION="0.0.1"
echo "version=$VERSION" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "📦 Deploying version: $VERSION" echo "📦 Deploying version: $VERSION"
@ -557,23 +562,42 @@ jobs:
- name: Prepare release stack manifest - name: Prepare release stack manifest
run: | run: |
mkdir -p artifacts mkdir -p artifacts
export BCARDS_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} BCARDS_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
envsubst '$BCARDS_IMAGE' < deploy/docker-stack.release.yml > artifacts/docker-stack.release.yml
# Replace ${BCARDS_IMAGE} with actual image name using sed
sed "s|\${BCARDS_IMAGE}|${BCARDS_IMAGE}|g" deploy/docker-stack.release.yml > artifacts/docker-stack.release.yml
echo "🔧 Generated manifest with image: ${BCARDS_IMAGE}"
echo "📄 Manifest content:"
head -10 artifacts/docker-stack.release.yml
- name: Deploy to release swarm - name: Deploy to release swarm
run: | run: |
echo "🚀 Deploying release stack to Orange Pi swarm..." echo "🚀 Deploying release stack to Orange Pi swarm..."
docker stack deploy -c artifacts/docker-stack.release.yml bcards-release
mkdir -p ~/.ssh - name: Await release service readiness
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa run: |
chmod 600 ~/.ssh/id_rsa echo "⏳ Aguardando serviço bcards-release estabilizar..."
ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts ATTEMPTS=30
ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts while [ $ATTEMPTS -gt 0 ]; do
REPLICAS=$(docker service ls --filter name=bcards-release_bcards-release --format '{{.Replicas}}')
if [ "$REPLICAS" = "1/1" ]; then
echo "✅ Serviço com $REPLICAS réplica"
break
fi
echo "Atual: ${REPLICAS:-N/A}; aguardando..."
sleep 5
ATTEMPTS=$((ATTEMPTS-1))
done
scp -o StrictHostKeyChecking=no artifacts/docker-stack.release.yml ubuntu@141.148.162.114:/home/ubuntu/docker-stack.release.yml if [ "$REPLICAS" != "1/1" ]; then
echo "❌ Serviço não atingiu 1/1 réplica"
docker service ps bcards-release_bcards-release
exit 1
fi
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 \ docker service ps bcards-release_bcards-release
'/home/ubuntu/scripts/swarm_deploy.sh bcards-release bcards-release /home/ubuntu/docker-stack.release.yml http://localhost:28080/health 2'
cleanup: cleanup:
name: Cleanup Old Resources name: Cleanup Old Resources
@ -586,39 +610,25 @@ jobs:
run: | run: |
echo "🧹 Limpando recursos antigos..." echo "🧹 Limpando recursos antigos..."
# Configura SSH (igual ao QRRapido) if [ "${{ github.ref_name }}" = "main" ]; then
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa
# Adiciona hosts conhecidos
ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts
ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts
# Testa a chave SSH
ssh-add ~/.ssh/id_rsa 2>/dev/null || echo "SSH key loaded" ssh-add ~/.ssh/id_rsa 2>/dev/null || echo "SSH key loaded"
# Lista de servidores baseada na branch for server in 141.148.162.114 129.146.116.218; do
if [ "${{ github.ref_name }}" = "main" ]; then
SERVERS=("141.148.162.114" "129.146.116.218")
else
SERVERS=("141.148.162.114" "129.146.116.218")
fi
# Limpeza em cada servidor
for server in "${SERVERS[@]}"; do
echo "🧹 Limpando servidor $server..." echo "🧹 Limpando servidor $server..."
ssh -o StrictHostKeyChecking=no ubuntu@$server << 'EOF' ssh -o StrictHostKeyChecking=no ubuntu@$server << 'EOF'
# Remove containers parados
docker container prune -f docker container prune -f
# Remove imagens não utilizadas
docker image prune -f docker image prune -f
# Remove redes não utilizadas
docker network prune -f docker network prune -f
EOF EOF
done done
else
echo " Release branch: limpeza remota ignorada (Swarm gerencia recursos)."
fi
echo "✅ Limpeza concluída!" echo "✅ Limpeza concluída!"

View File

@ -6,9 +6,7 @@ services:
networks: networks:
- bcards-net - bcards-net
deploy: deploy:
replicas: 2 replicas: 1
placement:
max_replicas_per_node: 1
update_config: update_config:
parallelism: 1 parallelism: 1
delay: 10s delay: 10s
@ -22,13 +20,20 @@ services:
ASPNETCORE_ENVIRONMENT: Release ASPNETCORE_ENVIRONMENT: Release
ASPNETCORE_URLS: http://+:8080 ASPNETCORE_URLS: http://+:8080
ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true" ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true"
# MongoDB local (Core i5)
MongoDb__ConnectionString: mongodb://192.168.0.100:27017/BCardsDB MongoDb__ConnectionString: mongodb://192.168.0.100:27017/BCardsDB
MongoDb__DatabaseName: BCardsDB MongoDb__DatabaseName: BCardsDB
DataProtection__Mongo__ConnectionString: mongodb://192.168.0.100:27017/BCardsDB DataProtection__Mongo__ConnectionString: mongodb://192.168.0.100:27017/BCardsDB
DataProtection__Mongo__DatabaseName: BCardsDB DataProtection__Mongo__DatabaseName: BCardsDB
DataProtection__Mongo__CollectionName: DataProtectionKeys DataProtection__Mongo__CollectionName: DataProtectionKeys
Serilog__OpenSearchUrl: http://141.148.162.114:19201 # OpenSearch local (Core i5)
Serilog__OpenSearchFallback: http://129.146.116.218:19202 Serilog__OpenSearchUrl: http://192.168.0.100:9200
Serilog__OpenSearchFallback: http://192.168.0.100:9200
# Stripe test keys (same as development)
Stripe__PublishableKey: pk_test_51RjUmIBMIadsOxJVP4bWc54pHEOSf5km1hpOkOBSoGVoKxI46N4KSWtevpXCSq68OjFazBuXmPJGBwZ1KDN5MNJy003lj1YmAS
Stripe__SecretKey: sk_test_51RjUmIBMIadsOxJVeqsMFxnZ8ePR7d8IbnaF4sAwBVJv9rrfODPEQ2C9fF3beoABpITdfzEk0ZDzGTTQfvKv63xI00PeZoABGO
Stripe__WebhookSecret: whsec_8d189c137ff170ab5e62498003512b9d073e2db50c50ed7d8712b7ef11a37543
Stripe__Environment: test
Logging__LogLevel__Default: Debug Logging__LogLevel__Default: Debug
healthcheck: healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"] test: ["CMD", "curl", "-f", "http://localhost:8080/health"]

View File

@ -196,7 +196,7 @@ deploy_new_version() {
cat > "$DEPLOY_DIR/.env" << EOF cat > "$DEPLOY_DIR/.env" << EOF
IMAGE_TAG=$image_tag IMAGE_TAG=$image_tag
REGISTRY=registry.redecarneir.us REGISTRY=registry.redecarneir.us
MONGODB_CONNECTION_STRING=mongodb://192.168.0.100:27017/BCardsDB MONGODB_CONNECTION_STRING=mongodb://admin:c4rn31r0@129.146.116.218:27017,141.148.162.114:27017/BCardsDB?replicaSet=rs0&authSource=admin
ASPNETCORE_ENVIRONMENT=Release ASPNETCORE_ENVIRONMENT=Release
CERT_PASSWORD= CERT_PASSWORD=
EOF EOF

View File

@ -53,10 +53,13 @@ namespace BCards.Web.Middleware
// Só adicionar se não foi definido explicitamente pelo controller // Só adicionar se não foi definido explicitamente pelo controller
if (!context.Response.Headers.ContainsKey("Cache-Control")) if (!context.Response.Headers.ContainsKey("Cache-Control"))
{ {
context.Response.Headers["Cache-Control"] = "no-cache, must-revalidate"; // Headers mais fortes para garantir que CDNs como Cloudflare não façam cache
context.Response.Headers["Vary"] = "Cookie"; context.Response.Headers["Cache-Control"] = "no-store, no-cache, must-revalidate, proxy-revalidate";
context.Response.Headers["Pragma"] = "no-cache";
context.Response.Headers["Expires"] = "0";
context.Response.Headers["Vary"] = "Cookie, Authorization";
_logger.LogDebug("AuthCache: Applied no-cache for authenticated user on {Path}", path); _logger.LogDebug("AuthCache: Applied strong no-cache headers for authenticated user on {Path}", path);
} }
} }
else else