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: 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 "ci@lab.local" git commit -am "deploy: hello-devops $TAG [skip ci]" && git push