ci: add Gitea Actions workflow with BuildKit
Some checks failed
Build and Deploy / build (push) Failing after 23m52s
Some checks failed
Build and Deploy / build (push) Failing after 23m52s
This commit is contained in:
@@ -1,60 +1,76 @@
|
|||||||
name: Build and Push to GHCR
|
name: Build and Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [master, main]
|
branches: [master, main]
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: ghcr.io
|
|
||||||
IMAGE_NAME: ${{ github.repository }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Trigger BuildKit Build
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Log in to Container Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Extract metadata
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
||||||
tags: |
|
|
||||||
type=sha,prefix=,suffix=,format=short
|
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
|
||||||
- name: Update kustomization.yaml
|
|
||||||
run: |
|
run: |
|
||||||
COMMIT_SHA=${{ github.sha }}
|
echo "Building commit: ${GITHUB_SHA}"
|
||||||
SHORT_SHA=${COMMIT_SHA:0:7}
|
|
||||||
sed -i "s|newTag: .*|newTag: ${SHORT_SHA}|" k8s/kustomization.yaml
|
# Delete old job
|
||||||
|
kubectl delete job build-manoon-headless-action -n gitea --ignore-not-found=true 2>/dev/null || true
|
||||||
- name: Commit and push changes
|
|
||||||
run: |
|
# Create build job
|
||||||
git config --local user.email "gitea-actions[bot]@users.noreply.gitea.io"
|
kubectl apply -f - << EOF
|
||||||
git config --local user.name "gitea-actions[bot]"
|
apiVersion: batch/v1
|
||||||
git add k8s/kustomization.yaml
|
kind: Job
|
||||||
git diff --quiet && git diff --staged --quiet || git commit -m "deploy: update image to ${SHORT_SHA} [skip ci]"
|
metadata:
|
||||||
git push
|
name: build-manoon-headless-action
|
||||||
|
namespace: gitea
|
||||||
|
spec:
|
||||||
|
ttlSecondsAfterFinished: 86400
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
restartPolicy: Never
|
||||||
|
initContainers:
|
||||||
|
- name: clone
|
||||||
|
image: alpine/git:latest
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
set -e
|
||||||
|
git clone --depth 1 http://gitea:3000/unchained/manoon-headless.git /workspace
|
||||||
|
cd /workspace && git checkout ${GITHUB_SHA}
|
||||||
|
echo "Building: \$(git rev-parse --short HEAD)"
|
||||||
|
volumeMounts:
|
||||||
|
- name: workspace
|
||||||
|
mountPath: /workspace
|
||||||
|
containers:
|
||||||
|
- name: build
|
||||||
|
image: moby/buildkit:latest
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
set -e
|
||||||
|
mkdir -p /root/.docker
|
||||||
|
cp /docker-config/.dockerconfigjson /root/.docker/config.json
|
||||||
|
buildctl --addr tcp://buildkit.gitea.svc.cluster.local:1234 build \
|
||||||
|
--frontend dockerfile.v0 \
|
||||||
|
--local context=/workspace \
|
||||||
|
--local dockerfile=/workspace \
|
||||||
|
--output type=image,name=ghcr.io/unchainedio/manoon-headless:latest,push=true
|
||||||
|
kubectl annotate kustomization -n flux-system manoonoils-storefront --overwrite reconcile.fluxcd.io/requestedAt="\$(date +%s)"
|
||||||
|
echo "Done!"
|
||||||
|
volumeMounts:
|
||||||
|
- name: workspace
|
||||||
|
mountPath: /workspace
|
||||||
|
- name: docker-config
|
||||||
|
mountPath: /docker-config
|
||||||
|
readOnly: true
|
||||||
|
volumes:
|
||||||
|
- name: workspace
|
||||||
|
emptyDir: {}
|
||||||
|
- name: docker-config
|
||||||
|
secret:
|
||||||
|
secretName: ghcr-pull-secret
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Build job created!"
|
||||||
|
kubectl wait --for=condition=complete job/build-manoon-headless-action -n gitea --timeout=600s || echo "Build running in background"
|
||||||
|
|||||||
Reference in New Issue
Block a user