-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(jenkinsfile): update demo jenkinsfile
- Loading branch information
1 parent
513d9be
commit 269d652
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
pipeline { | ||
agent { | ||
kubernetes { | ||
yaml ''' | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: kube-pod | ||
spec: | ||
containers: | ||
- name: docker | ||
image: docker:latest | ||
imagePullPolicy: Always | ||
command: | ||
- cat | ||
tty: true | ||
securityContext: | ||
privileged: true | ||
runAsUser: 0 | ||
volumeMounts: | ||
- mountPath: /var/run/docker.sock | ||
name: docker-sock | ||
- name: ubuntu | ||
image: robolaunchio/build-image:1.0 | ||
imagePullPolicy: Always | ||
command: | ||
- cat | ||
tty: true | ||
env: | ||
- name: CI | ||
value: false | ||
volumes: | ||
- name: docker-sock | ||
hostPath: | ||
path: /var/run/docker.sock | ||
''' | ||
} | ||
} | ||
stages { | ||
stage('Install Node') { | ||
steps { | ||
container('ubuntu') { | ||
sh 'npm install -g n' | ||
sh 'n latest' | ||
} | ||
} | ||
} | ||
stage('Git Clone') { | ||
steps { | ||
container('ubuntu') { | ||
git branch: 'main', credentialsId: '7322b7d8-a45e-4594-9bd8-fa1952a7aaad', url: 'git@github.com:robolaunch/ui.git' | ||
sh """export VER=`grep '"version":' package.json | awk '{print \$2}' | sed 's/"//g' | sed 's/,//'` && echo \$VER > version.txt""" | ||
script { | ||
env.VER = readFile('version.txt').trim() | ||
} | ||
} | ||
} | ||
} | ||
stage('Install Depends && Build') { | ||
steps { | ||
container('ubuntu') { | ||
withCredentials([file(credentialsId: 'frontend-public-demo-env', variable: 'text')]) { | ||
writeFile file:'./.env', text: readFile(text) | ||
} | ||
sh 'npm i --force' | ||
sh 'npm run build' | ||
sh "tar -zcvf ui-${env.VER}-${env.BUILD_NUMBER}.tar.gz build" | ||
withCredentials([usernamePassword(credentialsId: '7fadeb6b-976b-40ed-8c7c-20e157b4f81a', passwordVariable: 'password', usernameVariable: 'username')]) { | ||
sh "curl --fail -u $username:$password --upload-file ui-${env.VER}-${env.BUILD_NUMBER}.tar.gz https://nexus.robolaunch.cloud/repository/ui/" | ||
} | ||
} | ||
} | ||
} | ||
stage('Docker Build && Push') { | ||
steps { | ||
container('docker') { | ||
sh "docker build -t robolaunchio/frontend-public-demo-httpd:${env.VER} ." | ||
withCredentials([usernamePassword(credentialsId: 'dockerhub-robolaunchio', passwordVariable: 'password', usernameVariable: 'username')]) { | ||
sh 'docker login -u $username -p $password' | ||
} | ||
sh "docker push robolaunchio/frontend-public-demo-httpd:${env.VER}" | ||
} | ||
} | ||
} | ||
stage('Kubernetes Deploy') { | ||
steps { | ||
container('ubuntu') { | ||
withCredentials([file(credentialsId: 'hetzner_prod', variable: 'config')]) { | ||
sh "kubectl set image deployment.v1.apps/ui -n ui ui=robolaunchio/frontend-public-demo-httpd:${env.VER} --kubeconfig=$config" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |