summaryrefslogtreecommitdiffci
path: root/Jenkinsfile
blob: 34b6f5d2eb8f023cb188e02e532a5be2de3c08de (plain)
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
pipeline {
    agent none

    stages {
        stage('Compile Tailwind CSS') {
            agent {
                docker {
                    image 'node:26.3.1-alpine3.24'
                    args  '-v /tmp:/tmp -v /.npm:/.npm'
                }
            }
            steps {
                checkout scm
                sh '''
                    npm install tailwindcss @tailwindcss/cli @tailwindcss/forms
                    npx tailwindcss -i static/input.css -o static/output.css --minify
                '''
                stash name: 'tailwindcss-output', includes: 'static/output.css'
            }
        }

        stage('Matrix Build') {
            matrix {
                axes {
                    axis {
                        name 'GOOS'
                        values 'linux'
                    }
                    axis {
                        name 'GOARCH'
                        values 'arm64', 'amd64'
                    }
                }
                stages {
                    stage('Build') {
                        agent {
                            kubernetes {
                                defaultContainer 'kaniko'
                                yaml """
apiVersion: v1
kind: Pod
metadata:
  namespace: jenkins
spec:
  containers:
    - name: kaniko
      image: gcr.io/kaniko-project/executor:v1.24.0-debug
      imagePullPolicy: Always
      command: [ /busybox/cat ]
      tty: true
      resources:
        requests:
          cpu: "1"
          memory: 2Gi
          ephemeral-storage: 4Gi
        limits:
          memory: 4Gi
          ephemeral-storage: 8Gi
"""
                            }
                        }
                        environment {
                            IMAGE_PUSH_DESTINATION="registry.sayag.it/sayauz/web"
                        }
                        steps {
                            checkout scm
                            unstash 'tailwindcss-output'
                            container(name: 'kaniko', shell: '/busybox/sh') {
                                withCredentials([string(credentialsId: 'registry-sayagit-jenkins-password', variable: 'REGISTRY_SAYAGIT_JENKINS_PASSWORD')]) {
                                    withEnv(['PATH+EXTRA=/busybox']) {
                                        script {
                                            env.GIT_COMMIT_SHORT = env.GIT_COMMIT ? env.GIT_COMMIT.take(7) : "unknown"
                                            try {
                                                sh '''#!/busybox/sh
                                                    mkdir -p /kaniko/.docker
                                                    echo "{\"auths\":{\"https://registry.sayag.it\":{\"username\":\"jenkins\",\"password\":\"$REGISTRY_SAYAGIT_JENKINS_PASSWORD\"}}}" > /kaniko/.docker/config.json
                                                    /kaniko/executor --context `pwd` \
                                                        --custom-platform=linux/${GOARCH} \
                                                        --build-arg TARGETOS=linux \
                                                        --build-arg TARGETARCH=${GOARCH} \
                                                        --destination $IMAGE_PUSH_DESTINATION:commit-$GIT_COMMIT_SHORT-$GOARCH
                                                '''
                                            } catch (Exception e) {
                                                echo "Caught exception: ${e.getMessage()}"
                                                currentBuild.result = 'FAILURE'
                                                throw e
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        stage('Stitch Manifest') {
            agent {
                kubernetes {
                    defaultContainer 'manifest-tool'
                    yaml """
apiVersion: v1
kind: Pod
metadata:
  namespace: jenkins
spec:
  containers:
    - name: manifest-tool
      image: mplatform/manifest-tool:alpine-v2.2.2
      imagePullPolicy: Always
      entrypoint: [ 'true' ]
      tty: true
      resources:
        requests:
          cpu: "1"
          memory: 2Gi
          ephemeral-storage: 4Gi
"""
                }
            }
            environment {
                IMAGE_PUSH_DESTINATION="registry.sayag.it/sayauz/web"
            }
            steps {
                script {
                    env.GIT_COMMIT_SHORT = env.GIT_COMMIT ? env.GIT_COMMIT.take(7) : "unknown"
                    sh '''#!/busybox/sh
                        mkdir -p /kaniko/.docker
                        echo "{\"auths\":{\"https://registry.sayag.it\":{\"username\":\"jenkins\",\"password\":\"$REGISTRY_SAYAGIT_JENKINS_PASSWORD\"}}}" > /kaniko/.docker/config.json
                        pushToTags="$IMAGE_PUSH_DESTINATION:commit-$GIT_COMMIT_SHORT-$GOARCH"
                        if [ "$TAG_NAME" != "" ]; then
                            pushToTags="$pushToTags $IMAGE_PUSH_DESTINATION:$TAG_NAME-$GOARCH"
                        fi
                        manifest-tool push from-args \
                            --platforms linux/amd64,linux/arm64 \
                            --template $IMAGE_PUSH_DESTINATION:commit-$GIT_COMMIT_SHORT-ARCH \
                            --target $IMAGE_PUSH_DESTINATION:commit-$GIT_COMMIT_SHORT
                        manifest-tool push from-args \
                            --platforms linux/amd64,linux/arm64 \
                            --template $IMAGE_PUSH_DESTINATION:commit-$GIT_COMMIT_SHORT-ARCH \
                            --target $IMAGE_PUSH_DESTINATION:latest
                        if [ "$TAG_NAME" != "" ]; then
                            manifest-tool push from-args \
                                --platforms linux/amd64,linux/arm64 \
                                --template $IMAGE_PUSH_DESTINATION:commit-$GIT_COMMIT_SHORT-ARCH \
                                --target $IMAGE_PUSH_DESTINATION:stable
                            manifest-tool push from-args \
                                --platforms linux/amd64,linux/arm64 \
                                --template $IMAGE_PUSH_DESTINATION:commit-$GIT_COMMIT_SHORT-ARCH \
                                --target $IMAGE_PUSH_DESTINATION:$TAG_NAME
                        fi
                    '''
                }
            }
        }
    }
}