Files
hello-devops/.gitea/workflows/ci.yaml
T
josephandClaude Opus 5.5 c506ea5735
build-scan-deploy / sonarqube (push) Successful in 49s
build-scan-deploy / build (push) Successful in 2m36s
ci: add SonarQube scan job
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-21 20:42:21 +03:00

53 lines
2.2 KiB
YAML

name: build-scan-deploy
on:
push:
branches: [main]
paths-ignore: ["k8s/**"]
workflow_dispatch:
env:
REGISTRY: 192.168.0.43:3000
IMAGE: 192.168.0.43:3000/joseph/hello-devops
jobs:
# Code-quality scan on SonarQube (ops VM 106, https://sonar.labjom.com). Informational only: it never blocks a deploy.
# Uses the user-level secret SONAR_TOKEN and variable SONAR_HOST_URL set in Gitea (joseph > Settings > Actions).
sonarqube:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}
- name: SonarQube scan
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
run: >
npx --yes @sonar/scan
-Dsonar.projectKey=hello-devops -Dsonar.projectName=hello-devops
-Dsonar.exclusions="**/node_modules/**,**/bin/**,**/obj/**,**/dist/**,**/.angular/**"
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: {token: "${{ secrets.REGISTRY_TOKEN }}"}
- name: Install docker CLI
run: curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz | tar xz --strip-components=1 -C /usr/local/bin docker/docker
- name: Lint Dockerfile
run: docker run --rm -i hadolint/hadolint < Dockerfile || true
- name: Build image
run: |
TAG=${GITHUB_SHA::7}
echo "TAG=$TAG" >> $GITHUB_ENV
docker build --build-arg VERSION=$TAG -t $IMAGE:$TAG -t $IMAGE:latest .
- name: Scan with Trivy (fail on CRITICAL)
run: docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:latest image --severity CRITICAL --exit-code 1 --ignore-unfixed $IMAGE:$TAG
- name: Push to Gitea registry
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login $REGISTRY -u joseph --password-stdin
docker push $IMAGE:$TAG && docker push $IMAGE:latest
- name: GitOps - bump image tag
run: |
sed -i "s#image: .*hello-devops:.*#image: $IMAGE:$TAG#" k8s/app.yaml
git config user.name "gitea-actions"; git config user.email "[email protected]"
git commit -am "deploy: hello-devops $TAG [skip ci]" && git push