Compare commits

...

2 Commits

Author SHA1 Message Date
Dustin 9808245f85 ci: Add Jenkins build pipeline
dustin/tmpl/pipeline/head There was a failure building this commit Details
We'll build and publish `tmpl` with a container image, to make it easier
for other container images to include it.
2024-01-13 10:44:44 -06:00
Dustin 4c7192582d checksum: Fix EOF handling
Using `Read::read_exact` is not the correct way to read a file in
chunks.  When it returns `UnexpectedEof`, the buffer has data in it, but
is zero-padded to the end.  This causes the calculated checksum to be
incorrect.
2024-01-12 09:42:31 -06:00
7 changed files with 120 additions and 7 deletions

4
.containerignore Normal file
View File

@ -0,0 +1,4 @@
*
!src
!Cargo.toml
!Cargo.lock

25
Containerfile Normal file
View File

@ -0,0 +1,25 @@
FROM registry.fedoraproject.org/fedora-minimal:39 AS build
RUN --mount=type=cache,target=/var/cache \
microdnf install -y \
--setopt install_weak_deps=0 \
cargo\
&& :
COPY . /src
WORKDIR /src
RUN cargo build --release --locked
FROM registry.fedoraproject.org/fedora-minimal:39
COPY --from=build /src/target/release/tmpl /usr/local/bin
ENTRYPOINT ["/usr/local/bin/tmpl"]
LABEL name='tmpl' \
vendor='Dustin C. Hatch' \
license='MIT OR APACHE-2.0' \
version='0.1.0'

64
ci/Jenkinsfile vendored Normal file
View File

@ -0,0 +1,64 @@
pipeline {
agent none
stages {
stage('tmpl') {
matrix {
axes {
axis {
name 'ARCH'
values 'amd64', 'arm64'
}
}
stages {
stage('tmpl') {
agent {
kubernetes {
yamlFile 'podTemplate.yaml'
yamlMergeStrategy merge()
defaultContainer 'build'
nodeSelector "kubernetes.io/arch=${ARCH}"
}
}
stages {
stage {
stage('Build') {
steps {
sh '. ci/build.sh'
}
post {
success {
archiveArtifacts "${ARCH}/*"
}
}
}
stage('Publish') {
env {
REGISTRY_AUTH_FILE = "${env.WORKSPACE_TMP}/auth.json"
}
steps {
withCredentials([usernamePassword(
credentialsId: 'jenkins-packages',
usernameVariable: 'BUILDAH_USERNAME',
passwordVariable: 'BUILDAH_PASSWORD',
)]) {
sh """
buildah login \
--username \${BUILDAH_USERNAME} \
--password \${BUILDAH_PASSWORD} \
git.pyrocufflink.net
"""
}
sh '. ci/publish.sh'
}
}
}
}
}
}
}
}
}
}

7
ci/build.sh Normal file
View File

@ -0,0 +1,7 @@
. ci/common.sh
buildah push "${IMAGE_NAME}:${TAG}"
buildah push "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:${TAG}-${BUILD_NUMBER}"
if [ ${BRANCH_NAME} = master ]; then
buildah push "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:latest"
fi

13
ci/common.sh Normal file
View File

@ -0,0 +1,13 @@
escape_name() {
echo "$1" \
| tr A-Z a-z \
| sed -e 's/[^a-zA-Z0-9._-]/-/g' -e 's/^[.-]/_/'
}
REGISTRY_URL=git.pyrocufflink.net
NAMESPACE=containerimages
NAME="${JOB_NAME#*/}"
NAME=$(escape_name "${NAME%/*}")
TAG=$(escape_name "${BRANCH_NAME}")
IMAGE_NAME="${REGISTRY_URL}/${NAMESPACE}/${NAME}"

3
ci/publish.sh Normal file
View File

@ -0,0 +1,3 @@
. ci/common.sh
buildah build -t "${IMAGE_NAME}:${TAG}" .

View File

@ -303,14 +303,11 @@ fn checksum(path: impl AsRef<Path>) -> std::io::Result<Vec<u8>> {
let mut blake = Blake2b512::new(); let mut blake = Blake2b512::new();
loop { loop {
let mut buf = vec![0u8; 16384]; let mut buf = vec![0u8; 16384];
match f.read_exact(&mut buf) { let sz = f.read(&mut buf)?;
Ok(_) => blake.update(buf), if sz == 0 {
Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => { break;
blake.update(buf);
break;
}
Err(e) => return Err(e),
} }
blake.update(&buf[..sz]);
} }
Ok(blake.finalize().to_vec()) Ok(blake.finalize().to_vec())
} }