Skip to content

Commit

Permalink
Create workflow for pushing mayastor images to dockerhub (CAS-450)
Browse files Browse the repository at this point in the history
This commit does a couple of things:
* ci/cd tests are run only for pull requests and develop (see below)
* schedules nightly builds of develop every day at 2am
* nightly job on develop pushes images to dockerhub
* a commit to master/release branch pushes images to dockerhub
* new script for building & pushing imgs usable even w/o jenkins
  • Loading branch information
Jan Kryl committed Sep 17, 2020
1 parent 90a0513 commit 4d7d20b
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 8 deletions.
58 changes: 54 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
pipeline {
agent none
triggers {
cron('0 2 * * *')
}

stages {
stage('linter') {
agent { label 'nixos-mayastor' }
when {
beforeAgent true
anyOf {
branch 'PR-*'
allOf {
branch 'develop'
triggeredBy 'TimerTrigger'
}
}
}
steps {
sh 'nix-shell --run "cargo fmt --all -- --check"'
sh 'nix-shell --run "cargo clippy --all-targets -- -D warnings"'
sh 'nix-shell --run "./scripts/js-check.sh"'
}
}
stage('test') {
when {
beforeAgent true
anyOf {
branch 'PR-*'
allOf {
branch 'develop'
triggeredBy 'TimerTrigger'
}
}
}
parallel {
stage('rust unit tests') {
agent { label 'nixos-mayastor' }
Expand Down Expand Up @@ -49,14 +72,41 @@ pipeline {
}
}
}
stage('dev images') {
agent { label 'nixos-mayastor' }
steps {
sh 'nix-build --no-out-link -A images.mayastor-dev-image'
sh 'nix-build --no-out-link -A images.mayastor-csi-dev-image'
sh 'nix-build --no-out-link -A images.moac-image'
sh 'nix-store --delete /nix/store/*docker-image*'
}
}
}
}
stage('images') {
stage('push images') {
agent { label 'nixos-mayastor' }
when {
beforeAgent true
anyOf {
branch 'master'
branch 'release/*'
allOf {
branch 'develop'
triggeredBy 'TimerTrigger'
}
}
}
steps {
sh 'nix-build --no-out-link -A images.mayastor-dev-image'
sh 'nix-build --no-out-link -A images.mayastor-csi-dev-image'
sh 'nix-build --no-out-link -A images.moac-image'
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'echo $PASSWORD | docker login -u $USERNAME --password-stdin'
}
sh './scripts/release.sh'
}
post {
always {
sh 'docker logout'
sh 'docker image prune --all --force'
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions doc/jenkins.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ for system configuration of nodes (as opposed to using ansible, salt, etc.).
};
environment.systemPackages = with pkgs; [
wget vim git
wget curl vim git
];
}
```
Expand Down Expand Up @@ -144,6 +144,8 @@ for system configuration of nodes (as opposed to using ansible, salt, etc.).
boot.kernelModules = [ "nbd" "xfs" "nvme_tcp" "kvm_intel" ];
boot.extraModprobeConfig = "options kvm_intel nested=1";
virtualisation.docker.enable = true;
networking.firewall.enable = false;
networking.hostName = "ci-slave";
Expand All @@ -164,16 +166,16 @@ for system configuration of nodes (as opposed to using ansible, salt, etc.).
# account is also possible.
users.users.mayastor = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
extraGroups = [ "wheel" "docker" ]; # Enable ‘sudo’ for the user.
password = "";
openssh.authorizedKeys.keys = [ "ssh-rsa your-key ..." ];
};
users.users.jenkins.extraGroups = [ "wheel" ];
users.users.jenkins.extraGroups = [ "wheel" "docker" ];
users.users.jenkins.openssh.authorizedKeys.keys = [ "ssh-rsa key used by Jenkins master ..." ];
environment.systemPackages = with pkgs; [
wget vim git jdk openiscsi nvme-cli
wget curl vim git jdk openiscsi nvme-cli
];
}
```
Expand Down
88 changes: 88 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash

# Build and upload mayastor docker images to dockerhub repository.
# Use --dry-run to just see what would happen.
# The script assumes that a user is logged on to dockerhub.

set -euo pipefail

docker_tag_exists() {
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 1>/dev/null 2>&1
}

get_tag() {
vers=`git tag --points-at HEAD`
if [ -z "$vers" ]; then
vers=`git rev-parse --short HEAD`
fi
echo -n $vers
}

DOCKER="docker"
NIX_BUILD="nix-build"
RM="rm"
SCRIPTDIR=$(dirname "$0")
IMAGES="mayastor mayastor-csi moac"
TAG=`get_tag`
BRANCH=`git rev-parse --abbrev-ref HEAD`
UPLOAD=

# Check if all needed tools are installed
curl --version >/dev/null
if [ $? -ne 0 ]; then
echo "Missing curl - install it and put it to your PATH"
exit 1
fi
$DOCKER --version >/dev/null
if [ $? -ne 0 ]; then
echo "Missing docker - install it and put it to your PATH"
exit 1
fi
if [ "$#" -gt 0 ]; then
if [ "$1" == "--dry-run" ]; then
DOCKER="echo $DOCKER"
NIX_BUILD="echo $NIX_BUILD"
RM="echo $RM"
else
echo "Usage: release.sh [--dry-run]"
fi
fi

cd $SCRIPTDIR/..

# Build all images first
for name in $IMAGES; do
archive=${name}-image
image=mayadata/$name
if docker_tag_exists $image $TAG; then
echo "Skipping $image:$TAG that already exists"
else
echo "Building $image:$TAG ..."
$NIX_BUILD --out-link $archive --no-build-output -A images.$archive
$DOCKER load -i $archive
$RM $archive
UPLOAD="$UPLOAD $image"
fi
done

# Nothing to upload?
[ -z "$UPLOAD" ] && exit 0

# Upload them
for img in $UPLOAD; do
echo "Uploading $img:$TAG to registry ..."
$DOCKER push $img:$TAG
done

# Create aliases
if [ "$BRANCH" == "develop" ]; then
for img in $UPLOAD; do
$DOCKER tag $img:$TAG $img:develop
$DOCKER push $img:develop
done
elif [ "$BRANCH" == "master" ]; then
for img in $UPLOAD; do
$DOCKER tag $img:$TAG $img:latest
$DOCKER push $img:latest
done
fi

0 comments on commit 4d7d20b

Please sign in to comment.