basic stuff. still need to log into the repo.
All checks were successful
git.cronocide.net/container-copy/pipeline/head This commit looks good
All checks were successful
git.cronocide.net/container-copy/pipeline/head This commit looks good
This commit is contained in:
parent
1c1d917f4f
commit
d1ee05af9e
51
Jenkinsfile
vendored
51
Jenkinsfile
vendored
@ -7,62 +7,15 @@ pipeline {
|
|||||||
parameters {
|
parameters {
|
||||||
string(name: 'GIT_REPO_NAME', defaultValue: 'git.cronocide.net', description: 'The hostname of the git repository.')
|
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.')
|
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 {
|
environment {
|
||||||
WORKSPACE_PATH = "/opt/nomad/alloc/${NOMAD_ALLOC_ID}/${NOMAD_TASK_NAME}${WORKSPACE}"
|
WORKSPACE_PATH = "/opt/nomad/alloc/${NOMAD_ALLOC_ID}/${NOMAD_TASK_NAME}${WORKSPACE}"
|
||||||
DESCRIPTION = "Another amazing piece of software written by Cronocide."
|
DESCRIPTION = "Another amazing piece of software written by Cronocide."
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Prepare') {
|
stage('Copy') {
|
||||||
when { expression { params.PREPARE } }
|
|
||||||
steps {
|
steps {
|
||||||
withEnv(['ACTION=cicd_prepare']) {
|
withEnv(['ACTION=cicd_copy']) {
|
||||||
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']) {
|
|
||||||
sh ( script: './build.sh')
|
sh ( script: './build.sh')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
82
build.sh
82
build.sh
@ -86,77 +86,27 @@ error() {
|
|||||||
# | _|| |_| | .` | (__ | | | | (_) | .` \__ \
|
# | _|| |_| | .` | (__ | | | | (_) | .` \__ \
|
||||||
# |_| \___/|_|\_|\___| |_| |___\___/|_|\_|___/
|
# |_| \___/|_|\_|\___| |_| |___\___/|_|\_|___/
|
||||||
|
|
||||||
|
get_regctl() {
|
||||||
cicd_prepare() {
|
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)
|
||||||
# Prepare the build environment.
|
wget -q "$REGCTL_URL" -O regctl
|
||||||
echo "Preparing for Build"
|
chmod +x regctl
|
||||||
# TODO
|
|
||||||
echo "Completed Preparing for Build"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cicd_inspect() {
|
cicd_copy() {
|
||||||
# Information about the build environment.
|
# Download regctl
|
||||||
echo "Inspecting Build Environment"
|
echo "Downloading regctl..."
|
||||||
env
|
get_regctl
|
||||||
echo "Completed Inspecting Build Environment"
|
# Log in to repo
|
||||||
}
|
|
||||||
|
|
||||||
cicd_build() {
|
# Copy repos
|
||||||
# Build a new software artifact.
|
echo "Copying repos..."
|
||||||
__missing_reqs "docker" && exit 1
|
for i in "${REPOS_TO_COPY[@]}"; do
|
||||||
echo "Building Software"
|
./regctl image copy $i
|
||||||
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
|
|
||||||
done
|
done
|
||||||
[[ "$SKIP_DOCKER_LOGIN" != "1" ]] && docker login "$GIT_REPO_NAME" -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
|
echo "Done copying images"
|
||||||
docker push ${COMMIT_TAG}
|
|
||||||
docker push ${LATEST_TAG}
|
|
||||||
echo "Completed Publishing Software"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 "$USERN" ] && export USERN=cronocide
|
||||||
[ -z "$GIT_REPO_NAME" ] && export GIT_REPO_NAME=git.cronocide.net
|
[ -z "$GIT_REPO_NAME" ] && export GIT_REPO_NAME=git.cronocide.net
|
||||||
|
|
||||||
|
|
||||||
# Define needed build strings
|
# Define needed build strings
|
||||||
DIR=$(cd $(dirname $BASH_SOURCE[0]) && pwd)
|
DIR=$(cd $(dirname $BASH_SOURCE[0]) && pwd)
|
||||||
PROJECT_NAME="$(git config --local remote.origin.url|sed -n 's#.*/\([^.]*\)\.git#\1#p')"
|
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}"
|
COMMIT_TAG="${IMAGE_NAME}:${GIT_COMMIT}"
|
||||||
LATEST_TAG="${IMAGE_NAME}:latest"
|
LATEST_TAG="${IMAGE_NAME}:latest"
|
||||||
|
|
||||||
|
REPOS_TO_COPY=("busybox:latest git.cronocide.net/cronocide/busybox:latest")
|
||||||
# Run specified build task
|
# Run specified build task
|
||||||
"$ACTION"
|
"$ACTION"
|
||||||
|
Reference in New Issue
Block a user