121 lines
4.4 KiB
YAML
121 lines
4.4 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
schedule:
|
|
# Saturday 05:00 UTC: 06:00 in Paris in winter, 07:00 in summer (Gitea runs cron in UTC).
|
|
- cron: "0 5 * * 6"
|
|
|
|
jobs:
|
|
build-and-scan:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
persist-credentials: false
|
|
|
|
- name: Get shared actions
|
|
uses: actions/checkout@v7
|
|
with:
|
|
repository: labeex/cicdeex
|
|
ref: 1.0.0
|
|
token: ${{ secrets.CICDEEX_TOKEN }}
|
|
path: .cicdeex
|
|
persist-credentials: false
|
|
|
|
- name: Scan for secrets
|
|
uses: ./.cicdeex/secret-scan
|
|
|
|
- name: Lint Dockerfile with hadolint
|
|
uses: ./.cicdeex/hadolint
|
|
|
|
- name: Build Docker image
|
|
run: docker build -t socat-proxy:ci .
|
|
|
|
- name: Smoke test (syntax check)
|
|
run: docker run --rm --entrypoint sh socat-proxy:ci -n /entrypoint.sh
|
|
|
|
- name: Run unit tests
|
|
run: |
|
|
docker build --target test -t socat-proxy:test .
|
|
docker run --rm socat-proxy:test bats /app/tests/entrypoint.bats
|
|
|
|
- name: Lint entrypoint.sh with shellcheck
|
|
run: docker build --target lint -t socat-proxy:lint .
|
|
|
|
- name: Scan with Trivy (critical - blocking)
|
|
id: trivy_critical
|
|
continue-on-error: true
|
|
uses: ./.cicdeex/trivy
|
|
with:
|
|
image: socat-proxy:ci
|
|
|
|
- name: Handle CRITICAL findings
|
|
if: steps.trivy_critical.outcome == 'failure'
|
|
run: |
|
|
if [ "${{ github.event_name }}" != "schedule" ]; then
|
|
echo "::error::CRITICAL vulnerabilities found, failing the build."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Scheduled scan found CRITICAL vulnerabilities — attempting an automatic apk upgrade + rescan."
|
|
|
|
sed -i '/^FROM .* AS base$/a RUN apk upgrade --no-cache' Dockerfile
|
|
docker build -t socat-proxy:remediated .
|
|
|
|
if docker run --rm \
|
|
-e DOCKER_HOST=tcp://dockerhost:2375 \
|
|
--add-host=dockerhost:host-gateway \
|
|
aquasec/trivy:0.76.2 image --exit-code 1 --severity CRITICAL socat-proxy:remediated; then
|
|
echo "apk upgrade clears the CRITICAL finding(s) — opening a PR for review."
|
|
|
|
BRANCH="auto/cve-fix-$(date +%Y%m%d)-$(echo "${{ github.sha }}" | cut -c1-7)"
|
|
git config user.name "socat-proxy-ci"
|
|
git config user.email "[email protected]"
|
|
git checkout -b "$BRANCH"
|
|
git add Dockerfile
|
|
git commit -m "Auto-remediate CRITICAL CVE via apk upgrade"
|
|
git config --unset-all http.https://git.djeex.fr/.extraheader || true
|
|
git push "https://Djeex:${{ secrets.CI_PUSH_TOKEN }}@git.djeex.fr/Djeex/socat-proxy.git" "HEAD:$BRANCH"
|
|
|
|
PR_JSON=$(curl -s -X POST \
|
|
-H "Authorization: token ${{ secrets.CI_PUSH_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$(jq -n --arg head "$BRANCH" '{title: "🔒 Auto: remediate CRITICAL CVE via apk upgrade", head: $head, base: "main", body: "Opened automatically by the scheduled CVE scan. An `apk upgrade --no-cache` cleared the CRITICAL Trivy finding(s) in a rebuild — review the diff and merge to publish the fix."}')" \
|
|
"https://git.djeex.fr/api/v1/repos/Djeex/socat-proxy/pulls")
|
|
echo "PR API response: $(echo "$PR_JSON" | jq -r '.html_url // .message // "unknown"')"
|
|
else
|
|
echo "::error::apk upgrade does not clear the CRITICAL finding(s) — no automatic fix available, needs manual review."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Scan with Trivy (high - informative)
|
|
uses: ./.cicdeex/trivy
|
|
with:
|
|
image: socat-proxy:ci
|
|
severity: HIGH
|
|
exit-code: "0"
|
|
|
|
- name: Publish tagged image
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
uses: ./.cicdeex/publish
|
|
with:
|
|
image: socat-proxy:ci
|
|
paths: '^(Dockerfile|entrypoint\.sh|VERSION)$'
|
|
push-token: ${{ secrets.CI_PUSH_TOKEN }}
|
|
registry-token: ${{ secrets.REGISTRY_TOKEN }}
|
|
github-mirror: "true"
|
|
github-token: ${{ secrets.GH_TOKEN }}
|
|
|
|
- name: Notify failures
|
|
if: always()
|
|
uses: ./.cicdeex/notify
|
|
with:
|
|
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
status: ${{ job.status }}
|