Skip to content

Fix worker logs process #59

Fix worker logs process

Fix worker logs process #59

Workflow file for this run

name: CI/CD WriteFluency
on:
push:
tags:
- '*.*.*'
env:
GITHUB_ACTIONS: true
Jwt__Key: ${{ secrets.Jwt__Key }}
Authentication__Google__ClientId: ${{ secrets.Authentication__Google__ClientId }}
Authentication__Google__ClientSecret: ${{ secrets.Authentication__Google__ClientSecret }}
ExternalApis__OpenAI__Key: ${{ secrets.ExternalApis__OpenAI__Key }}
ExternalApis__TextToSpeech__Key: ${{ secrets.ExternalApis__TextToSpeech__Key }}
ExternalApis__News__Key: ${{ secrets.ExternalApis__News__Key }}
APPLICATIONINSIGHTS_CONNECTION_STRING: ${{ secrets.APPLICATIONINSIGHTS_CONNECTION_STRING }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
MINIO_ROOT_PASSWORD: ${{ secrets.MINIO_ROOT_PASSWORD }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_API_TOKEN_CACHE: ${{ secrets.CLOUDFLARE_API_TOKEN_CACHE }}
Propositions__DailyRequestsLimit: ${{ vars.Propositions__DailyRequestsLimit }}
Propositions__LimitPerTopic: ${{ vars.Propositions__LimitPerTopic }}
Propositions__NewsRequestLimit: ${{ vars.Propositions__NewsRequestLimit }}
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
jobs:
deploy:
runs-on: ubuntu-latest
env:
K8S_IMAGE_TAG: ${{ github.ref_name }}
KUBE_CONTEXT: github-context
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22.12.x'
cache: 'npm'
cache-dependency-path: 'src/webapp/package-lock.json'
- name: Install webapp dependencies
working-directory: ./src/webapp
run: npm ci
- name: Run Angular tests
working-directory: ./src/webapp
run: npm test -- --no-watch --no-progress --browsers=ChromeHeadless
- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Run .NET Tests
run: dotnet test
- name: Install Aspirate
run: dotnet tool install --global aspirate --version 9.1.0
- name: Add .dotnet tools to PATH
run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH
- name: Configure kubeconfig using Service Account
run: |
mkdir -p ~/.kube
cat <<EOF > ~/.kube/config
apiVersion: v1
kind: Config
clusters:
- cluster:
server: ${{ secrets.KUBE_SERVER }}
certificate-authority-data: ${{ secrets.KUBE_CA }}
name: cluster
contexts:
- context:
cluster: cluster
user: github
name: github-context
current-context: github-context
users:
- name: github
user:
token: ${{ secrets.KUBE_TOKEN }}
EOF
- name: Turn scripts executable
run: |
chmod +x ./src/host/WriteFluency.AppHost/build-k8s-images.sh
chmod +x ./src/host/WriteFluency.AppHost/deploy-k8s.sh
chmod +x ./src/host/WriteFluency.AppHost/generate-k8s-secret.sh
- name: Login no GitHub Container Registry (GHCR)
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
- name: Build Images
working-directory: ./src/host/WriteFluency.AppHost
run: ./build-k8s-images.sh $K8S_IMAGE_TAG
- name: Purge Cloudflare cache
if: success()
env:
CLOUDFLARE_ZONE_NAME: writefluency.com
CLOUDFLARE_ZONE_ID: 7441ef61fbb296b61b4cb4e418f4ebc6
run: |
set -euo pipefail
CF_TOKEN="${CLOUDFLARE_API_TOKEN_CACHE:-$CLOUDFLARE_API_TOKEN}"
if [ -z "${CF_TOKEN}" ]; then
echo "CLOUDFLARE_API_TOKEN_CACHE or CLOUDFLARE_API_TOKEN is required."
exit 1
fi
ZONE_ID="${CLOUDFLARE_ZONE_ID:-}"
if [ -z "${ZONE_ID}" ] || [ "${ZONE_ID}" = "null" ]; then
echo "Cloudflare zone id not found. Set CLOUDFLARE_ZONE_ID."
exit 1
fi
echo "Purging Cloudflare cache for zone ${ZONE_ID}..."
response="$(curl -sS -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
-H "Authorization: Bearer ${CF_TOKEN}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}')"
echo "${response}" | jq
success="$(echo "${response}" | jq -r '.success')"
if [ "${success}" != "true" ]; then
echo "Cloudflare purge failed."
exit 1
fi
- name: Deploy to Cluster
working-directory: ./src/host/WriteFluency.AppHost
run: ./deploy-k8s.sh $KUBE_CONTEXT