-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
159 lines (159 loc) · 6.04 KB
/
Jenkinsfile
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
pipeline {
agent {
label 'X86-BUILDER-1'
}
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('github_token')
IG_USER = 'imagegenius'
IG_REPO = 'aports'
}
stages {
stage("Set ENV Variables"){
steps{
script{
env.GITHUBIMAGE = 'ghcr.io/' + env.IG_USER + '/' + env.IG_REPO + '-cache'
}
}
}
stage('Build-Multi') {
matrix {
axes {
axis {
name 'MATRIXARCH'
values 'X86-64', 'ARM64'
}
axis {
name 'ALPINETAG'
values '3.19', '3.20', 'edge'
}
}
stages {
stage('axis') {
agent none
steps {
script {
stage("alpine-v${ALPINETAG} on ${MATRIXARCH}") {
print "alpine-v${ALPINETAG} on ${MATRIXARCH}"
}
}
}
}
stage ('Build') {
agent {
label "${MATRIXARCH}"
}
steps {
echo "Running on node: ${NODE_NAME}"
withCredentials([
string(credentialsId: 'package-private-key', variable: 'PRIVKEY'),
]) {
echo 'Logging into Github'
sh '''#!/bin/bash
echo $GITHUB_TOKEN | docker login ghcr.io -u ImageGenius-CI --password-stdin
'''
echo 'Building packages'
sh '''#!/bin/bash
if [[ "$MATRIXARCH" == "X86-64" ]]; then
ARCH="x86_64"
BUILD_ARCH="amd64"
elif [[ "$MATRIXARCH" == "ARM64" ]]; then
ARCH="aarch64"
BUILD_ARCH="aarch64"
elif [[ "$MATRIXARCH" == "ARMHF" ]]; then
ARCH="armhf"
BUILD_ARCH="arm/v7"
fi
BUILDX_CONTAINER=$(head /dev/urandom | tr -dc 'a-z' | head -c12)
docker buildx create --driver=docker-container --name=${BUILDX_CONTAINER}
docker pull ${GITHUBIMAGE}:v${ALPINETAG}-${ARCH}
if [ $? -ne 0 ]; then
echo "It doesn't look like \"${GITHUBIMAGE}:v${ALPINETAG}-${ARCH}\" exists on ghcr, building an empty image"
docker buildx build \
-t ${GITHUBIMAGE}:v${ALPINETAG}-${ARCH} \
--build-arg ALPINETAG=${ALPINETAG} \
-f Dockerfile.empty . \
--platform=linux/${BUILD_ARCH} \
--builder=${BUILDX_CONTAINER} --load
docker push ${GITHUBIMAGE}:v${ALPINETAG}-${ARCH}
fi
set -e
docker buildx build \
--no-cache --pull -t ${GITHUBIMAGE}:v${ALPINETAG}-${ARCH} \
--build-arg PRIVKEY="$PRIVKEY" \
--build-arg ALPINETAG=${ALPINETAG} \
--build-arg ARCH=${ARCH} . \
--platform=linux/${BUILD_ARCH} \
--builder=${BUILDX_CONTAINER} --load
docker push ${GITHUBIMAGE}:v${ALPINETAG}-${ARCH}
docker rmi \
${GITHUBIMAGE}:v${ALPINETAG}-${ARCH} || :
docker buildx rm ${BUILDX_CONTAINER}
'''
}
}
}
}
}
}
stage ('Download Packages') {
steps {
withCredentials([
string(credentialsId: 'ci-tests-s3-key-id', variable: 'S3_KEY'),
string(credentialsId: 'ci-tests-s3-secret-access-key', variable: 'S3_SECRET')
]) {
// 'version' and 'arches' need to match matrix axis'
echo "Get packages from images"
sh '''#!/bin/bash
versions=(3.19 3.20 edge)
arches=(x86_64 aarch64)
for version in "${versions[@]}"; do
for arch in "${arches[@]}"; do
docker pull ${GITHUBIMAGE}:v${version}-${arch}
docker create --name aports-${version}-${arch} ${GITHUBIMAGE}:v${version}-${arch} blah
docker cp aports-${version}-${arch}:/aports .
docker rm aports-${version}-${arch}
docker rmi ${GITHUBIMAGE}:v${version}-${arch}
done
done
'''
echo "Copy Packages to Webroot"
sh '''#!/bin/bash
set -e
rclone sync aports s3:packages.imagegenius.io \
--filter "+ */" \
--filter "+ */**" \
--filter "- *" \
--s3-access-key-id=${S3_KEY} \
--s3-secret-access-key=${S3_SECRET}
rm -rf aports
'''
}
}
}
}
post {
always {
script{
if (currentBuild.currentResult == "SUCCESS"){
sh ''' curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://wiki.jenkins.io/JENKINS/attachments/2916393/57409617.png","embeds": [{"color": 1681177,\
"description": "**'${IG_REPO}' build '${BUILD_NUMBER}'**\\n**Job:** '${RUN_DISPLAY_URL}'\\n"}],\
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
}
else {
sh ''' curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://wiki.jenkins.io/JENKINS/attachments/2916393/57409617.png","embeds": [{"color": 16711680,\
"description": "**'${IG_REPO}' build '${BUILD_NUMBER}' Failed!**\\n**Job:** '${RUN_DISPLAY_URL}'\\n"}],\
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
}
}
}
cleanup {
cleanWs()
}
}
}