This repository was archived by the owner on May 5, 2026. It is now read-only.
forked from open-webui/open-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (167 loc) · 6.83 KB
/
Copy pathionos-dev-docker-build.yaml
File metadata and controls
182 lines (167 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: OpenWebUI Docker Build
on:
workflow_dispatch:
push:
branches:
- ionos-dev
- 'ts**'
- 'tl/ci-test-**'
tags:
- 'ionos-**'
- 'snap-**'
- 'live-**'
env:
JOB_NAME: openwebui-build-push-image
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
REGISTRY_HOST: ${{ vars.REGISTRY_HOST }}
REGISTRY_URL: ${{ vars.REGISTRY_HOST }}${{ vars.REGISTRY_PATH }}
jobs:
build:
runs-on: self-hosted
permissions:
contents: read
issues: write
steps:
- name: Set TIMESTAMP variable
run: echo "TIMESTAMP=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Install kubectl
uses: azure/setup-kubectl@v4
id: install
with:
version: 'latest'
- name: Create Docker Secret Config for Kaniko
run: |
mkdir -p $HOME/.docker
AUTH="$(echo -n "${HARBOR_USERNAME}:${HARBOR_PASSWORD}" | base64 -w0 )"
echo "{\"auths\":{\"${REGISTRY_HOST}\":{\"auth\":\"${AUTH}\"}}}" > $HOME/.docker/config.json
set +e
kubectl get secret dock-sec -n arc-runners
if [ $? -eq 0 ]; then
echo "dock-sec already exists, deleting it ..."
kubectl delete secret -n arc-runners dock-sec --ignore-not-found
fi
echo "Create docker-sec ..."
kubectl create secret generic dock-sec --from-file=config.json=$HOME/.docker/config.json --namespace=arc-runners
set -e
env:
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
- name: Create and Apply Kaniko Job
run: |
set +e
# Check if the job exists
kubectl get job ${{ env.JOB_NAME }} -n arc-runners
if [ $? -eq 0 ]; then
echo "Job gpt-build-push-image, deleting it..."
kubectl delete job ${{ env.JOB_NAME }} -n arc-runners --ignore-not-found
fi
# Create a new job
echo "
apiVersion: batch/v1
kind: Job
metadata:
name: openwebui-build-push-image
namespace: arc-runners
spec:
template:
spec:
initContainers:
- name: git-clone
image: alpine/git
command: ["/bin/sh", "-c"]
args:
- |
git config --global url."https://oauth:${TOKEN}@github.com/".insteadOf "https://github.com/" &&
git clone --recursive -b ${{ env.BRANCH_NAME }} --depth=1 https://github.com/${{ github.repository }}.git /workspace
volumeMounts:
- name: build-context
mountPath: /workspace
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:latest
args:
- --dockerfile=./Dockerfile
- --context=dir:///workspace
- --destination=${{ env.REGISTRY_URL }}:${{ github.run_id }}
- --destination=${{ env.REGISTRY_URL }}:${ADDITIONAL_TAG//\//_}
- --build-arg=BUILD_HASH=${{ github.sha }}
- --git=recurse-submodules=true
- --skip-tls-verify
volumeMounts:
- name: build-context
mountPath: /workspace
- name: dock-sec
mountPath: /kaniko/.docker
restartPolicy: Never
volumes:
- name: build-context
emptyDir: {}
- name: dock-sec
secret:
secretName: dock-sec
backoffLimit: 1
" | kubectl apply -f -
set -e
env:
TOKEN: ${{ secrets.GIT_TOKEN }}
ADDITIONAL_TAG: ${{ github.ref_name || github.sha }}
- name: Monitor Job Status and Print Logs
run: |
echo "Monitoring build job."
set -e
TIMEOUT=1200 # Set your desired timeout in seconds
INTERVAL=30 # Interval for checking job status and printing logs
until POD_NAME=$(kubectl get pods --namespace=arc-runners --selector=job-name=${{ env.JOB_NAME }} --output=jsonpath='{.items[0].metadata.name}' 2>/dev/null); do
echo "Waiting for pod to be created..."
sleep 5
done
echo "Pod ${POD_NAME} is created."
# Wait for pod to be running
POD_STATUS=""
until [ "$POD_STATUS" == "Running" ]; do
POD_STATUS=$(kubectl get pod ${POD_NAME} -o jsonpath='{.status.phase}')
if [ "$POD_STATUS" == "Failed" ]; then
echo "Pod failed."
echo "git-clone:"
kubectl logs -c git-clone ${POD_NAME}
echo "kaniko:"
kubectl logs -c kaniko ${POD_NAME}
exit 1
fi
if [ "$POD_STATUS" != "Running" ]; then
echo "Waiting for pod ${POD_NAME} to be running. Current status: ${POD_STATUS}"
sleep 5
fi
done
echo "Pod ${POD_NAME} is running. Following the log ..."
echo "=== Logs for pod ${POD_NAME} ==="
kubectl logs --namespace=arc-runners ${POD_NAME} --follow
echo "=== END: Logs for pod ${POD_NAME} ==="
echo "Wait for the container to stop running ..."
for n in $( seq 1 10 ); do
sleep 10
# This would either yield an object (truthy for is running) or nothing if not running anymore
running_state="$( kubectl get pod ${POD_NAME} -o jsonpath='{.status.containerStatuses[0].state.running}' )"
if [ -z "${running_state}" ]; then
break
else
echo "Container still running after $(( n * 10 ))s. Waiting 10s more ..."
fi
done
# tr -d is used to remove quotes from the returned _numerical_ value
JOB_EXIT_CODE=$( kubectl get pod ${POD_NAME} -o jsonpath='{.status.containerStatuses[0].state.terminated.exitCode}' | tr -d "'" )
if [[ "$JOB_EXIT_CODE" == "0" ]]; then
echo "Job ${{ env.JOB_NAME }} is complete."
echo "Image is pushed to the Harbor Registry with TAG '${{ github.run_id }}' and '${ADDITIONAL_TAG//\//_}'"
else
echo "Job ${{ env.JOB_NAME }} failed. Status JSON:"
kubectl get --namespace=arc-runners pod/${POD_NAME} -o "jsonpath='{.status}'"
exit 1
fi
env:
ADDITIONAL_TAG: ${{ github.ref_name || github.sha }}
- name: Delete Kaniko Job
run: |
kubectl delete job ${{ env.JOB_NAME }} --namespace=arc-runners --ignore-not-found
kubectl delete secret -n arc-runners dock-sec --ignore-not-found
echo "All tasks completed gracefully."