Skip to content

Commit

Permalink
44 Build Once and Use Git-Tags
Browse files Browse the repository at this point in the history
This removes the .version files and uses git-tags. This also builds canu
inside of the RPM spec file, and then uses the RPM from there.

The spec file will create a canu user.

Since the Docker image is still Debian, this does not incorporate the
RPM into the image build.
  • Loading branch information
rustydb committed Oct 11, 2022
1 parent dbc13da commit 06aa701
Show file tree
Hide file tree
Showing 28 changed files with 357 additions and 408 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
select = B,B9,BLK,C,D,DAR,E,F,I,W,C4,N
ignore = E203,E501,W503,WPS111,WPS201,WPS202,WPS210,WPS211,WPS213,WPS219,WPS220,WPS221,WPS216,WPS226,WPS231,WPS232,WPS305,WPS336,WPS432,I001,I003,I004,I005
ignore = E203,E501,W503,WPS111,WPS201,WPS202,WPS210,WPS211,WPS213,WPS219,WPS220,WPS221,WPS216,WPS226,WPS231,WPS232,WPS305,WPS336,WPS432,I001,I003,I004,I005,BLK100
max-line-length = 120
application-import-names = canu,tests
import-order-style = google
Expand Down
9 changes: 4 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
Description: What does this change do? Use examples of new options and output changes when possible. If other changes were made list these as well in a list.

PR checklist (you may replace this section):
- [ ] I have run `nox` locally and all tests, linting, and code coverage pass.
- [ ] I have run `nox` locally and all tests, linting, and code coverage pass
- [ ] I have added new tests to cover the new code
- [ ] My code follows the style guidelines of this project
- [ ] If adding a new file, I have updated pyinstaller.py
- [ ] I have updated the appropriate Changelog entries in readme.md
- [ ] I have incremented the version in the readme.md
- [ ] I have incremented the version in `canu/.version` and `.version`
- [ ] If adding a new file, I have updated `pyinstaller.py`
- [ ] I have updated the appropriate Changelog entries in `README.md`
- [ ] I have incremented the version in the `README.md`

### Issues and Related PRs

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Python package
name: Python

on: [push]

jobs:
nox:
name: Coverage, Docs, Lint, and Unit Tests
name: Docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Also fetch git-tags
- name: Set up Python
uses: actions/setup-python@v3
with:
Expand All @@ -16,4 +18,5 @@ jobs:
env:
GIT_REPO_NAME: "${GITHUB_REPOSITORY#*/}"
run: |
make test
pip install .[ci]
nox -e docs
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Python

on: [push]

jobs:
nox:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Also fetch git-tags
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: nox
env:
GIT_REPO_NAME: "${GITHUB_REPOSITORY#*/}"
run: |
pip install .[ci]
nox -e lint
23 changes: 23 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Python

on: [push]

jobs:
nox:
name: Tests and Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Also fetch git-tags
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: nox
env:
GIT_REPO_NAME: "${GITHUB_REPOSITORY#*/}"
run: |
pip install .[ci]
nox -e tests
nox -e cover
1 change: 0 additions & 1 deletion .version

This file was deleted.

24 changes: 7 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,22 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

FROM artifactory.algol60.net/csm-docker/stable/csm-docker-sle-python:3.10

# create canu user
RUN useradd -ms /bin/bash canu
FROM artifactory.algol60.net/csm-docker/stable/csm-docker-sle-python:3.10

# update command prompt
RUN echo 'export PS1="canu \w : "' >> /etc/bash.bashrc

# make files dir
RUN mkdir /files

# prep image layer for faster builds
COPY requirements.txt /app/canu/

RUN pip3 install -r /app/canu/requirements.txt
COPY dist/rpmbuild/RPMS/x86_64/ /files

# copy canu files
COPY . /app/canu

# install canu
RUN pip3 install --editable /app/canu/
RUN ls -l /files && \
zypper -n in --allow-unsigned-rpm -y /files/canu*.rpm

# set file perms for canu
RUN chown -R canu /app/canu /files /home
# set none root user: canu
USER canu
RUN chown -R canu /files /home

