CI / CD / Unit tests (push) Successful in 38s
CI / CD / Build & push Helm chart (push) Failing after 7s
CI / CD / Build & push frontend-static (push) Successful in 28s
CI / CD / Build & push frontend (nginx) (push) Successful in 28s
CI / CD / Build & push backend (push) Successful in 1m55s
208 lines
7.2 KiB
YAML
208 lines
7.2 KiB
YAML
name: CI / CD
|
|
|
|
on:
|
|
push:
|
|
branches: ['**']
|
|
tags: ['v*']
|
|
pull_request:
|
|
|
|
env:
|
|
REGISTRY: code.kruzya.dev
|
|
# backend: api + bot + migrator (единый образ, разные CMD)
|
|
BACKEND_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/backend
|
|
# frontend: miniapp nginx (для docker-compose)
|
|
FRONTEND_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/frontend
|
|
# frontend-static: FROM scratch, используется как image volume в k8s
|
|
FRONTEND_STATIC_IMAGE: code.kruzya.dev/crazyhackgut/telegrammemevault/frontend-static
|
|
|
|
jobs:
|
|
# ─────────────────────────────── TESTS ──────────────────────────────────────
|
|
test:
|
|
name: Unit tests
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '10.0.x'
|
|
|
|
- name: Restore
|
|
run: dotnet restore MemeVault.sln
|
|
|
|
- name: Test
|
|
run: |
|
|
dotnet test src/MemeVault.Tests.Unit \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--logger "console;verbosity=normal"
|
|
|
|
# ─────────────────────────────── HELM ───────────────────────────────────────
|
|
build-helm:
|
|
name: Build & push Helm chart
|
|
needs: test
|
|
if: github.event_name == 'push' && github.ref_type == 'tag'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Compute chart version
|
|
id: meta
|
|
run: |
|
|
VERSION="${GITHUB_REF_NAME#v}"
|
|
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to registry
|
|
run: |
|
|
helm registry login ${{ env.REGISTRY }} \
|
|
--username CrazyHackGUT \
|
|
--password ${{ secrets.IMAGE_PUSH_TOKEN }}
|
|
|
|
- name: Package and push
|
|
run: |
|
|
helm package helm/memevault --version ${{ steps.meta.outputs.version }}
|
|
helm push memevault-${{ steps.meta.outputs.version }}.tgz \
|
|
oci://${{ env.REGISTRY }}/crazyhackgut/telegrammemevault
|
|
|
|
# ─────────────────────────────── BACKEND ────────────────────────────────────
|
|
build-backend:
|
|
name: Build & push backend
|
|
needs: test
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Compute image tags
|
|
id: meta
|
|
run: |
|
|
SHA="${GITHUB_SHA:0:12}"
|
|
SAFE_REF=$(echo "$GITHUB_REF_NAME" \
|
|
| tr '[:upper:]' '[:lower:]' \
|
|
| sed 's/[^a-z0-9._-]/-/g')
|
|
IMG="${{ env.BACKEND_IMAGE }}"
|
|
TAGS="${IMG}:sha-${SHA},${IMG}:${SAFE_REF}"
|
|
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
|
|
TAGS="${TAGS},${IMG}:latest"
|
|
fi
|
|
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: CrazyHackGUT
|
|
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE }}:cache
|
|
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE }}:cache,mode=max
|
|
|
|
# ─────────────────────── FRONTEND-STATIC (FROM scratch) ─────────────────────
|
|
build-frontend-static:
|
|
name: Build & push frontend-static
|
|
needs: test
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
packages: write
|
|
outputs:
|
|
# Передаём точный sha-тег следующему джобу
|
|
image: ${{ steps.meta.outputs.image }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Compute image tags
|
|
id: meta
|
|
run: |
|
|
SHA="${GITHUB_SHA:0:12}"
|
|
SAFE_REF=$(echo "$GITHUB_REF_NAME" \
|
|
| tr '[:upper:]' '[:lower:]' \
|
|
| sed 's/[^a-z0-9._-]/-/g')
|
|
IMG="${{ env.FRONTEND_STATIC_IMAGE }}"
|
|
TAGS="${IMG}:sha-${SHA},${IMG}:${SAFE_REF}"
|
|
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
|
|
TAGS="${TAGS},${IMG}:latest"
|
|
fi
|
|
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
|
|
echo "image=${IMG}:sha-${SHA}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: CrazyHackGUT
|
|
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: miniapp
|
|
file: miniapp/Dockerfile.frontend
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
cache-from: type=registry,ref=${{ env.FRONTEND_STATIC_IMAGE }}:cache
|
|
cache-to: type=registry,ref=${{ env.FRONTEND_STATIC_IMAGE }}:cache,mode=max
|
|
|
|
# ─────────────────────── FRONTEND (nginx поверх static) ─────────────────────
|
|
build-frontend:
|
|
name: Build & push frontend (nginx)
|
|
needs: build-frontend-static
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Compute image tags
|
|
id: meta
|
|
run: |
|
|
SHA="${GITHUB_SHA:0:12}"
|
|
SAFE_REF=$(echo "$GITHUB_REF_NAME" \
|
|
| tr '[:upper:]' '[:lower:]' \
|
|
| sed 's/[^a-z0-9._-]/-/g')
|
|
IMG="${{ env.FRONTEND_IMAGE }}"
|
|
TAGS="${IMG}:sha-${SHA},${IMG}:${SAFE_REF}"
|
|
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
|
|
TAGS="${TAGS},${IMG}:latest"
|
|
fi
|
|
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: CrazyHackGUT
|
|
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: miniapp
|
|
file: miniapp/Dockerfile.nginx
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
# Передаём точный тег собранного frontend-static
|
|
build-args: |
|
|
STATIC_IMAGE=${{ needs.build-frontend-static.outputs.image }}
|
|
cache-from: type=registry,ref=${{ env.FRONTEND_IMAGE }}:cache
|
|
cache-to: type=registry,ref=${{ env.FRONTEND_IMAGE }}:cache,mode=max
|