diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..3dfb56b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,91 @@ +pipeline { + agent none + stages { + stage('Build') { + parallel { + stage('Build backend-glibc') { + agent { docker { image 'rust:bullseye' }} + steps { + dir('backend') { + sh 'cargo build --release' + dir('target/release') { + stash includes: 'backend_rust', name: 'backend-glibc' + } + } + } + } + stage('Build backend-muslc') { + agent { docker { image 'rust:alpine' }} + steps { + dir('backend') { + sh 'cargo build --release' + dir('target/release') { + stash includes: 'backend_rust', name: 'backend-muslc' + } + } + } + } + stage('Build frontend') { + agent { docker { image 'node:current-alpine' }} + steps { + dir('frontend') { + sh 'yarn install --frozen-lockfile' + sh 'yarn lint' + sh 'yarn build' + dir('dist') { + stash name: 'frontend' + } + } + } + } + } + } + stage('Package') { + agent { docker { image 'alpine:latest' reuseNode true }} + steps { + sh 'apk add tar xz' + dir('static') { + unstash name: 'frontend' + } + unstash name: 'backend-glibc' + sh 'tar -cvJf --transform="flags=r;s|backend_rust|server|" linux-x64-glibc.tar.xz backend_rust static' + unstash name: 'backend-muslc' + sh 'tar -cvJf --transform="flags=r;s|backend_rust|server|" linux-x64-muslc.tar.xz backend_rust static' + archiveArtifacts artifacts: '*.tar.xz', allowEmptyArchive: false, onlyIfSuccessful: true + } + } + stage('Release') { + agent { docker { image 'alpine:latest' reuseNode true }} + when { buildingTag() } + environment { + TOKEN = credentials('abd7020c-43d6-485b-ae09-2f9b484d9c15') + } + steps { + def release_body = [ + 'name': "Version ${TAG_NAME}", + 'tag_name': "${TAG_NAME}", + 'is_draft': false, + 'is_prerelease': false + ] + def release_body_str = writeJSON returnText: true, data: release_body + def release_resp = httpRequest 'https://gitea.mattv.de/api/v1/repos/root/fileserver/releases', + acceptType: 'APPLICATION_JSON', + contentType: 'APPLICATION_JSON', + customHeaders: [[name: 'Authorization', value: 'token ${TOKEN_PSW}', maskValue: true]], + httpMode: 'POST', + requestBody: release_body_str + def release_json = readJson text: release_resp.content + httpRequest 'https://gitea.mattv.de/api/v1/repos/root/fileserver/releases/${release_json.id}/assets?name=linux-x64-glibc.tar.xz', + httpMode: 'POST', + acceptType: 'APPLICATION_JSON', + customHeaders: [[name: 'Authorization', value: 'token ${TOKEN_PSW}', maskValue: true]], + formData: [[contentType: 'application/octet-stream', name: 'attachment', fileName: 'linux-x64-glibc.tar.xz', uploadFile: 'linux-x64-glibc.tar.xz']] + httpRequest 'https://gitea.mattv.de/api/v1/repos/root/fileserver/releases/${release_json.id}/assets?name=linux-x64-muslc.tar.xz', + httpMode: 'POST', + acceptType: 'APPLICATION_JSON', + customHeaders: [[name: 'Authorization', value: 'token ${TOKEN_PSW}', maskValue: true]], + formData: [[contentType: 'application/octet-stream', name: 'attachment', fileName: 'linux-x64-muslc.tar.xz', uploadFile: 'linux-x64-muslc.tar.xz']] + } + } + } +}