USER canu

WORKDIR /files
38 changes: 13 additions & 25 deletions Jenkinsfile.github
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

@Library('csm-shared-library') _

def isStable = env.TAG_NAME != null ? true : false
def pythonVersion = '3.10'

pipeline {
agent {
label "metal-gcp-builder"
Expand All @@ -34,23 +36,19 @@ pipeline {
}

environment {
DESCRIPTION = "CANU (CSM Automatic Network Utility) will float through a Shasta network and make switch setup and validation a breeze."
IS_STABLE = getBuildIsStable()
GIT_REPO_NAME = getRepoName()
BUILD_METADATA = getRpmRevision(isStable: env.IS_STABLE)
IMAGE_VERSION = getDockerBuildVersion(isStable: env.IS_STABLE)
DOCKER_ARGS = getDockerBuildArgs(name: "cray-${getRepoName()}", description: env.DESCRIPTION)
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()
}

stages {
stages {

stage("Prepare: RPM") {
stage('Prepare: RPM') {
agent {
docker {
label 'docker'
image "artifactory.algol60.net/csm-docker/stable/csm-docker-sle-python:${pythonVersion}"
reuseNode true
// Support docker in docker for clamav scan
args "-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker --group-add 999"
}
}
steps {
Expand All @@ -61,22 +59,12 @@ pipeline {
}
}

stage("Build: Binary") {
steps {
script {
sh "make binary"
}
}
}


stage("Build: RPMs") {
stage('Build: RPMs') {
agent {
docker {
label 'docker'
image "artifactory.algol60.net/csm-docker/stable/csm-docker-sle-python:${pythonVersion}"
reuseNode true
// Support docker in docker for clamav scan
args "-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker --group-add 999"
}
}
steps {
Expand All @@ -87,10 +75,10 @@ pipeline {
stage('Publish: RPMs') {
steps {
script {
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/RPMS/x86_64/*.rpm", os: "sle-15sp2", arch: "x86_64", isStable: env.IS_STABLE)
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/RPMS/x86_64/*.rpm", os: "sle-15sp3", arch: "x86_64", isStable: env.IS_STABLE)
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/SRPMS/*.rpm", os: "sle-15sp2", arch: "src", isStable: env.IS_STABLE)
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/SRPMS/*.rpm", os: "sle-15sp3", arch: "src", isStable: env.IS_STABLE)
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/RPMS/x86_64/*.rpm", os: "sle-15sp2", arch: "x86_64", isStable: isStable)
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/RPMS/x86_64/*.rpm", os: "sle-15sp3", arch: "x86_64", isStable: isStable)
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/SRPMS/*.rpm", os: "sle-15sp2", arch: "src", isStable: isStable)
publishCsmRpms(component: env.GIT_REPO_NAME, pattern: "dist/rpmbuild/SRPMS/*.rpm", os: "sle-15sp3", arch: "src", isStable: isStable)
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions pyinstaller.sh → MANIFEST.in
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#
# MIT License
#
# (C) Copyright [2022] Hewlett Packard Enterprise Development LP
# (C) Copyright 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"),
Expand All @@ -20,9 +20,6 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# Pyinstaller needs a .spec file but it conflicts with rpm builds
cp pyinstaller.py pyinstaller.spec
pyinstaller --clean -y --dist ./dist/linux --workpath /tmp pyinstaller.spec
rm pyinstaller.spec
chown -R --reference=. ./dist/linux
#
include README.md
include LICENSE
41 changes: 18 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,41 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
name ?= ${GIT_REPO_NAME}
NAME ?= ${GIT_REPO_NAME}

version ?= $(shell cat .version)
build_image := cdrx/pyinstaller-linux:python3
ifeq ($(IMAGE_VERSION),)
IMAGE_VERSION := $(shell git describe --tags | tr -s '-' '_' | tr -d '^v')
endif

# Default release if not set
BUILD_METADATA ?= "1~development~$(shell git rev-parse --short HEAD)"
ifeq ($(VERSION),)
VERSION := $(shell git describe --tags | tr -s '-' '~' | tr -d '^v')
endif

spec_file := ${name}.spec
source_name := ${name}-${version}
SPEC_FILE := ${NAME}.spec
SOURCE_NAME := ${NAME}-${VERSION}

build_dir := $(PWD)/dist/rpmbuild
source_path := ${build_dir}/SOURCES/${source_name}.tar.bz2
IMAGE_VERSION ?= ${IMAGE_VERSION}
BUILD_DIR := $(PWD)/dist/rpmbuild
SOURCE_PATH := ${BUILD_DIR}/SOURCES/${SOURCE_NAME}.tar.bz2

all : prepare binary test rpm
rpm: rpm_package_source rpm_build_source rpm_build

prepare:
rm -rf dist
mkdir -p $(build_dir)/SPECS $(build_dir)/SOURCES
cp $(spec_file) $(build_dir)/SPECS/

binary:
docker run --rm -v $(PWD):/src $(build_image) ./pyinstaller.sh

test:
docker run --rm -v $(PWD):/src $(build_image) nox
mkdir -p $(BUILD_DIR)/SPECS $(BUILD_DIR)/SOURCES
cp $(SPEC_FILE) $(BUILD_DIR)/SPECS/

image:
docker build --no-cache --pull ${DOCKER_ARGS} --tag 'cray-${name}:${IMAGE_VERSION}' .
docker build --no-cache --pull --tag 'cray-${NAME}:${IMAGE_VERSION}' .

snyk:
$(MAKE) -s image | xargs --verbose -n 1 snyk container test
$(MAKE) -s image | xargs --verbose -n 1 snyk container test

rpm_package_source:
tar --transform 'flags=r;s,^,/$(source_name)/,' --exclude .git --exclude .nox --exclude dist/rpmbuild -cvjf $(source_path) .
tar --transform 'flags=r;s,^,/$(SOURCE_NAME)/,' --exclude .nox --exclude dist/rpmbuild -cvjf $(SOURCE_PATH) .

rpm_build_source:
BUILD_METADATA=$(BUILD_METADATA) rpmbuild -ts $(source_path) --define "_topdir $(build_dir)"
rpmbuild -ts $(SOURCE_PATH) --define "_topdir $(BUILD_DIR)"

rpm_build:
BUILD_METADATA=$(BUILD_METADATA) rpmbuild -ba $(spec_file) --define "_topdir $(build_dir)"
rpmbuild -ba $(SPEC_FILE) --define "_topdir $(BUILD_DIR)"
File renamed without changes.
50 changes: 44 additions & 6 deletions canu.spec
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
#
# MIT License
#
# (C) Copyright 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
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
%global __python /usr/local/bin/python3.10
%define __pyinstaller /home/jenkins/.local/bin/pyinstaller

Name: canu
BuildArch: x86_64
License: MIT License
Summary: CSM Automatic Network Utility
Version: %(cat .version)
Release: %(echo ${BUILD_METADATA})
Version: %(echo $VERSION)
Release: 1
Source: %{name}-%{version}.tar.bz2
Vendor: Cray Inc.
Group: Metal
Vendor: Cray HPE

%description
CSM Automatic Network Utility
%{summary}

%prep
%setup -q

%build
# PIP and Setuptools updates.
%{__python} -m pip install -U pyinstaller
%{__python} -m pip install -q build
%{__python} -m build

cp pyinstaller.py pyinstaller.spec
%{__pyinstaller} --clean -y --dist ./dist/linux --workpath /tmp pyinstaller.spec
rm pyinstaller.spec
chown -R --reference=. ./dist/linux

%install
mkdir -p %{buildroot}%{_bindir}
install -m 755 dist/linux/canu %{buildroot}%{_bindir}/canu

%pre
getent passwd canu >/dev/null || \
useradd -U -m -s -c "CANU user" /bin/bash canu

%files
%{_bindir}/canu
%attr(755, canu, canu) %{_bindir}/canu
%license LICENSE

%changelog
1 change: 0 additions & 1 deletion canu/.version

This file was deleted.

Loading

0 comments on commit 06aa701

Please sign in to comment.