Repository navigation
Expand file tree
/
Copy pathJenkinsfile.homeassistant
More file actions
186 lines (186 loc) · 8.36 KB
/
Copy pathJenkinsfile.homeassistant
File metadata and controls
186 lines (186 loc) · 8.36 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
183
184
185
186
pipeline {
agent {
label 'X86-64-MULTI'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10', daysToKeepStr: '60'))
parallelsAlwaysFailFast()
}
// Configuration for the variables used for this specific repo
environment {
BUILDS_DISCORD=credentials('build_webhook_url')
GITHUB_TOKEN=credentials('498b4638-2d02-4ce5-832d-8a57d01d97ab')
}
stages {
stage('Grab requirements') {
steps {
echo "Running on node: ${NODE_NAME}"
echo 'Grabbing requirements.txt files'
sh '''#! /bin/bash
set -e
export HASS_RELEASE=$(curl -H "Authorization: token ${GITHUB_TOKEN}" -sf https://api.github.com/repos/home-assistant/core/releases/latest \
| jq -r .tag_name)
echo "HASS_RELEASE is ${HASS_RELEASE}"
export HASS_BASE=$(curl -sfL https://raw.githubusercontent.com/home-assistant/core/${HASS_RELEASE}/build.yaml \
| grep 'amd64: ' \
| cut -d: -f3)
echo "HASS_BASE is ${HASS_BASE}"
echo "Downloading upstream requirements files. . ."
mkdir -p upstream
curl -sfL https://raw.githubusercontent.com/home-assistant/core/${HASS_RELEASE}/requirements.txt -o upstream/requirements.txt
curl -sfL https://raw.githubusercontent.com/home-assistant/core/${HASS_RELEASE}/requirements_all.txt -o upstream/requirements_all.txt
curl -sfL https://raw.githubusercontent.com/home-assistant/docker/${HASS_BASE}/requirements.txt -o upstream/requirements_base.txt
'''
}
}
stage('Build-Multi') {
parallel {
stage('Build amd64') {
steps {
echo "Running on node: ${NODE_NAME}"
echo 'Logging into Github'
sh '''#! /bin/bash
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
'''
sh "docker buildx build --no-cache --pull --platform=linux/amd64 -t ghcr.io/linuxserver/wheelie:homeassistant-amd64 --build-arg ARCH=amd64 -f Dockerfile.homeassistant ."
}
}
stage('Build arm64v8') {
agent {
label 'ARM64'
}
steps {
echo "Running on node: ${NODE_NAME}"
echo 'Logging into Github'
sh '''#! /bin/bash
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
'''
sh "docker buildx build --no-cache --pull --platform=linux/arm64 -t ghcr.io/linuxserver/wheelie:homeassistant-arm64v8 --build-arg ARCH=arm64v8 -f Dockerfile.homeassistant ."
retry(5) {
sh "docker push ghcr.io/linuxserver/wheelie:homeassistant-arm64v8"
}
echo 'Cleaning up'
sh '''#! /bin/bash
containers=$(docker ps -aq)
if [[ -n "${containers}" ]]; then
docker stop ${containers}
fi
docker system prune -af --volumes || : '''
}
}
}
}
stage('Push artifacts') {
steps {
withCredentials([
string(credentialsId: 'ci-tests-s3-key-id', variable: 'S3_KEY'),
string(credentialsId: 'ci-tests-s3-secret-access-key ', variable: 'S3_SECRET')
]) {
sh '''#! /bin/bash
set -e
mkdir -p build
docker pull ghcr.io/linuxserver/wheelie:homeassistant-arm64v8
docker create --name wheelie-homeassistant-amd64 ghcr.io/linuxserver/wheelie:homeassistant-amd64 blah
docker create --name wheelie-homeassistant-arm64v8 ghcr.io/linuxserver/wheelie:homeassistant-arm64v8 blah
docker cp wheelie-homeassistant-amd64:/build/. build/
docker cp wheelie-homeassistant-arm64v8:/build/. build/
docker rm \
wheelie-homeassistant-amd64 \
wheelie-homeassistant-arm64v8
'''
script {
env.TEMPDIR = sh(
script: '''mktemp -d ''',
returnStdout: true).trim()
}
sh '''#! /bin/bash
set -e
git clone https://github.com/linuxserver/wheelie.git ${TEMPDIR}/wheelie
echo "setting up s3cmd"
docker run -d --rm \
--name s3cmd \
-v ${PWD}/build:/build \
-e AWS_ACCESS_KEY_ID=\"${S3_KEY}\" \
-e AWS_SECRET_ACCESS_KEY=\"${S3_SECRET}\" \
ghcr.io/linuxserver/baseimage-alpine:3.16
docker exec s3cmd /bin/bash -c 'apk add --no-cache py3-pip && pip install s3cmd'
echo "pushing wheels as necessary"
os="homeassistant-3.18"
for wheel in $(ls build/); do
if ! grep -q "${wheel}" "${TEMPDIR}/wheelie/docs/${os}/index.html"; then
echo "**** ${wheel} for ${os} is being uploaded to aws ****"
UPLOADED="${UPLOADED}\\n${wheel}"
docker exec s3cmd s3cmd put --acl-public "/build/${wheel}" "s3://wheels.linuxserver.io/${os}/${wheel}"
sed -i "s|</body>| <a href='https://wheels.linuxserver.io/${os}/${wheel}'>${wheel}</a>\\n <br />\\n\\n</body>|" "${TEMPDIR}/wheelie/docs/${os}/index.html"
else
echo "**** ${wheel} for ${os} already processed, skipping ****"
fi
done
if [ -n "${UPLOADED}" ]; then
echo -e "**** Uploaded wheels are: **** ${UPLOADED}"
else
echo "No wheels were uploaded"
fi
echo "Stopping s3cmd and removing temp files"
docker stop s3cmd
rm -rf build
mv -f upstream/requirement*.txt "${TEMPDIR}/wheelie/HA-reqs/"
'''
sh '''#! /bin/bash
set -e
echo "updating git repo as necessary"
cd ${TEMPDIR}/wheelie
git add . || :
git commit -m '[bot] Updating HA indices and requirements files' || :
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/wheelie.git --all || :
'''
}
}
}
stage('Trigger HA external trigger') {
steps {
sh '''#! /bin/bash
set -e
echo "Triggering HA external trigger"
curl -ifX POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\\"ref\\":\\"refs/heads/main\\"}" \
https://api.github.com/repos/linuxserver/docker-homeassistant/actions/workflows/external_trigger.yml/dispatches
'''
}
}
}
post {
always {
script {
sh '''#! /bin/bash
docker stop s3cmd || :
rm -rf ${TEMPDIR}/wheelie
'''
if (currentBuild.currentResult == "SUCCESS"){
sh ''' TRIGGER_REASON="A new set of wheels built for HomeAssistant. Triggering HA trigger."
curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png","embeds": [{"color": 1681177,\
"description": "**WheelieHA Build:** '${BUILD_NUMBER}'\\n**Status:** Success\\n**Job:** '${RUN_DISPLAY_URL}'\\n**Reason:** '"${TRIGGER_REASON}"' \\n**HA trigger build:** '"https://github.com/linuxserver/docker-homeassistant/actions/workflows/external_trigger.yml"' \\n"}],\
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
}
else {
sh ''' curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png","embeds": [{"color": 16711680,\
"description": "**WheelieHA Build:** '${BUILD_NUMBER}'\\n**Status:** failure\\n**Job:** '${RUN_DISPLAY_URL}'\\n"}],\
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
}
}
}
cleanup {
sh '''#! /bin/bash
echo "Performing docker system prune!!"
containers=$(docker ps -aq)
if [[ -n "${containers}" ]]; then
docker stop ${containers}
fi
docker system prune -af --volumes || :
'''
cleanWs()
}
}
}