Commit e58d0b19 authored by Brian Lee's avatar Brian Lee

Merge branch 'add-packages' into 'master'

Add packages

Closes #4

See merge request !25
parents bfec84d1 23864917
Pipeline #23403354 passed with stages
in 15 minutes and 6 seconds
artifacts/
testdir/
......@@ -73,3 +73,90 @@ job-test-services-postgres:
do printf "."; sleep 1; done;
printf " done!\n"
- psql -h db-postgres -U postgres -c 'select version();'
##################################################
# ### PACKAGE BUILD ### #
##################################################
.build-package-template: &build-package-template
image: registry.gitlab.com/ercom/docker-images/fpm:1.10.0-ubuntu-16.04
stage: build
variables:
CITBX_JOB_RUN_FILE_NAME: build-package.sh
tags:
- docker
script:
- ci-scripts/run-job-script.sh
.package-channel-dev: &package-channel-dev
except:
- tags
- master
.package-channel-rel: &package-channel-rel
only:
- tags
- master
.build-package-dev: &build-package-dev
<<: *build-package-template
<<: *package-channel-dev
artifacts:
paths:
- artifacts/
expire_in: 7d
.build-package-rel: &build-package-rel
<<: *build-package-template
<<: *package-channel-rel
artifacts:
paths:
- artifacts/
build-package-dev-deb: *build-package-dev
build-package-dev-rpm: *build-package-dev
build-package-rel-deb: *build-package-rel
build-package-rel-rpm: *build-package-rel
##################################################
# ### PACKAGE TESTSUITES ### #
##################################################
.test-package-template: &test-package-template
stage: test
variables:
CITBX_JOB_RUN_FILE_NAME: test-package.sh
tags: ["docker"]
script: ["ci-scripts/run-job-script.sh"]
test-package-deb-dev-ubuntu-18.04:
image: ubuntu:16.04
dependencies: ["build-package-dev-deb"]
<<: *test-package-template
<<: *package-channel-dev
test-package-deb-dev-ubuntu-16.04:
image: ubuntu:16.04
dependencies: ["build-package-dev-deb"]
<<: *test-package-template
<<: *package-channel-dev
test-package-rpm-dev-fedora-27:
image: fedora:27
dependencies: ["build-package-dev-rpm"]
<<: *test-package-template
<<: *package-channel-dev
test-package-deb-rel-ubuntu-18.04:
image: ubuntu:16.04
dependencies: ["build-package-rel-deb"]
<<: *test-package-template
<<: *package-channel-rel
test-package-deb-rel-ubuntu-14.04:
image: ubuntu:16.04
dependencies: ["build-package-rel-deb"]
<<: *test-package-template
<<: *package-channel-rel
test-package-rpm-rel-fedora-27:
image: fedora:27
dependencies: ["build-package-rel-rpm"]
<<: *test-package-template
<<: *package-channel-rel
......@@ -11,6 +11,8 @@
* [ci-toolbox] Add option to enable access to the host docker daemon into the job environment
* [modules/runshell] Add runshell module to run a shell on a specific build step, useful for debugging
* [ci-toolbox] Add options to manage Docker configuration propagation
* [packaging] Add build-package job for Debian-like and RedHat-like operating systems
* [CI] Add testsuites for RPM and DEB packages
## 4.1.0
* [env-setup/common] update install_tools function
......
......@@ -32,7 +32,8 @@ Cette boîte à outils peut être utilisée pour
### Installation de l'outil ci-toolbox
L'installation peut se faire :
* Manuellement en clonant le projet et en lançant le script `./setup/install.sh local`
* Manuellement en clonant le projet et en lançant le script `./setup/install.sh local|master|<specific version>`
* En installant le paquet pour les OS de type [Debian](https://gitlab.com/ercom/citbx4gitlab/-/jobs/artifacts/master/download?job=build-package-deb) ou pour les OS de type [RedHat](https://gitlab.com/ercom/citbx4gitlab/-/jobs/artifacts/master/download?job=build-package-rpm).
* En copiant ce qui suit dans une invite de commande (en remplaçant si besoin 'master' par le numéro de version choisi dans l'URL) :
```bash
......
......@@ -32,7 +32,8 @@ This toolbox can be used to
### ci-toolbox tool setup
You can perform this setup (where `master` can be changed by a specific version in the URL):
* Manually by cloning this project and executing `./setup/install.sh local`
* Manually by cloning this project and executing `./setup/install.sh local|master|<specific version>`
* By installing the package for [Debian](https://gitlab.com/ercom/citbx4gitlab/-/jobs/artifacts/master/download?job=build-package-deb)-like OS or for [RedHat](https://gitlab.com/ercom/citbx4gitlab/-/jobs/artifacts/master/download?job=build-package-rpm)-like OS
* Or pasting the following content into your shell:
```bash
......
CITBX_PACKAGE_NAME="ci-toolbox"
job_define() {
bashopts_declare -n CI_COMMIT_TAG -l image-tag -d "Image tag" -t string -v "$(cat VERSION)-dev"
citbx_export CI_COMMIT_TAG
}
job_main() {
local pkgtype=${CI_JOB_NAME##*-}
local version=${CI_COMMIT_TAG:-$(
cat VERSION | tr -d '\n'
if [ "$CI_COMMIT_REF_NAME" != "master" ]; then
echo -n "-dev"
fi
)}
local fpm_args=(
-s dir
-n $CITBX_PACKAGE_NAME
--url https://gitlab.com/ercom/citbx4gitlab
--description "CI toolbox for Gitlab CI"
-m "ERCOM <support@ercom.fr>"
--license "GPLv3"
--vendor "ERCOM"
--conflicts $CITBX_PACKAGE_NAME
--provides $CITBX_PACKAGE_NAME
--replaces $CITBX_PACKAGE_NAME
--depends git
--depends curl
--depends tar
--depends file
--depends bzip2
-a all
)
case "$pkgtype" in
deb)
rm -f artifacts/$CITBX_PACKAGE_NAME.deb
fpm_args+=(
--depends debianutils
-v $version
-t deb --deb-priority optional --category admin
--deb-no-default-config-files
-p artifacts/$CITBX_PACKAGE_NAME.deb --deb-compression xz
--after-install packaging/scripts/postinst.deb
--depends ca-certificates
)
;;
rpm)
rm -f artifacts/$CITBX_PACKAGE_NAME.rpm
fpm_args+=(
--depends which
-v ${version//-/_}
-t rpm --rpm-os linux
-p artifacts/$CITBX_PACKAGE_NAME.rpm --rpm-compression xz
--after-install packaging/scripts/postinst.rpm
)
;;
*)
print_critical "Unsupported package type: '$pkgtype'"
;;
esac
mkdir -p artifacts
fpm_args+=(
packaging/root/=/
ci-toolbox/ci-toolbox.sh=/usr/lib/ci-toolbox/ci-toolbox.sh
ci-scripts/common.sh=/usr/lib/ci-toolbox/common.sh
.ci-toolbox.properties=/etc/ci-toolbox/ci-toolbox.properties.default
ci-toolbox/env-setup/=/usr/lib/ci-toolbox/env-setup/
ci-toolbox/3rdparty/=/usr/lib/ci-toolbox/3rdparty/
wrapper/ci-toolbox=/usr/bin/ci-toolbox
wrapper/bashcomp=/usr/share/bash-completion/completions/ci-toolbox
)
fpm "${fpm_args[@]}"
}
citbx_use runshell
CITBX_PACKAGE_NAME="ci-toolbox"
job_define() {
CITBX_UID=0
}
job_setup() {
CI_COMMIT_REF_NAME=$(git rev-parse --abbrev-ref HEAD)
TEST_USER_UID=$(id -u)
TEST_USER_HOME=$HOME
citbx_export CI_COMMIT_REF_NAME TEST_USER_UID TEST_USER_HOME
citbx_docker_run_add_args --privileged
}
job_main() {
case "$CI_JOB_NAME" in
test-package-rpm-*)
dnf install -y sudo psmisc
dnf install -y ./artifacts/ci-toolbox.rpm
;;
test-package-deb-*)
apt update
apt -y install sudo psmisc
apt -y install ./artifacts/ci-toolbox.deb
;;
esac
case "$CI_JOB_NAME" in
*-rel-*)
export CITBX_PACKAGE_CHANNEL=rel
;;
*-dev-*)
export CITBX_PACKAGE_CHANNEL=dev
;;
esac
if [ -z "$TEST_USER_UID" ]; then
TEST_USER_UID=1000
fi
if [ -z "$TEST_USER_HOME" ]; then
TEST_USER_HOME=/home/testuser
fi
print_info "### STEP1 ### Environment setup"
useradd -o -u $TEST_USER_UID -s /bin/sh -d $TEST_USER_HOME -M test-user
echo "test-user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
if [ ! -d "$TEST_USER_HOME" ]; then
mkdir -p "$TEST_USER_HOME"
chown test-user:test-user "$TEST_USER_HOME"
fi
print_info "### STEP2 ### ci-toolbox setup"
sudo -u test-user env HOME="$TEST_USER_HOME" \
ci-toolbox setup "$CI_COMMIT_REF_NAME" \
--docker-storage-driver overlay2 \
--docker-bip "172.30.0.1/24" \
--docker-cdir "172.30.0.0/24" \
--docker-dns 9.9.9.9 \
--component base-pkgs \
--component docker-cfg \
--component git-lfs \
--component ca-certs
print_info "### STEP3 ### Docker daemon start"
dockerd --data-root "$CI_PROJECT_DIR/testdir/docker/data"&
echo -n "Waiting for docker daemon"
until [ -e /var/run/docker.sock ]; do sleep 1; echo -n "."; done
print_info "### STEP3 ### job-* exec"
for j in $(ci-toolbox | grep '^ job-'); do
print_info "### JOB ### Running job $j..."
sudo -u test-user env HOME="$TEST_USER_HOME" ci-toolbox $j
done
}
job_after() {
if [ -f /var/run/docker.pid ]; then
# Kill the docker daemon
local pid=$(cat /var/run/docker.pid)
kill $pid || true
wait $pid || true
fi
# Remove testdir and ignore errors
rm -rf testdir || true
}
......@@ -56,6 +56,12 @@ write_daemon_json() {
}' | sudo_sponge /etc/docker/daemon.json
}
install_pkgs_postinst() {
if [ $(id -u) -ne 0 ]; then
_sudo usermod -a -G docker $(id -u -n)
fi
}
CITBX_TMPDIR=$(mktemp -d)
install_finish() {
rm -rf $CITBX_TMPDIR
......@@ -69,11 +75,9 @@ install_ci_toolbox() {
mkdir -p $tmpdir
curl -fSsL https://gitlab.com/ercom/citbx4gitlab/repository/$version/archive.tar.bz2 | tar -C $tmpdir -xj
# Execute setup process from the remote archive
CITBX_GIT_REF=$version
CITBX_SRC_DIR="$(readlink -f $tmpdir/citbx4gitlab-*)"
CITBX_SETUP_TYPE=ci-tools
source $CITBX_SRC_DIR/setup/install.sh
print_info "done!"
local extract_dir="$(readlink -f $tmpdir/citbx4gitlab-*)"
bash $extract_dir/setup/install.sh $version
print_info "CI Toolbox setup complete"
}
install_ca_certificates_system() {
......
......@@ -19,9 +19,7 @@ if [ "${#INSTALL_PKGS[@]}" -gt 0 ]; then
fi
if setup_component_enabled base-pkgs; then
if [ "${USER}" != "root" ]; then
_sudo gpasswd -a ${USER} docker
fi
install_pkgs_postinst
fi
if setup_component_enabled ca-certs; then
......@@ -37,7 +35,9 @@ if setup_component_enabled docker-cfg; then
write_daemon_json
_sudo ip link del docker0 2>/dev/null || true
_sudo systemctl restart docker
if systemctl status dbus.socket /dev/null 2>&1; then
_sudo service docker restart
fi
fi
if setup_component_enabled ci-toolbox; then
......
......@@ -22,9 +22,7 @@ if [ "${#INSTALL_PKGS[@]}" -gt 0 ]; then
fi
if setup_component_enabled base-pkgs; then
if [ "${USER}" != "root" ]; then
_sudo gpasswd -a ${USER} docker
fi
install_pkgs_postinst
fi
if setup_component_enabled ca-certs; then
......
......@@ -68,9 +68,7 @@ if [ "${#INSTALL_PKGS[@]}" -gt 0 ]; then
fi
if setup_component_enabled base-pkgs; then
if [ "${USER}" != "root" ]; then
_sudo gpasswd -a ${USER} docker
fi
install_pkgs_postinst
fi
if setup_component_enabled ca-certs; then
......@@ -90,7 +88,9 @@ if setup_component_enabled docker-cfg; then
_sudo sed '/^ *\<DOCKER_OPTS\>/s/^/#/' -i /etc/default/docker
fi
_sudo ip link del docker0 2>/dev/null || true
_sudo service docker restart
if systemctl status dbus.socket /dev/null 2>&1; then
_sudo service docker restart
fi
fi
if setup_component_enabled ci-toolbox; then
......
#!/bin/sh
# Fixes file permission
chmod +x /usr/bin/ci-toolbox
cleanup_manual_install() {
for f in "$@"; do
if [ -d "$f" ]; then
echo "Removing directory $f..."
rm -r "$f"
elif [ -e "$f" ]; then
echo "Removing file $f..."
rm "$f"
fi
done
}
# if settings from manual installation exists, import this file into the new location
# only for a fresh installation
if [ ! -f /etc/ci-toolbox/ci-toolbox.properties ] \
&& [ -f /usr/local/lib/ci-toolbox/ci-toolbox.properties ]; then
mv /usr/local/lib/ci-toolbox/ci-toolbox.properties \
/etc/ci-toolbox/ci-toolbox.properties
fi
# Remove ci-toolbox installation using the manual way
cleanup_manual_install /usr/local/bin/ci-toolbox \
/etc/bash_completion.d/ci-toolbox /usr/local/lib/ci-toolbox
if [ ! -f /etc/ci-toolbox/ci-toolbox.properties ]; then
echo "Initializing file /etc/ci-toolbox/ci-toolbox.properties with default values..."
cp /etc/ci-toolbox/ci-toolbox.properties.default /etc/ci-toolbox/ci-toolbox.properties
fi
ln -sf /etc/ci-toolbox/ci-toolbox.properties /usr/lib/ci-toolbox/ci-toolbox.properties
#!/bin/sh
set -e
case "$1" in
abort-upgrade|abort-remove|abort-deconfigure)
;;
configure)
/usr/share/ci-toolbox/post-install
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
exit 0
#!/bin/sh
set -e
/usr/share/ci-toolbox/post-install
exit 0
# Project setup directory
This directory is only used by install/update tools and should not be integrated into any project.
Files:
* `install.sh`: This file is read (with `source` command) during install/update process and should not be executed directly
......@@ -22,10 +22,56 @@ setup_local() {
fi
}
_which() {
for p in $(echo "$PATH" | tr : \ ); do
if [ -x "$p/$1" ]; then
echo "$p/$1"
return 0
fi
done
return 1
}
if _which curl > /dev/null; then
fetch_dist_file() {
curl -Lso "$1" "$2"
}
elif _which wget > /dev/null; then
fetch_dist_file() {
wget -O "$1" "$2"
}
fi
install_pkg_deb() {
_sudo apt install --reinstall --allow-downgrades -y "$@"
}
install_pkg_rpm() {
# TODO 1: Find a way to add --reinstall option that works on all cases (install & reinstall)
# TODO 2: Find an equivalent to the apt 'allow-downgrades' option
_sudo dnf install -y "$@"
}
setup_pkg() {
local pkg_type=$1
mkdir -p $CITBX_SRC_DIR/artifacts
if ! _which unzip > /dev/null; then
install_pkg_$pkg_type unzip
fi
fetch_dist_file $CITBX_SRC_DIR/artifacts/ci-toolbox.zip \
https://gitlab.com/ercom/citbx4gitlab/-/jobs/artifacts/$CITBX_GIT_REF/download?job=build-package-$CITBX_PACKAGE_CHANNEL-$pkg_type
unzip -p $CITBX_SRC_DIR/artifacts/ci-toolbox.zip artifacts/ci-toolbox.$pkg_type > $CITBX_SRC_DIR/artifacts/ci-toolbox.$pkg_type
install_pkg_$pkg_type $CITBX_SRC_DIR/artifacts/ci-toolbox.$pkg_type
}
if [ -n "$1" ]; then
CITBX_GIT_REF=$1
fi
if [ -n "$2" ]; then
CITBX_PACKAGE_CHANNEL=$2
fi
# Assure backward compatibility
if [ "${BASH_SOURCE[0]}" != "$0" ]; then
if [ "$CITBX_SETUP_TYPE" != "ci-tools" ]; then
......@@ -39,11 +85,31 @@ fi
if [ -z "$CITBX_GIT_REF" ]; then
print_critical "No version given: this tool requires the first argument to be the version of this tool to install" \
" or 'local' keyword to force the installation into /usr/local using the generic install process (without using the suited package)" \
"Usage: ${BASH_SOURCE[0]} local"
" You can add the 'dev' keyword as the second argument to use the development package version" "" \
"Usage: ${BASH_SOURCE[0]} local|master|<version> [dev|development]"
fi
case "$CITBX_PACKAGE_CHANNEL" in
''|rel|release)
CITBX_PACKAGE_CHANNEL=rel
;;
dev|development)
CITBX_PACKAGE_CHANNEL=dev
;;
*)
print_critical "Invalid package '$CITBX_PACKAGE_CHANNEL' channel (accepted values are rel|release or dev|development)"
;;
esac
if [ "$CITBX_GIT_REF" == "local" ]; then
setup_local
elif [ -f /etc/debian_version ]; then
# Debian based system
setup_pkg deb
elif [ -f /etc/redhat-release ]; then
# Redhat based system
setup_pkg rpm
else
print_critical "No package available for your OS" "=> You can try the command '$0 local' to install this tool using the generic install process"
print_warning "No package available for your OS" "> the generic install process ('setup/install.sh local') will be executed"
setup_local
fi
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