Skip to content

Commit

Permalink
Merge pull request #13 from SimonStiil/going-arm
Browse files Browse the repository at this point in the history
Going Arm
  • Loading branch information
SimonStiil authored Apr 27, 2024
2 parents d97eec9 + 9a05655 commit 77525c1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
77 changes: 58 additions & 19 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ podTemplate(yaml: '''
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker
- name: manifest-tool
image: mplatform/manifest-tool:alpine-v2.1.6
command:
- sleep
args:
- 99d
volumeMounts:
- name: kaniko-secret
mountPath: /root/.docker
- name: golang
image: golang:1.22.2-alpine3.19
command:
- sleep
args:
- 99d
restartPolicy: Never
nodeSelector:
kubernetes.io/arch: amd64
volumes:
- name: kaniko-secret
secret:
Expand All @@ -37,46 +44,78 @@ podTemplate(yaml: '''
node(POD_LABEL) {
TreeMap scmData
String gitCommitMessage
Map properties
stage('checkout SCM') {
scmData = checkout scm
gitCommitMessage = sh(returnStdout: true, script: "git log --format=%B -n 1 ${scmData.GIT_COMMIT}").trim()
gitMap = scmGetOrgRepo scmData.GIT_URL
githubWebhookManager gitMap: gitMap, webhookTokenId: 'jenkins-webhook-repo-cleanup'
properties = readProperties file: 'package.env'
}
container('golang') {
stage('UnitTests') {
withEnv(['CGO_ENABLED=0', 'GOOS=linux', 'GOARCH=amd64']) {
withEnv(['CGO_ENABLED=0']) {
sh '''
go test .
'''
}
}
stage('Build Application') {
withEnv(['CGO_ENABLED=0', 'GOOS=linux', 'GOARCH=amd64']) {
stage('Build Application AMD64') {
withEnv(['CGO_ENABLED=0', 'GOOS=linux', 'GOARCH=amd64', "PACKAGE_CONTAINER_APPLICATION=${properties.PACKAGE_CONTAINER_APPLICATION}"]) {
sh '''
go build -ldflags="-w -s" .
go build -ldflags="-w -s" -o $PACKAGE_CONTAINER_APPLICATION-amd64 .
'''
}
}
stage('Generate Dockerfile') {
sh '''
./dockerfilegen.sh
'''
stage('Build Application ARM64') {
withEnv(['CGO_ENABLED=0', 'GOOS=linux', 'GOARCH=arm64', "PACKAGE_CONTAINER_APPLICATION=${properties.PACKAGE_CONTAINER_APPLICATION}"]) {
sh '''
go build -ldflags="-w -s" -o $PACKAGE_CONTAINER_APPLICATION-arm64 .
'''
}
}
}
if ( !gitCommitMessage.startsWith("renovate/") || ! gitCommitMessage.startsWith("WIP") ) {
stage('Build Docker Image') {
container('kaniko') {
def properties = readProperties file: 'package.env'
container('golang') {
stage('Generate Dockerfile AMD64') {
sh '''
./dockerfilegen.sh amd64
'''
}
}
container('kaniko') {
stage('Build Docker Image AMD64') {
withEnv(["GIT_COMMIT=${scmData.GIT_COMMIT}", "PACKAGE_NAME=${properties.PACKAGE_NAME}", "PACKAGE_DESTINATION=${properties.PACKAGE_DESTINATION}", "PACKAGE_CONTAINER_SOURCE=${properties.PACKAGE_CONTAINER_SOURCE}", "GIT_BRANCH=${BRANCH_NAME}"]) {
if (isMainBranch()){
sh '''
/kaniko/executor --force --context `pwd` --log-format text --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:latest --label org.opencontainers.image.description="Build based on $PACKAGE_CONTAINER_SOURCE/commit/$GIT_COMMIT" --label org.opencontainers.image.revision=$GIT_COMMIT --label org.opencontainers.image.version=$GIT_BRANCH
sh '''
/kaniko/executor --force --context `pwd` --log-format text --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME-amd64 --label org.opencontainers.image.description="Build based on $PACKAGE_CONTAINER_SOURCE/commit/$GIT_COMMIT" --label org.opencontainers.image.revision=$GIT_COMMIT --label org.opencontainers.image.version=$GIT_BRANCH
'''
} else {
sh '''
/kaniko/executor --force --context `pwd` --log-format text --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME --label org.opencontainers.image.description="Build based on $PACKAGE_CONTAINER_SOURCE/commit/$GIT_COMMIT" --label org.opencontainers.image.revision=$GIT_COMMIT --label org.opencontainers.image.version=$GIT_BRANCH
}
}
}
container('golang') {
stage('Generate Dockerfile ARM64') {
sh '''
./dockerfilegen.sh arm64
'''
}
}
container('kaniko') {
stage('Build Docker Image ARM64') {
withEnv(["GIT_COMMIT=${scmData.GIT_COMMIT}", "PACKAGE_NAME=${properties.PACKAGE_NAME}", "PACKAGE_DESTINATION=${properties.PACKAGE_DESTINATION}", "PACKAGE_CONTAINER_SOURCE=${properties.PACKAGE_CONTAINER_SOURCE}", "GIT_BRANCH=${BRANCH_NAME}"]) {
sh '''
/kaniko/executor --force --context `pwd` --log-format text --custom-platform=linux/arm64 --destination $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME-arm64 --label org.opencontainers.image.description="Build based on $PACKAGE_CONTAINER_SOURCE/commit/$GIT_COMMIT" --label org.opencontainers.image.revision=$GIT_COMMIT --label org.opencontainers.image.version=$GIT_BRANCH
'''
}
}
}
container('manifest-tool') {
stage('Build combined manifest') {
sh 'echo $HOME && pwd && whoami'
withEnv(["GIT_COMMIT=${scmData.GIT_COMMIT}", "PACKAGE_NAME=${properties.PACKAGE_NAME}", "PACKAGE_DESTINATION=${properties.PACKAGE_DESTINATION}", "PACKAGE_CONTAINER_SOURCE=${properties.PACKAGE_CONTAINER_SOURCE}", "GIT_BRANCH=${BRANCH_NAME}"]) {
if (isMainBranch()){
sh 'manifest-tool push from-args --platforms linux/amd64,linux/arm64 --template $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME-ARCH --tags latest --target $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME'
} else {
sh 'manifest-tool push from-args --platforms linux/amd64,linux/arm64 --template $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME-ARCH --target $PACKAGE_DESTINATION/$PACKAGE_NAME:$BRANCH_NAME'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dockerfilegen.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source package.env
echo -n "FROM ${PACKAGE_CONTAINER_BASE}
WORKDIR ${PACKAGE_CONTAINER_WORKDIR}
COPY ${PACKAGE_CONTAINER_APPLICATION} ${PACKAGE_CONTAINER_DESTINATION}
COPY ${PACKAGE_CONTAINER_APPLICATION}-${1} ${PACKAGE_CONTAINER_DESTINATION}
COPY keysindex.html ${PACKAGE_CONTAINER_WORKDIR}
COPY namespacesindex.html ${PACKAGE_CONTAINER_WORKDIR}
COPY certificates /
Expand Down

0 comments on commit 77525c1

Please sign in to comment.