Release/versao1 #18

Merged
ricardo merged 8 commits from Release/versao1 into main 2025-09-22 18:37:52 +00:00
2 changed files with 125 additions and 125 deletions
Showing only changes of commit ee4db7a910 - Show all commits

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,22 @@ 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 = Swarm tests (Orange Pi arm64) # 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]//') VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//')
[ -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/arm64" >> $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

View File

@ -1,120 +1,120 @@
# Dockerfile.release - Multi-architecture build for Release environment # Dockerfile.release - Multi-architecture build for Release environment
# Supports: linux/amd64, linux/arm64 # Supports: linux/amd64, linux/arm64
ARG BUILDPLATFORM=linux/amd64 ARG BUILDPLATFORM=linux/amd64
ARG TARGETPLATFORM ARG TARGETPLATFORM
ARG VERSION=0.0.1 ARG VERSION=0.0.1
ARG COMMIT=unknown ARG COMMIT=unknown
# Base runtime image with multi-arch support # Base runtime image with multi-arch support
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0 AS base FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app WORKDIR /app
EXPOSE 8080 EXPOSE 8080
EXPOSE 8443 EXPOSE 8443
# Install dependencies based on target platform # Install dependencies based on target platform
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
libgdiplus \ libgdiplus \
curl \ curl \
ca-certificates \ ca-certificates \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& apt-get clean && apt-get clean
# Create application directories # Create application directories
RUN mkdir -p /app/uploads /app/logs \ RUN mkdir -p /app/uploads /app/logs \
&& chmod 755 /app/uploads /app/logs && chmod 755 /app/uploads /app/logs
# Build stage - restore and publish # Build stage - restore and publish
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETPLATFORM ARG TARGETPLATFORM
ARG VERSION ARG VERSION
ARG COMMIT ARG COMMIT
WORKDIR /src WORKDIR /src
# Copy project file and restore dependencies # Copy project file and restore dependencies
COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"] COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"]
# Map platform to .NET runtime identifier and restore # Map platform to .NET runtime identifier and restore
RUN case "$TARGETPLATFORM" in \ RUN case "$TARGETPLATFORM" in \
"linux/amd64") RID="linux-x64" ;; \ "linux/amd64") RID="linux-x64" ;; \
"linux/arm64") RID="linux-arm64" ;; \ "linux/arm64") RID="linux-arm64" ;; \
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac && \ esac && \
echo "🔧 Restoring for RID: $RID" && \ echo "🔧 Restoring for RID: $RID" && \
dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID
# Copy source code # Copy source code
COPY . . COPY . .
WORKDIR "/src/src/BCards.Web" WORKDIR "/src/src/BCards.Web"
# Publish diretamente (build + publish em um comando) # Publish diretamente (build + publish em um comando)
RUN case "$TARGETPLATFORM" in \ RUN case "$TARGETPLATFORM" in \
"linux/amd64") RID="linux-x64" ;; \ "linux/amd64") RID="linux-x64" ;; \
"linux/arm64") RID="linux-arm64" ;; \ "linux/arm64") RID="linux-arm64" ;; \
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac && \ esac && \
echo "📦 Publishing for RID: $RID" && \ echo "📦 Publishing for RID: $RID" && \
dotnet publish "BCards.Web.csproj" \ dotnet publish "BCards.Web.csproj" \
-c Release \ -c Release \
-o /app/publish \ -o /app/publish \
--no-restore \ --no-restore \
--runtime $RID \ --runtime $RID \
--self-contained false \ --self-contained false \
-p:PublishReadyToRun=false \ -p:PublishReadyToRun=false \
-p:PublishSingleFile=false \ -p:PublishSingleFile=false \
-p:UseAppHost=false \ -p:UseAppHost=false \
-p:Version=$VERSION \ -p:Version=$VERSION \
-p:InformationalVersion=$COMMIT -p:InformationalVersion=$COMMIT
# Final stage - runtime optimized for Release environment # Final stage - runtime optimized for Release environment
FROM base AS final FROM base AS final
ARG VERSION=0.0.1 ARG VERSION=0.0.1
ARG COMMIT=unknown ARG COMMIT=unknown
ARG TARGETPLATFORM ARG TARGETPLATFORM
# Metadata labels # Metadata labels
LABEL maintainer="BCards Team" LABEL maintainer="BCards Team"
LABEL version=$VERSION LABEL version=$VERSION
LABEL commit=$COMMIT LABEL commit=$COMMIT
LABEL platform=$TARGETPLATFORM LABEL platform=$TARGETPLATFORM
LABEL environment="release" LABEL environment="release"
WORKDIR /app WORKDIR /app
# Copy published application # Copy published application
COPY --from=build /app/publish . COPY --from=build /app/publish .
# Create non-root user for security # Create non-root user for security
RUN groupadd -r bcards && useradd -r -g bcards bcards \ RUN groupadd -r bcards && useradd -r -g bcards bcards \
&& chown -R bcards:bcards /app && chown -R bcards:bcards /app
# Environment variables for Release # Environment variables for Release
ENV ASPNETCORE_ENVIRONMENT=Release ENV ASPNETCORE_ENVIRONMENT=Release
ENV ASPNETCORE_URLS=http://+:8080 ENV ASPNETCORE_URLS=http://+:8080
ENV DOTNET_RUNNING_IN_CONTAINER=true ENV DOTNET_RUNNING_IN_CONTAINER=true
ENV DOTNET_EnableDiagnostics=0 ENV DOTNET_EnableDiagnostics=0
ENV DOTNET_USE_POLLING_FILE_WATCHER=true ENV DOTNET_USE_POLLING_FILE_WATCHER=true
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
# Platform-specific optimizations # Platform-specific optimizations
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
echo "🔧 Applying ARM64 optimizations..." && \ echo "🔧 Applying ARM64 optimizations..." && \
echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \
echo 'export DOTNET_TC_QuickJitForLoops=1' >> /etc/environment && \ echo 'export DOTNET_TC_QuickJitForLoops=1' >> /etc/environment && \
echo 'export DOTNET_ReadyToRun=0' >> /etc/environment; \ echo 'export DOTNET_ReadyToRun=0' >> /etc/environment; \
else \ else \
echo "🔧 Applying AMD64 optimizations..." && \ echo "🔧 Applying AMD64 optimizations..." && \
echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \
echo 'export DOTNET_ReadyToRun=1' >> /etc/environment; \ echo 'export DOTNET_ReadyToRun=1' >> /etc/environment; \
fi fi
# Health check endpoint # Health check endpoint
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1 CMD curl -f http://localhost:8080/health || exit 1
# Switch to non-root user # Switch to non-root user
USER bcards USER bcards
# Entry point with optimized runtime settings # Entry point with optimized runtime settings
ENTRYPOINT ["dotnet", "BCards.Web.dll"] ENTRYPOINT ["dotnet", "BCards.Web.dll"]