Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use single container k8s build environment (Fix INFRA issues) #964

Merged
merged 3 commits into from
Jan 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 42 additions & 63 deletions Jenkinsfile_k8s
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def recordDeployment(owner, repo, ref, status, environmentURL, environment = "pr
pipeline {
agent {
kubernetes {
inheritFrom 'jnlp-linux'
yaml '''
apiVersion: "v1"
kind: "Pod"
Expand All @@ -51,28 +50,11 @@ spec:
values:
- linux
restartPolicy: "Never"
automountServiceAccountToken: false
containers:
- name: "node"
image: "node:14.17"
securityContext:
privileged: false
tty: true
command:
- cat
- name: "blobxfer"
image: "mcr.microsoft.com/blobxfer:1.9.1"
command:
- cat
securityContext:
privileged: false
tty: true
- name: "builder"
image: "jenkinsciinfra/builder:1.2.0"
command:
- cat
securityContext:
privileged: false
tty: true
- name: "jnlp"
image: "jenkinsciinfra/builder"
imagePullPolicy: Always
'''
}
}
Expand All @@ -82,6 +64,7 @@ spec:
GET_CONTENT = "true"
NODE_ENV = "production"
HOME = "/tmp"
PATH = "/tmp/.npm-packages/bin:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}

triggers {
Expand All @@ -96,11 +79,19 @@ spec:
}

stages {
stage('Setup NPM and Yarn') {
steps {
sh '''
mkdir "${HOME}/.npm-packages"
npm config set prefix "${HOME}/.npm-packages"
npm install --global yarn
'''
}
}

stage('NPM Install') {
steps {
container('node') {
sh 'NODE_ENV=development yarn install'
}
sh 'NODE_ENV=development yarn install'
}
}

Expand All @@ -115,9 +106,7 @@ spec:
NETLIFY = "true"
}
steps {
container('node') {
sh 'yarn build'
}
sh 'yarn build'
}
}

Expand All @@ -134,9 +123,7 @@ spec:
GATSBY_ALGOLIA_WRITE_KEY = credentials('algolia-plugins-write-key')
}
steps {
container('node') {
sh 'yarn build'
}
sh 'yarn build'
}
}

Expand All @@ -152,10 +139,10 @@ spec:
NODE_ENV = "development"
}
steps {
container('node') {
sh 'yarn lint'
sh 'yarn test'
}
sh '''
yarn lint
yarn test
'''
}
}

Expand All @@ -167,21 +154,19 @@ spec:
PLUGINSITE_STORAGEACCOUNTKEY = credentials('PLUGINSITE_STORAGEACCOUNTKEY')
}
steps {
container('blobxfer') {
sh('''
blobxfer upload \
--local-path ./plugins/plugin-site/public \
--storage-account-key $PLUGINSITE_STORAGEACCOUNTKEY \
--storage-account prodpluginsite \
--remote-path pluginsite \
--recursive \
--mode file \
--skip-on-md5-match \
--file-md5 \
--connect-timeout 30 \
--delete
''')
}
sh('''
blobxfer upload \
--local-path ./plugins/plugin-site/public \
--storage-account-key $PLUGINSITE_STORAGEACCOUNTKEY \
--storage-account prodpluginsite \
--remote-path pluginsite \
--recursive \
--mode file \
--skip-on-md5-match \
--file-md5 \
--connect-timeout 30 \
--delete
''')
}
}

Expand All @@ -194,25 +179,19 @@ spec:
}
post {
success {
container('builder') {
recordDeployment('jenkins-infra', 'plugin-site', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--jenkins-plugin-site-pr.netlify.app")
}
recordDeployment('jenkins-infra', 'plugin-site', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--jenkins-plugin-site-pr.netlify.app")
}
failure {
container('builder') {
recordDeployment('jenkins-infra', 'plugin-site', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--jenkins-plugin-site-pr.netlify.app")
}
recordDeployment('jenkins-infra', 'plugin-site', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--jenkins-plugin-site-pr.netlify.app")
}
}
steps {
container('node') {
script {
def netlifySite = readJSON(text: sh(script: 'yarn exec netlify sites:list --json', returnStdout: true).trim()).find { it.name == 'jenkins-plugin-site-pr' }
env.NETLIFY_SITE_ID = netlifySite['site_id']
env.NETLIFY_DOMAIN = netlifySite['default_domain']
script {
def netlifySite = readJSON(text: sh(script: 'yarn exec netlify sites:list --json', returnStdout: true).trim()).find { it.name == 'jenkins-plugin-site-pr' }
env.NETLIFY_SITE_ID = netlifySite['site_id']
env.NETLIFY_DOMAIN = netlifySite['default_domain']

sh('yarn exec netlify deploy --message "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./plugins/plugin-site/public')
}
sh('yarn exec netlify deploy --message "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./plugins/plugin-site/public')
}
}
}
Expand Down