ci: build images with Kaniko jobs instead of a privileged Docker daemon
This commit is contained in:
1 parent
05c271677b
commit
390f72e53a
2 files changed
+102
-40
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user