From e649ffced70214a5d941d60ff143de70cb13990b Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 5 Sep 2022 22:41:47 -0500 Subject: [PATCH] ci: Begin Jenkins build pipeline --- .dockerignore | 4 +++ .editorconfig | 5 ++++ Containerfile | 5 ++++ ci/Jenkinsfile | 59 +++++++++++++++++++++++++++++++++++++++++++++ ci/build.sh | 3 +++ ci/common.sh | 5 ++++ ci/container.sh | 5 ++++ ci/podTemplate.yaml | 19 +++++++++++++++ ci/publish.sh | 10 ++++++++ ci/test.sh | 3 +++ 10 files changed, 118 insertions(+) create mode 100644 .dockerignore create mode 100644 Containerfile create mode 100644 ci/Jenkinsfile create mode 100644 ci/build.sh create mode 100644 ci/common.sh create mode 100644 ci/container.sh create mode 100644 ci/podTemplate.yaml create mode 100644 ci/publish.sh create mode 100644 ci/test.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..abd5567 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +target/ +!target/*/dynk8s-provisioner +src/ +test/ diff --git a/.editorconfig b/.editorconfig index c6d39a8..93f4e5f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,8 @@ trim_trailing_whitespace = true [**.rs] max_line_length = 79 + +[Jenkinsfile] +max_line_length = 79 +indent_style = space +indent_size = 4 diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..6d30ad8 --- /dev/null +++ b/Containerfile @@ -0,0 +1,5 @@ +FROM fedora:36 + +COPY target/release/dynk8s-provisioner /usr/bin/ + +CMD ["/usr/bin/dynk8s-provisioner"] diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile new file mode 100644 index 0000000..968372e --- /dev/null +++ b/ci/Jenkinsfile @@ -0,0 +1,59 @@ +pipeline { + agent { + kubernetes { + yamlFile 'ci/podTemplate.yaml' + workspaceVolume dynamicPVC() + } + } + + options { + buildDiscarder logRotator(numToKeepStr: '5') + disableConcurrentBuilds() + } + + environment { + CARGO_HOME = "${env.WORKSPACE}/.cargo" + TMPDIR = "${env.WORKSPACE_TMP}" + } + + stages { + stage('Test') { + steps { + container('build') { + sh '. ci/test.sh' + } + } + } + + stage('Build') { + steps { + container('build') { + sh '. ci/build.sh' + } + } + post { + success { + dir('target/release') { + archiveArtifacts 'dynk8s-provisioner' + } + } + } + } + + stage('Container') { + steps { + container('podman') { + sh '. ci/container.sh' + } + } + } + + stage('Publish') { + steps { + container('podman') { + sh '. ci/publish.sh' + } + } + } + } +} diff --git a/ci/build.sh b/ci/build.sh new file mode 100644 index 0000000..7d0b70d --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash -ex + +cargo build --release diff --git a/ci/common.sh b/ci/common.sh new file mode 100644 index 0000000..f1dc6f2 --- /dev/null +++ b/ci/common.sh @@ -0,0 +1,5 @@ +# shellcheck: shell=sh + +tag_name() { + echo "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g' -e 's/^[.-]/_/' +} diff --git a/ci/container.sh b/ci/container.sh new file mode 100644 index 0000000..fa76697 --- /dev/null +++ b/ci/container.sh @@ -0,0 +1,5 @@ +#!/bin/bash -ex + +. ci/common.sh + +podman build -t dynk8s-provider:$(tag_name ${BUILD_TAG}) . diff --git a/ci/podTemplate.yaml b/ci/podTemplate.yaml new file mode 100644 index 0000000..47d5439 --- /dev/null +++ b/ci/podTemplate.yaml @@ -0,0 +1,19 @@ +spec: + securityContext: + fsGroup: 1000 + containers: + - name: build + image: docker.io/rust:1.63 + command: + - sleep + - infinity + securityContext: + readOnlyRootFilesystem: true + runAsUser: 1000 + - name: podman + image: quay.io/containers/podman:v3.4 + command: + - sleep + - infinity + securityContext: + privileged: true diff --git a/ci/publish.sh b/ci/publish.sh new file mode 100644 index 0000000..3cb6464 --- /dev/null +++ b/ci/publish.sh @@ -0,0 +1,10 @@ +#!/bin/bash -ex + +. ci/common.sh + +remote=git.pyrocufflink.blue/dustin/dynk8s-provisioner +t=$(tag_name ${BUILD_TAG}) +podman push dynk8s-provider:${t} ${remote}:${t} +if [ "${BRANCH_NAME}" = master ]; then + podman push dynk8s-provider:${t} ${remote}:${t} +fi diff --git a/ci/test.sh b/ci/test.sh new file mode 100644 index 0000000..6fd0a92 --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash -ex + +cargo test