diff --git a/.gitea/workflows/deploy-bcards.yml b/.gitea/workflows/deploy-bcards.yml index 68e3c91..77542da 100644 --- a/.gitea/workflows/deploy-bcards.yml +++ b/.gitea/workflows/deploy-bcards.yml @@ -101,7 +101,7 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: - platforms: linux/amd64,linux/arm64 + platforms: linux/arm64 - name: Determine build settings id: settings @@ -109,22 +109,22 @@ jobs: BRANCH_NAME="${{ github.ref_name }}" 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 "platform=linux/arm64" >> $GITHUB_OUTPUT echo "environment=Production" >> $GITHUB_OUTPUT echo "dockerfile=Dockerfile" >> $GITHUB_OUTPUT echo "deploy_target=production" >> $GITHUB_OUTPUT elif [[ "$BRANCH_NAME" == Release/* ]]; then - # Release = Swarm tests (Orange Pi arm64) + # Release = Swarm tests (Orange Pi arm64) - usando Dockerfile simples também VERSION_RAW=${BRANCH_NAME#Release/} VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//') [ -z "$VERSION" ] && VERSION="0.0.1" - + echo "tag=$VERSION" >> $GITHUB_OUTPUT echo "platform=linux/arm64" >> $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 "version=$VERSION" >> $GITHUB_OUTPUT fi diff --git a/Dockerfile.release b/archive/Dockerfile.release.backup similarity index 96% rename from Dockerfile.release rename to archive/Dockerfile.release.backup index b347256..334c100 100644 --- a/Dockerfile.release +++ b/archive/Dockerfile.release.backup @@ -1,120 +1,120 @@ -# Dockerfile.release - Multi-architecture build for Release environment -# Supports: linux/amd64, linux/arm64 -ARG BUILDPLATFORM=linux/amd64 -ARG TARGETPLATFORM -ARG VERSION=0.0.1 -ARG COMMIT=unknown - -# Base runtime image with multi-arch support -FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0 AS base -WORKDIR /app -EXPOSE 8080 -EXPOSE 8443 - -# Install dependencies based on target platform -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - libgdiplus \ - curl \ - ca-certificates \ - && rm -rf /var/lib/apt/lists/* \ - && apt-get clean - -# Create application directories -RUN mkdir -p /app/uploads /app/logs \ - && chmod 755 /app/uploads /app/logs - -# Build stage - restore and publish -FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build -ARG TARGETPLATFORM -ARG VERSION -ARG COMMIT - -WORKDIR /src - -# Copy project file and restore dependencies -COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"] - -# Map platform to .NET runtime identifier and restore -RUN case "$TARGETPLATFORM" in \ - "linux/amd64") RID="linux-x64" ;; \ - "linux/arm64") RID="linux-arm64" ;; \ - *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ - esac && \ - echo "🔧 Restoring for RID: $RID" && \ - dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID - -# Copy source code -COPY . . -WORKDIR "/src/src/BCards.Web" - -# Publish diretamente (build + publish em um comando) -RUN case "$TARGETPLATFORM" in \ - "linux/amd64") RID="linux-x64" ;; \ - "linux/arm64") RID="linux-arm64" ;; \ - *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ - esac && \ - echo "📦 Publishing for RID: $RID" && \ - dotnet publish "BCards.Web.csproj" \ - -c Release \ - -o /app/publish \ - --no-restore \ - --runtime $RID \ - --self-contained false \ - -p:PublishReadyToRun=false \ - -p:PublishSingleFile=false \ - -p:UseAppHost=false \ - -p:Version=$VERSION \ - -p:InformationalVersion=$COMMIT - -# Final stage - runtime optimized for Release environment -FROM base AS final -ARG VERSION=0.0.1 -ARG COMMIT=unknown -ARG TARGETPLATFORM - -# Metadata labels -LABEL maintainer="BCards Team" -LABEL version=$VERSION -LABEL commit=$COMMIT -LABEL platform=$TARGETPLATFORM -LABEL environment="release" - -WORKDIR /app - -# Copy published application -COPY --from=build /app/publish . - -# Create non-root user for security -RUN groupadd -r bcards && useradd -r -g bcards bcards \ - && chown -R bcards:bcards /app - -# Environment variables for Release -ENV ASPNETCORE_ENVIRONMENT=Release -ENV ASPNETCORE_URLS=http://+:8080 -ENV DOTNET_RUNNING_IN_CONTAINER=true -ENV DOTNET_EnableDiagnostics=0 -ENV DOTNET_USE_POLLING_FILE_WATCHER=true -ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false - -# Platform-specific optimizations -RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ - echo "🔧 Applying ARM64 optimizations..." && \ - echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ - echo 'export DOTNET_TC_QuickJitForLoops=1' >> /etc/environment && \ - echo 'export DOTNET_ReadyToRun=0' >> /etc/environment; \ - else \ - echo "🔧 Applying AMD64 optimizations..." && \ - echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ - echo 'export DOTNET_ReadyToRun=1' >> /etc/environment; \ - fi - -# Health check endpoint -HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ - CMD curl -f http://localhost:8080/health || exit 1 - -# Switch to non-root user -USER bcards - -# Entry point with optimized runtime settings -ENTRYPOINT ["dotnet", "BCards.Web.dll"] +# Dockerfile.release - Multi-architecture build for Release environment +# Supports: linux/amd64, linux/arm64 +ARG BUILDPLATFORM=linux/amd64 +ARG TARGETPLATFORM +ARG VERSION=0.0.1 +ARG COMMIT=unknown + +# Base runtime image with multi-arch support +FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +WORKDIR /app +EXPOSE 8080 +EXPOSE 8443 + +# Install dependencies based on target platform +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libgdiplus \ + curl \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get clean + +# Create application directories +RUN mkdir -p /app/uploads /app/logs \ + && chmod 755 /app/uploads /app/logs + +# Build stage - restore and publish +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG TARGETPLATFORM +ARG VERSION +ARG COMMIT + +WORKDIR /src + +# Copy project file and restore dependencies +COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"] + +# Map platform to .NET runtime identifier and restore +RUN case "$TARGETPLATFORM" in \ + "linux/amd64") RID="linux-x64" ;; \ + "linux/arm64") RID="linux-arm64" ;; \ + *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ + esac && \ + echo "🔧 Restoring for RID: $RID" && \ + dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID + +# Copy source code +COPY . . +WORKDIR "/src/src/BCards.Web" + +# Publish diretamente (build + publish em um comando) +RUN case "$TARGETPLATFORM" in \ + "linux/amd64") RID="linux-x64" ;; \ + "linux/arm64") RID="linux-arm64" ;; \ + *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ + esac && \ + echo "📦 Publishing for RID: $RID" && \ + dotnet publish "BCards.Web.csproj" \ + -c Release \ + -o /app/publish \ + --no-restore \ + --runtime $RID \ + --self-contained false \ + -p:PublishReadyToRun=false \ + -p:PublishSingleFile=false \ + -p:UseAppHost=false \ + -p:Version=$VERSION \ + -p:InformationalVersion=$COMMIT + +# Final stage - runtime optimized for Release environment +FROM base AS final +ARG VERSION=0.0.1 +ARG COMMIT=unknown +ARG TARGETPLATFORM + +# Metadata labels +LABEL maintainer="BCards Team" +LABEL version=$VERSION +LABEL commit=$COMMIT +LABEL platform=$TARGETPLATFORM +LABEL environment="release" + +WORKDIR /app + +# Copy published application +COPY --from=build /app/publish . + +# Create non-root user for security +RUN groupadd -r bcards && useradd -r -g bcards bcards \ + && chown -R bcards:bcards /app + +# Environment variables for Release +ENV ASPNETCORE_ENVIRONMENT=Release +ENV ASPNETCORE_URLS=http://+:8080 +ENV DOTNET_RUNNING_IN_CONTAINER=true +ENV DOTNET_EnableDiagnostics=0 +ENV DOTNET_USE_POLLING_FILE_WATCHER=true +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false + +# Platform-specific optimizations +RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + echo "🔧 Applying ARM64 optimizations..." && \ + echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ + echo 'export DOTNET_TC_QuickJitForLoops=1' >> /etc/environment && \ + echo 'export DOTNET_ReadyToRun=0' >> /etc/environment; \ + else \ + echo "🔧 Applying AMD64 optimizations..." && \ + echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ + echo 'export DOTNET_ReadyToRun=1' >> /etc/environment; \ + fi + +# Health check endpoint +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD curl -f http://localhost:8080/health || exit 1 + +# Switch to non-root user +USER bcards + +# Entry point with optimized runtime settings +ENTRYPOINT ["dotnet", "BCards.Web.dll"]