basic stuff. still need to log into the repo.
All checks were successful
git.cronocide.net/container-copy/pipeline/head This commit looks good

This commit is contained in:
Daniel Dayley 2023-10-12 23:49:42 -06:00
parent 1c1d917f4f
commit d1ee05af9e
Signed by: Cronocide
GPG Key ID: 2CB7D4B8DEB3198E
2 changed files with 18 additions and 115 deletions

51
Jenkinsfile vendored
View File

@ -7,62 +7,15 @@ pipeline {
parameters {
string(name: 'GIT_REPO_NAME', defaultValue: 'git.cronocide.net', description: 'The hostname of the git repository.')
string(name: 'USERN', defaultValue: 'cronocide', description: 'The username of the user in the git repository.')
booleanParam(name: 'PREPARE', defaultValue: true, description: 'Do preparations on this project.')
booleanParam(name: 'INSPECT', defaultValue: false, description: 'Do inspections on this project.')
booleanParam(name: 'BUILD', defaultValue: true, description: 'Do builds on this project.')
booleanParam(name: 'TEST', defaultValue: true, description: 'Do tests on this project.')
booleanParam(name: 'PUBLISH', defaultValue: true, description: 'Publish this project.')
booleanParam(name: 'DEPLOY', defaultValue: false, description: 'Deploy this project.')
}
environment {
WORKSPACE_PATH = "/opt/nomad/alloc/${NOMAD_ALLOC_ID}/${NOMAD_TASK_NAME}${WORKSPACE}"
DESCRIPTION = "Another amazing piece of software written by Cronocide."
}
stages {
stage('Prepare') {
when { expression { params.PREPARE } }
stage('Copy') {
steps {
withEnv(['ACTION=cicd_prepare']) {
sh ( script: './build.sh')
}
}
}
stage('Inspect') {
when { expression { params.INSPECT } }
steps {
withEnv(['ACTION=cicd_inspect']) {
sh ( script: './build.sh')
}
}
}
stage('Build') {
when { expression { params.BUILD } }
steps {
withEnv(['ACTION=cicd_build']) {
sh ( script: './build.sh')
}
}
}
stage('Test') {
when { expression { params.TEST } }
steps {
withEnv(['ACTION=cicd_test']) {
sh ( script: './build.sh')
}
}
}
stage('Publish') {
when { expression { params.PUBLISH } }
steps {
withEnv(['ACTION=cicd_publish']) {
sh ( script: './build.sh')
}
}
}
stage('Deploy') {
when { expression { params.DEPLOY } }
steps {
withEnv(['ACTION=cicd_deploy']) {
withEnv(['ACTION=cicd_copy']) {
sh ( script: './build.sh')
}
}

View File

@ -86,77 +86,27 @@ error() {
# | _|| |_| | .` | (__ | | | | (_) | .` \__ \
# |_| \___/|_|\_|\___| |_| |___\___/|_|\_|___/
cicd_prepare() {
# Prepare the build environment.
echo "Preparing for Build"
# TODO
echo "Completed Preparing for Build"
get_regctl() {
REGCTL_URL=$(curl -s -L "https://api.github.com/repos/regclient/regclient/releases/latest" | grep browser_download_url | grep linux | grep amd | grep regctl | cut -d '"' -f 4)
wget -q "$REGCTL_URL" -O regctl
chmod +x regctl
}
cicd_inspect() {
# Information about the build environment.
echo "Inspecting Build Environment"
env
echo "Completed Inspecting Build Environment"
}
cicd_copy() {
# Download regctl
echo "Downloading regctl..."
get_regctl
# Log in to repo
cicd_build() {
# Build a new software artifact.
__missing_reqs "docker" && exit 1
echo "Building Software"
docker build --pull=true \
--label "org.opencontainers.image.vendor=cronocide.net" \
--label "org.opencontainers.image.title=${PROJECT_NAME}" \
--label "org.opencontainers.image.url=https://${GIT_REPO_NAME}" \
--label "org.opencontainers.image.source=https://${IMAGE_NAME}" \
--label "net.cronocide.build-info.git-repo=${GIT_URL}" \
--label "net.cronocide.build-info.git-branch=${GIT_BRANCH}" \
--label "net.cronocide.build-info.git-commit=${GIT_COMMIT}" \
--label "net.cronocide.build-info.build-time=$(date -u)" \
--tag="$COMMIT_TAG" \
--tag="$LATEST_TAG" \
.
echo "Completed Building Software"
}
cicd_test() {
# Run tests on the built software artifact.
echo "Testing Software"
# TODO
echo "Completed Testing Software"
}
cicd_publish() {
# Publish the software to artifact repositories.
__missing_reqs "docker" && exit 1
echo "Publishing Software"
# TODO: Improve the logic of this Docker login flow.
LOGIN_CREDS="DOCKER_USERNAME DOCKER_PASSWORD"
for CRED in $(echo "$LOGIN_CREDS"); do
[ -z "${!CRED}" ] && echo "Missing $CRED, skipping docker login." && export SKIP_DOCKER_LOGIN=1
# Copy repos
echo "Copying repos..."
for i in "${REPOS_TO_COPY[@]}"; do
./regctl image copy $i
done
[[ "$SKIP_DOCKER_LOGIN" != "1" ]] && docker login "$GIT_REPO_NAME" -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
docker push ${COMMIT_TAG}
docker push ${LATEST_TAG}
echo "Completed Publishing Software"
echo "Done copying images"
}
cicd_deploy() {
echo "Deploying Software"
# TODO: Check for a nomad folder
if ! [ -f "$PROJECT_NAME".hcl ]; then
__http_get "https://setup.cronocide.com/nomad/base.hcl" "$PROJECT_NAME".hcl
__http_get "https://setup.cronocide.com/nomad/base.volume" "$PROJECT_NAME".volume
sed_i "s#base#$PROJECT_NAME#g" "$PROJECT_NAME".hcl
sed_i "s#image:latest#$PROJECT_NAME:latest#g" "$PROJECT_NAME".hcl
sed_i "s#base#$PROJECT_NAME#g" "$PROJECT_NAME".volume
nomad volume create "$PROJECT_NAME".volume
else
nomad job run "$PROJECT_NAME".hcl
fi
echo "Completed Deploying Software"
}
# __ __ _ ___ _ _
# | \/ | /_\ |_ _| \| |
@ -175,7 +125,6 @@ __no_req "$ACTION" && error "Action $ACTION is not recognized as a valid action.
[ -z "$USERN" ] && export USERN=cronocide
[ -z "$GIT_REPO_NAME" ] && export GIT_REPO_NAME=git.cronocide.net
# Define needed build strings
DIR=$(cd $(dirname $BASH_SOURCE[0]) && pwd)
PROJECT_NAME="$(git config --local remote.origin.url|sed -n 's#.*/\([^.]*\)\.git#\1#p')"
@ -186,5 +135,6 @@ GIT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
COMMIT_TAG="${IMAGE_NAME}:${GIT_COMMIT}"
LATEST_TAG="${IMAGE_NAME}:latest"
REPOS_TO_COPY=("busybox:latest git.cronocide.net/cronocide/busybox:latest")
# Run specified build task
"$ACTION"