From a285f1181a4e8d57b47b18e7bcb04b78f049c37b Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 31 Jul 2022 10:34:02 -0500 Subject: [PATCH] ci: Begin Jenkins build pipeline --- ci/Jenkinsfile | 55 +++++++++++++++++++++++++++++++++++++++++++++ ci/build-svc.sh | 7 ++++++ ci/build-ui.sh | 14 ++++++++++++ ci/podTemplate.yaml | 29 ++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 ci/Jenkinsfile create mode 100644 ci/build-svc.sh create mode 100644 ci/build-ui.sh create mode 100644 ci/podTemplate.yaml diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile new file mode 100644 index 0000000..5200d1f --- /dev/null +++ b/ci/Jenkinsfile @@ -0,0 +1,55 @@ +// vim: set sw=4 ts=4 sts=4 et : +// vim: set ft=groovy : + +pipeline { + agent { + kubernetes { + yamlFile 'ci/podTemplate.yaml' + } + } + + stages { + stage('Build') { + parallel { + stage('Build Backend') { + steps { + container('python') { + dir('svc') { + sh '. ../ci/build-svc.sh' + } + } + } + post { + success { + dir('svc/dist') { + archiveArtifacts 'hudctrl-*' + } + } + } + } + + stage('Build Frontend') { + steps { + container('node') { + dir('ui') { + sh '. ../ci/build-ui.sh' + } + } + } + post { + success { + dir('ui') { + archiveArtifacts 'hudctrl-ui.tar.gz' + } + } + failure { + dir('ui/npm_cache/_logs') { + archiveArtifacts '*' + } + } + } + } + } + } + } +} diff --git a/ci/build-svc.sh b/ci/build-svc.sh new file mode 100644 index 0000000..5f54156 --- /dev/null +++ b/ci/build-svc.sh @@ -0,0 +1,7 @@ +#!/bin/sh -ex + +python -m venv .venv +.venv/bin/python -m pip install --no-cache-dir -U pip setuptools wheel +.venv/bin/python -m pip install --no-cache-dir poetry + +.venv/bin/poetry build diff --git a/ci/build-ui.sh b/ci/build-ui.sh new file mode 100644 index 0000000..efa857e --- /dev/null +++ b/ci/build-ui.sh @@ -0,0 +1,14 @@ +#!/bin/sh -ex + +export TEMP="${PWD}/tmp" +mkdir "${TEMP}" + +# https://github.com/npm/cli/issues/3208#issuecomment-1002990902 +# Work around crazy performance issue in npm@7 / npm@8 +mkdir node_modules + +npm ci + +npm run build +cd dist +find . -mindepth 1 -maxdepth 1 -printf '%P\0' | xargs -0 tar -czf ../hudctrl-ui.tar.gz diff --git a/ci/podTemplate.yaml b/ci/podTemplate.yaml new file mode 100644 index 0000000..154b1d7 --- /dev/null +++ b/ci/podTemplate.yaml @@ -0,0 +1,29 @@ +spec: + nodeSelector: + kubernetes.io/hostname: k8s-amd64-n2.pyrocufflink.blue + containers: + - name: python + image: docker.io/python:3.10 + command: + - sleep + - infinity + securityContext: + readOnlyRootFilesystem: true + runAsUser: 1000 + - name: node + image: docker.io/node:16-bullseye-slim + command: + - sleep + - infinity + env: + - name: npm_config_cache + value: ./npm_cache + - name: NODE_OPTIONS + value: '--max_old_space_size=512' + resources: + limits: + memory: 1536M + cpu: 1.0 + securityContext: + readOnlyRootFilesystem: true + runAsUser: 1000