ci: build images with Kaniko jobs instead of a privileged Docker daemon
CI/CD Pipeline / test (push) Failing after 0s
CI/CD Pipeline / build-push-deploy (push) Skipped

This commit is contained in:
kaliouich committed 2026-10-26 09:05:09 +00:00
1 parent 05c271677b
commit 390f72e53a
2 files changed
+102 -40

No files matched your search

+31 -40
View File
@@ -7,62 +7,53 @@ on:
- 'api-deployment.yaml'
- 'frontend-deployment.yaml'
env:
GIT_SSL_NO_VERIFY: "true"
NODE_TLS_REJECT_UNAUTHORIZED: "0"
# Runner en mode hote, sans daemon Docker : les images sont construites par des
# Jobs Kaniko (namespace ci-builds). Aucune action tierce n'est telechargee.
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies and test API
working-directory: ./api
run: npm install && node -c server.js
- name: Checkout
run: |
git clone -q "http://gitea-http.gitea.svc.cluster.local:3000/${{ github.repository }}.git" src
git -C src checkout -q "${{ github.sha }}"
- name: Install dependencies and check the API
working-directory: src/api
run: npm install --ignore-scripts && node -c server.js
build-push-deploy:
runs-on: ubuntu-latest
needs: test
permissions:
packages: write
contents: write
env:
DOCKER_HOST: tcp://localhost:2375
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Log in to Gitea Container Registry
run: echo "${{ secrets.CR_PAT }}" | docker login https://git.khalilaliouich.com -u ${{ github.actor }} --password-stdin
- name: Build and Push API
- name: Build images with Kaniko
run: |
docker build --network=host -t git.khalilaliouich.com/${{ github.repository_owner }}/tamagotchi-api:${{ github.sha }} ./api
docker push git.khalilaliouich.com/${{ github.repository_owner }}/tamagotchi-api:${{ github.sha }}
set -eu
git clone -q "http://gitea-http.gitea.svc.cluster.local:3000/${{ github.repository }}.git" src
git -C src checkout -q "${{ github.sha }}"
export SHA="${{ github.sha }}" RUN_ID="${{ github.run_id }}"
for pair in tamagotchi-api:api tamagotchi-frontend:frontend; do
export IMAGE="${pair%%:*}" CONTEXT_DIR="${pair##*:}"
envsubst '${IMAGE} ${CONTEXT_DIR} ${SHA} ${RUN_ID}' < src/ci/kaniko-job.yaml | kubectl create -f -
done
for img in tamagotchi-api tamagotchi-frontend; do
kubectl -n ci-builds wait --for=condition=complete --timeout=20m "job/build-${img}-${RUN_ID}" || {
kubectl -n ci-builds logs "job/build-${img}-${RUN_ID}" --all-containers --tail=50 || true
exit 1
}
done
- name: Build and Push Frontend
run: |
docker build --network=host -t git.khalilaliouich.com/${{ github.repository_owner }}/tamagotchi-frontend:${{ github.sha }} ./frontend
docker push git.khalilaliouich.com/${{ github.repository_owner }}/tamagotchi-frontend:${{ github.sha }}
- name: Update Kubernetes Manifests
- name: Update Kubernetes manifests
working-directory: src
run: |
sed -i "s|image: .*tamagotchi-api:.*|image: git.khalilaliouich.com/${{ github.repository_owner }}/tamagotchi-api:${{ github.sha }}|g" api-deployment.yaml
sed -i "s|image: .*tamagotchi-frontend:.*|image: git.khalilaliouich.com/${{ github.repository_owner }}/tamagotchi-frontend:${{ github.sha }}|g" frontend-deployment.yaml
- name: Commit and Push changes
- name: Commit and push
working-directory: src
run: |
git config --global user.name "gitea-actions[bot]"
git config --global user.email "gitea-actions@gitea.local"
# Force the push to use the PAT token explicitely
git remote set-url origin http://${{ github.actor }}:${{ secrets.CR_PAT }}@gitea-http.gitea.svc.cluster.local:3000/${{ github.repository }}.git
git config user.name "gitea-actions[bot]"
git config user.email "gitea-actions@gitea.local"
git remote set-url origin "http://${{ github.actor }}:${{ secrets.CR_PAT }}@gitea-http.gitea.svc.cluster.local:3000/${{ github.repository }}.git"
git add api-deployment.yaml frontend-deployment.yaml
git commit -m "chore: deploy version ${{ github.sha }} [skip ci]" || echo "No changes to commit"
git push origin main
+71
View File
@@ -0,0 +1,71 @@
# Modele du Job de build, rempli par le workflow avec envsubst.
# Variables : IMAGE (tamagotchi-api | tamagotchi-frontend), CONTEXT_DIR (api |
# frontend), SHA, RUN_ID.
# Les identifiants viennent de deux Secrets crees d'avance dans ci-builds :
# ci-git (username, password) : jeton en lecture seule pour le clone ;
# ci-registry (config.json) : jeton d'ecriture limite aux paquets.
# Le workflow n'a jamais acces a leur valeur.
apiVersion: batch/v1
kind: Job
metadata:
name: build-${IMAGE}-${RUN_ID}
namespace: ci-builds
spec:
backoffLimit: 0
activeDeadlineSeconds: 1200
ttlSecondsAfterFinished: 900
template:
metadata:
annotations:
linkerd.io/inject: disabled
spec:
restartPolicy: Never
automountServiceAccountToken: false
initContainers:
- name: clone
image: gitea-runner-ci:v1
imagePullPolicy: Never
command: [sh, -ec]
args:
- |
git clone -q http://gitea-http.gitea.svc.cluster.local:3000/khalil/tamagotchi-service.git /ws/src
git -C /ws/src checkout -q ${SHA}
env:
- { name: GIT_CONFIG_COUNT, value: "1" }
- { name: GIT_CONFIG_KEY_0, value: credential.helper }
- { name: GIT_CONFIG_VALUE_0, value: "!f() { echo username=$GIT_USER; echo password=$GIT_TOKEN; }; f" }
- name: GIT_USER
valueFrom: { secretKeyRef: { name: ci-git, key: username } }
- name: GIT_TOKEN
valueFrom: { secretKeyRef: { name: ci-git, key: password } }
securityContext:
allowPrivilegeEscalation: false
capabilities: { drop: [ALL] }
resources:
requests: { cpu: 10m, memory: 64Mi }
limits: { memory: 512Mi }
volumeMounts:
- { name: ws, mountPath: /ws }
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:v1.24.0
args:
- --context=/ws/src/${CONTEXT_DIR}
- --destination=gitea-http.gitea.svc.cluster.local:3000/khalil/${IMAGE}:${SHA}
- --insecure
- --cache=false
- --snapshot-mode=redo
resources:
requests: { cpu: 50m, memory: 256Mi }
limits: { memory: 2Gi }
volumeMounts:
- { name: ws, mountPath: /ws }
- { name: registry, mountPath: /kaniko/.docker, readOnly: true }
volumes:
- name: ws
emptyDir: {}
- name: registry
secret:
secretName: ci-registry
items:
- { key: config.json, path: config.json }