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

MTL-2171 #47

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
ARG GO_VERSION
ARG SLE_VERSION
FROM artifactory.algol60.net/csm-docker/stable/csm-docker-sle-go:${GO_VERSION}-SLES${SLE_VERSION} as builder
FROM artifactory.algol60.net/csm-docker/stable/csm-docker-sle-go:${GO_VERSION} as builder
WORKDIR /workspace
COPY . ./

Expand Down
88 changes: 66 additions & 22 deletions Jenkinsfile.github
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

def goImage = 'artifactory.algol60.net/csm-docker/stable/csm-docker-sle-go'

// Define the distro that the major.minor and major.minor.patch Docker tags publish to.
def mainSleVersion = '15.4'

def isStable = env.TAG_NAME != null ? true : false
pipeline {

Expand All @@ -46,9 +43,10 @@ pipeline {
DOCKER_ARGS = getDockerBuildArgs(name: getRepoName(), description: 'A cloud-init DataSource.')
NAME = getRepoName()
IS_STABLE = "${isStable}"
PRIMARY_NODE = "${env.NODE_NAME}"
GO_VERSION = sh(returnStdout: true, script: 'grep -Eo "^go .*" go.mod | cut -d " " -f2').trim()
IMAGE_VERSION = sh(returnStdout: true, script: "git describe --tags | tr -s '-' '_' | tr -d '^v'").trim()
VERSION = sh(returnStdout: true, script: "git describe --tags | tr -s '-' '~' | tr -d '^v'").trim()
IMAGE_VERSION = sh(returnStdout: true, script: "git describe --tags | tr -s '-' '_' | sed 's/^v//'").trim()
VERSION = sh(returnStdout: true, script: "git describe --tags | tr -s '-' '~' | sed 's/^v//'").trim()
}

stages {
Expand All @@ -65,73 +63,119 @@ pipeline {
}
}

stage('Build & Publish: RPM') {
stage('Build & Publish') {

matrix {

agent {
node {
label "metal-gcp-builder"
customWorkspace "${env.WORKSPACE}/${sleVersion}/${env.GO_VERSION}"
}
environment {
DOCKER_ARCH = sh(returnStdout: true, script: "[ ${ARCH} == 'x86_64' ] && echo -n 'amd64' || echo -n 'arm64'")
BUILD_DIR = "${env.WORKSPACE}/dist/rpmbuild/${ARCH}"
}

axes {

axis {
name 'sleVersion'
values 15.3, 15.4
name 'ARCH'
values 'x86_64'
}
}

stages {

stage('Build: setup') {
steps {
lock('docker-image-pull') {
sh "docker pull --platform linux/${DOCKER_ARCH} ${goImage}:${env.GO_VERSION}"
sh "docker tag ${goImage}:${env.GO_VERSION} ${goImage}:${env.GO_VERSION}-${DOCKER_ARCH}"
}
}
}

stage('Prepare: RPMs') {
agent {
docker {
label 'docker'
label "${PRIMARY_NODE}"
reuseNode true
image "${goImage}:${env.GO_VERSION}-SLES${sleVersion}"
args "-v /home/jenkins/.ssh:/home/jenkins/.ssh --platform linux/${DOCKER_ARCH}"
image "${goImage}:${env.GO_VERSION}-${DOCKER_ARCH}"
}
}

steps {
runLibraryScript("addRpmMetaData.sh", "${env.NAME}.spec")
sh "make rpm_prepare"
sh "make prepare"
sh "git update-index --assume-unchanged ${env.NAME}.spec"
}
}

stage('Build: RPMs') {
agent {
docker {
label 'docker'
label "${PRIMARY_NODE}"
reuseNode true
image "${goImage}:${env.GO_VERSION}-SLES${sleVersion}"
args "-v /home/jenkins/.ssh:/home/jenkins/.ssh --platform linux/${DOCKER_ARCH}"
image "${goImage}:${env.GO_VERSION}-${DOCKER_ARCH}"
}
}

steps {
sh "make rpm"
withCredentials([
usernamePassword(
credentialsId: 'artifactory-algol60-readonly',
usernameVariable: 'ARTIFACTORY_USER',
passwordVariable: 'ARTIFACTORY_TOKEN'
)
]) {
script {
sh "make rpm"
}
}
}
}

stage('Publish: RPMs') {
agent {
docker {
label "${PRIMARY_NODE}"
reuseNode true
args "-v /home/jenkins/.ssh:/home/jenkins/.ssh --platform linux/${DOCKER_ARCH}"
image "${goImage}:${env.GO_VERSION}-${DOCKER_ARCH}"
}
}

steps {
script {
def sleVersion = sh(returnStdout: true, script: 'awk -F= \'/VERSION_ID/{gsub(/["]/,""); print \$NF}\' /etc/os-release').trim()
def sles_version_parts = "${sleVersion}".tokenize('.')
def sles_major = "${sles_version_parts[0]}"
def sles_minor = "${sles_version_parts[1]}"
publishCsmRpms(
arch: "x86_64",
arch: "${ARCH}",
component: env.NAME,
isStable: isStable,
os: "sle-${sles_major}sp${sles_minor}",
pattern: "dist/rpmbuild/RPMS/x86_64/*.rpm",
pattern: "dist/rpmbuild/${ARCH}/RPMS/${ARCH}/*.rpm",
)
publishCsmRpms(
arch: "src",
component: env.NAME,
isStable: isStable,
os: "sle-${sles_major}sp${sles_minor}",
pattern: "dist/rpmbuild/SRPMS/*.rpm",
pattern: "dist/rpmbuild/${ARCH}/SRPMS/*.rpm",
)
publishCsmRpms(
arch: "${ARCH}",
component: env.NAME,
isStable: isStable,
os: "noos",
pattern: "dist/rpmbuild/${ARCH}/RPMS/${ARCH}/*.rpm",
)
publishCsmRpms(
arch: "src",
component: env.NAME,
isStable: isStable,
os: "noos",
pattern: "dist/rpmbuild/${ARCH}/SRPMS/*.rpm",
)
}
}
Expand Down
34 changes: 20 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# MIT License
#
#
# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
#
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Expand All @@ -26,11 +26,11 @@ NAME := $(shell basename $(shell pwd))
endif

ifeq ($(IMAGE_VERSION),)
IMAGE_VERSION := $(shell git describe --tags | tr -s '-' '_' | tr -d '^v')
IMAGE_VERSION := $(shell git describe --tags | tr -s '-' '_' | sed 's/^v//')
endif

ifeq ($(VERSION),)
VERSION := $(shell git describe --tags | tr -s '-' '~' | tr -d '^v')
VERSION := $(shell git describe --tags | tr -s '-' '~' | sed 's/^v//')
endif

ifeq ($(GO_VERSION),)
Expand All @@ -51,11 +51,13 @@ TAG?=latest
.BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
CHANGELOG_VERSION_ORIG=$(grep -m1 \## CHANGELOG.MD | sed -e "s/\].*\$//" |sed -e "s/^.*\[//")
CHANGELOG_VERSION=$(shell grep -m1 \ \[[0-9]*.[0-9]*.[0-9]*\] CHANGELOG.MD | sed -e "s/\].*$$//" |sed -e "s/^.*\[//")
TEST_OUTPUT_DIR ?= $(CURDIR)/build/results
SPEC_FILE := ${NAME}.spec
SOURCE_NAME := ${NAME}-${VERSION}

BUILD_DIR ?= $(PWD)/dist/rpmbuild
SPEC_FILE ?= ${NAME}.spec
SOURCE_NAME ?= ${NAME}-${VERSION}
SOURCE_PATH := ${BUILD_DIR}/SOURCES/${SOURCE_NAME}.tar.bz2
TEST_OUTPUT_DIR ?= $(CURDIR)/build/results


# if we're an automated build, use .GIT_COMMIT_AND_BRANCH as-is, else add '-dirty'
ifneq "$(origin BUILD_NUMBER)" "environment"
Expand Down Expand Up @@ -84,7 +86,7 @@ endif

all: fmt lint build

rpm: rpm_prepare rpm_package_source rpm_build_source rpm_build
rpm: prepare rpm_package_source rpm_build_source rpm_build

help:
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
Expand All @@ -111,6 +113,7 @@ clean:
rm -vf \
$(CURDIR)/build/results/coverage/* \
$(CURDIR)/build/results/unittest/* \
$(RM) -rf $(BUILD_DIR)

test: build
mkdir -pv $(TEST_OUTPUT_DIR)/unittest $(TEST_OUTPUT_DIR)/coverage
Expand Down Expand Up @@ -143,19 +146,22 @@ tidy:
build: fmt vet
go build -o bin/basecamp ./cmd/main.go

rpm_prepare:
prepare:
rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/SPECS $(BUILD_DIR)/SOURCES
cp $(SPEC_FILE) $(BUILD_DIR)/SPECS/

# touch the archive before creating it to prevent 'tar: .: file changed as we read it' errors
rpm_package_source:
tar --transform 'flags=r;s,^,/$(SOURCE_NAME)/,' --exclude .git --exclude dist -cvjf $(SOURCE_PATH) .
touch $(SOURCE_PATH)
tar --transform 'flags=r;s,^,/$(SOURCE_NAME)/,' --exclude .nox --exclude dist/rpmbuild --exclude ${SOURCE_NAME}.tar.bz2 -cvjf $(SOURCE_PATH) .

rpm_build_source:
rpmbuild --nodeps -ts $(SOURCE_PATH) --define "_topdir $(BUILD_DIR)"
rpmbuild -bs $(BUILD_DIR)/SPECS/$(SPEC_FILE) --target ${ARCH} --define "_topdir $(BUILD_DIR)"

rpm_build:
rpmbuild --nodeps -ba $(SPEC_FILE) --define "_topdir $(BUILD_DIR)"
rpmbuild -ba $(BUILD_DIR)/SPECS/$(SPEC_FILE) --target ${ARCH} --define "_topdir $(BUILD_DIR)"


doc:
godoc -http=:8080 -index
Expand Down
12 changes: 6 additions & 6 deletions metal-basecamp.spec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# MIT License
#
#
# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
#
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Expand Down Expand Up @@ -64,13 +64,13 @@ A cloud-init datasource that runs out of podman.
env
%setup -q
echo bucket: %{bucket} tag: %{image_tag} current_branch: %{current_branch}
timeout 15m sh -c 'until skopeo inspect docker://%{image}; do sleep 10; done'
timeout 15m sh -c 'until skopeo inspect --creds=%(echo $ARTIFACTORY_USER:$ARTIFACTORY_TOKEN) docker://%{image}; do sleep 10; done'

%build
sed -e 's,@@%{short_name}-image@@,%{image},g' \
-e 's,@@%{short_name}-path@@,%{imagedir}/%{image_tar},g' \
-i init/%{short_name}-init.sh
skopeo copy docker://%{image} docker-archive:%{image_tar}
skopeo copy --src-creds=%(echo $ARTIFACTORY_USER:$ARTIFACTORY_TOKEN) docker://%{image} docker-archive:%{image_tar}

%install
install -D -m 0644 -t %{buildroot}%{_unitdir} init/%{short_name}.service
Expand Down