Commit c208ecb9 authored by AlmAck's avatar AlmAck

use the chakra-gitlab-ci-scripts and remove the local files

parent f143c79c
#!/usr/bin/env bash
SCRIPT_DIR=$( dirname $( readlink -e $0 ) )
source "$SCRIPT_DIR/../.build-lib/ci-library.sh"
source "$SCRIPT_DIR/../.build-lib/ci-deploy-iso-library.sh"
# get the list of iso files to upload
_do list_upload_iso
# 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-iso-library depends on ci-library
UPLOAD_LIST=()
# 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_iso() {
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 _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
}
......@@ -9,34 +9,10 @@ stages:
- deploy-final
before_script:
# 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
# import the gitlab-ci scripts
- git clone --depth 1 https://code.chakralinux.org/tools/chakra-gitlab-ci-scripts _gitlab-ci-scripts
# setup basic environment settings, as root
- _gitlab-ci-scripts/prepare.sh
build_iso:
stage: build
......@@ -78,7 +54,7 @@ deploy_testing:
url: "${DEPLOY_SERVER}/testing"
when: manual
script:
- .build-bin/deploy.sh
- _gitlab-ci-scripts/deploy.sh
tags:
- rsync
......@@ -95,6 +71,6 @@ deploy_testing:
url: "${DEPLOY_SERVER}"
when: manual
script:
- .build-bin/deploy.sh
- _gitlab-ci-scripts/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