Commit 8e8b9673 authored by AlmAck's avatar AlmAck

Gitlab-ci integration

parent 2b9093ab
#!/usr/bin/env bash
SCRIPT_DIR=$( dirname $( readlink -e $0 ) )
source "$SCRIPT_DIR/../.build-lib/ci-iso-deploy-library.sh"
# rsync upload
_do upload_files
_log success "Done uploading!"
#!/usr/bin/env bash
SCRIPT_DIR=$( dirname $( readlink -e $0 ) )
source "$SCRIPT_DIR/../.build-lib/ci-library.sh"
# prepare the build environment
_log command "Setting up locale.conf..."
_do touch "/etc/locale.conf"
_do sh -c "echo 'LANG=C' >> '/etc/locale.conf'"
_do sh -c "echo 'LC_MESSAGES=C' >> '/etc/locale.conf'"
# ci-depoly-library depends on ci-library
UPLOAD_LIST=()
# Execute command and stop execution if the command fails
function _do_deploy() {
CMD=$@
_log command "$CMD"
$CMD || { _log failure "FAILED: $CMD"; _unlock_repo; exit 1; }
return $?
}
# checks whether $1 contains a globbing pattern
# returns: '$1' or '*$1*'
function _glob() {
if [[ "$1" =~ [][*?] ]]; then
echo -n "$1"
else
echo -n "*$1*"
fi
}
# takes a list of find patterns and transform it into arguments to find
function _find_args() {
local -a fargs=("-name" "$(_glob $1)"); shift
while [[ $# -gt 0 ]]; do
fargs+=("-o" "-name" "$(_glob $1)"); shift
done
echo "${fargs[@]}"
}
function list_upload_packages() {
UPLOAD_LIST+=( $(set -o noglob; find $REPODIR -name '*.iso.*' \( $(_find_args ${args[@]}) \) -print) )
}
function _upload_files() {
local -a files=( $* ) # files to upload
rsync -rltoDvh \
--omit-dir-times \
--numeric-ids \
--progress \
--delay-updates \
-e "ssh -p $SSH_PORT" \
"${files[@]}" $SSH_USER@$DEPLOY_SERVER:/srv/www/rsync.chakralinux.org/releases/$DEPLOY_FOLDER/
}
function upload_files() {
_log build_step "Start uploading to $DEPLOY_FOLDER the following packages: ${UPLOAD_LIST[@]}"
_do_deploy _upload_files "${UPLOAD_LIST[@]}"
_log success "rsync upload done"
}
_ensure-var "DEPLOY_FOLDER"
_ensure-var "DEPLOY_SERVER"
_ensure-var "SSH_USER"
_ensure-var "SSH_PORT"
# Print a colored log message
function _log() {
local type="${1}"
shift
local msg="${@}"
local normal='\e[0m'
local red='\e[1;31m'
local green='\e[1;32m'
local yellow='\e[1;33m'
local cyan='\e[1;36m'
case "${type}" in
failure) echo -e "$red$msg$normal" ;;
success) echo -e "$green$msg$normal" ;;
build_step) echo -e "$green$msg$normal" ;;
command) echo -e "$cyan$msg$normal" ;;
message) echo -e "$msg" ;;
esac
}
# Execute command and stop execution if the command fails
function _do() {
CMD=$@
_log command "$CMD"
$CMD || { _log failure "FAILED: $CMD"; exit 1; }
return $?
}
# Ensure that the given environment variable has been defined and is not empty
function _ensure-var() {
local -n VARNAME=$1
if [[ -z ${VARNAME+x} ]]; then
_log failure "Environment variable $1 not defined."
exit 1
fi
}
image: chakralinux/chakra-bootstrap:latest
variables:
REPODIR: "$CI_PROJECT_DIR"
stages:
- build
- deploy-testing
- deploy-final
before_script:
# install the basic packages required to build the ISO
- pacman -Syyu --needed --noconfirm base-devel gettext wget openssh git rsync arch-install-scripts libisoburn prebootloader squashfs-tools syslinux dosfstools
# SSH setup
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
#- mkdir -p ~/.ssh
#- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# In order to properly check the server's host key, assuming you created the
# SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
# instead.
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa && chmod 700 ~/.ssh
# GPG setup
- gpg -v --batch --import <(echo "$GPG_PRIVATE_KEY")
- echo "allow-loopback-pinentry" > ~/.gnupg/gpg-agent.conf
- gpg-connect-agent reloadagent /bye
- .build-bin/prepare.sh
build_iso:
stage: build
script:
# pacstrap does not accept --config, copy the current configuration inside the container
- cp config/pacman.conf /etc/pacman.conf
- pacman -Syu --noconfirm
- ./build
# rename the generated iso from output.iso to a real name
# name convention is: chakra-{YEAR}.{MONTH}.{DAY}-{SHA/8}-x86_64.iso
- mv output.iso chakra-"$(date '+%Y')"."$(date '+%m')"."$(date '+%d')"-$(echo "${CI_COMMIT_SHA}"| cut -c -8)-x86_64.iso
# sign the iso
- echo "$GPG_PASSWORD" | gpg -sb --pinentry-mode loopback --passphrase-fd 0 ./*.iso
- sha512sum *.iso >> output.iso.sha512sum
artifacts:
# expire artifacts per default - the gitlab web frontend can be used to keep
# artifacts of interest for an unlimited time
expire_in: 1 week
paths:
- ./*.iso
- ./*.iso.sig
- ./*.iso.sha512sum
name: "chakra-${CI_COMMIT_SHA}.iso"
tags:
- eevee
deploy_testing:
stage: deploy-testing
variables:
DEPLOY_FOLDER: "testing"
DEPLOY_SERVER: "$DEPLOY_SERVER"
SSH_USER: "$SSH_USER"
SSH_PORT: "$SSH_PORT"
environment:
name: testing-iso
url: "${DEPLOY_SERVER}/testing"
when: manual
script:
- .build-bin/deploy.sh
tags:
- rsync
# skipped for now, we have to rename and move automatically on releasing
.deploy_stable:
stage: deploy-final
variables:
DEPLOY_FOLDER: ""
DEPLOY_SERVER: "$DEPLOY_SERVER"
SSH_USER: "$SSH_USER"
SSH_PORT: "$SSH_PORT"
environment:
name: stable-iso
url: "${DEPLOY_SERVER}"
when: manual
script:
- .build-bin/deploy.sh
tags:
- rsync
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment