Files

159 lines
5.5 KiB
YAML

on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
name: Build Docker images with Sentry
permissions:
contents: read
packages: write
id-token: write
jobs:
# Blocking gate: the release image is only built if the web E2E run passes on this tag.
web_e2e:
name: Run web integration tests
uses: ./.github/workflows/reusable-web-integration-test.yaml
build-release-image-with-sentry:
name: Build release image with Sentry
needs: web_e2e
if: github.event_name == 'workflow_dispatch' || (github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Extract app version from pubspec.yaml
id: app_version
run: |
VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Docker metadata
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: |
${{ github.repository_owner }}/tmail-web
ghcr.io/${{ github.repository_owner }}/tmail-web
tags: |
type=ref,event=tag
type=raw,value=release
- name: Login to Docker Hub
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image (release)
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
cache-from: |
type=gha
cache-to: |
type=gha
secrets: |
sentry_auth_token=${{ secrets.SENTRY_AUTH_TOKEN }}
build-args: |
FLUTTER_VERSION=3.47.9
SENTRY_UPLOAD=1
SENTRY_ORG=${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }}
SENTRY_URL=${{ secrets.SENTRY_URL }}
SENTRY_RELEASE=${{ steps.app_version.outputs.version }}
GITHUB_SHA=${{ github.sha }}
VCS_REF=${{ github.repository }}@${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Extract sourcemaps from Docker image
if: always()
run: |
# Get the first image tag (for amd64 platform)
IMAGE_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
if [ -z "$IMAGE_TAG" ]; then
echo "No image tag found, skipping sourcemap extraction"
exit 0
fi
echo "Extracting sourcemaps from image: $IMAGE_TAG"
# Create temporary container to extract files
CONTAINER_ID=$(docker create --platform linux/amd64 "$IMAGE_TAG" 2>/dev/null | head -n1)
if [ -n "$CONTAINER_ID" ]; then
echo "Created container: $CONTAINER_ID"
# Create directory for sourcemaps
mkdir -p sourcemaps
# Copy all files from container
docker cp "$CONTAINER_ID:/usr/share/nginx/html/." sourcemaps/ 2>/dev/null || true
# Remove container
docker rm "$CONTAINER_ID" 2>/dev/null || true
# Filter only .map files and keep directory structure
find sourcemaps -type f ! -name "*.map" -delete 2>/dev/null || true
echo "Sourcemaps extracted:"
find sourcemaps -name "*.map" | head -10 || echo "No .map files found"
MAP_COUNT=$(find sourcemaps -name "*.map" 2>/dev/null | wc -l)
echo "Total .map files: $MAP_COUNT"
else
echo "Warning: Could not create container from image"
fi
- name: Upload sourcemaps as artifact
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: sourcemaps-${{ steps.app_version.outputs.version }}
path: sourcemaps/**/*.map
retention-days: 30
if-no-files-found: warn
security-release-scan:
name: Security release scan
needs: build-release-image-with-sentry
# manual image builds aren't release tags
if: github.event_name == 'push'
permissions:
contents: read
actions: read
uses: ./.github/workflows/security-release.yaml # zizmor: ignore[self-repository]
# the report secrets must reach the called workflow
secrets: inherit # zizmor: ignore[secrets-inherit]
memory-leak-check:
name: Memory leak check
# manual image builds aren't release tags
if: github.event_name == 'push'
permissions:
contents: read
uses: ./.github/workflows/memory-leak-check.yaml # zizmor: ignore[self-repository]