Skip to content

Commit

Permalink
build: add basic build infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasT committed Feb 12, 2019
1 parent d080903 commit 9d5f337
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
_build/

.vagrant/
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.POSIX:

MAKEFLAGS += -r
.DEFAULT_GOAL := default
.DELETE_ON_ERROR:
.SUFFIXES:

VERSION ?= 2.0

PWD := $(shell pwd)

BUILD_ROOT ?= $(PWD)/_build
ISO_ROOT ?= $(BUILD_ROOT)/root

ALL = \
$(ISO_ROOT)/bootstrap.sh \
\
$(ISO_ROOT)/salt/metalk8s/containerd/configured.sls \
$(ISO_ROOT)/salt/metalk8s/containerd/init.sls \
$(ISO_ROOT)/salt/metalk8s/containerd/installed.sls \
\
$(ISO_ROOT)/salt/metalk8s/defaults.yaml \
\
$(ISO_ROOT)/salt/metalk8s/kubelet/init.sls \
$(ISO_ROOT)/salt/metalk8s/kubelet/installed.sls \
\
$(ISO_ROOT)/salt/metalk8s/map.jinja \
\
$(ISO_ROOT)/salt/metalk8s/repo/configured.sls \
$(ISO_ROOT)/salt/metalk8s/repo/init.sls \
$(ISO_ROOT)/salt/metalk8s/repo/offline.sls \
$(ISO_ROOT)/salt/metalk8s/repo/online.sls \
\
$(ISO_ROOT)/salt/metalk8s/runc/init.sls \
$(ISO_ROOT)/salt/metalk8s/runc/installed.sls \
\
$(ISO_ROOT)/pillar/repositories.sls \
$(ISO_ROOT)/pillar/top.sls \


default: all
.PHONY: default

all: $(ALL)
.PHONY: all

$(ISO_ROOT)/bootstrap.sh: scripts/bootstrap.sh.in
mkdir -p $(shell dirname $@)
rm -f $@
sed s/@VERSION@/$(VERSION)/g < $< > $@ || rm -f $@
chmod a+x $@

$(ISO_ROOT)/salt/%: salt/%
mkdir -p $(shell dirname $@)
rm -f $@
cp --archive $< $@

$(ISO_ROOT)/pillar/top.sls: pillar/top.sls.in
mkdir -p $(shell dirname $@)
rm -f $@
sed s/@VERSION@/$(VERSION)/g < $< > $@ || rm -f $@

$(ISO_ROOT)/pillar/%: pillar/%
mkdir -p $(shell dirname $@)
rm -f $@
cp --archive $< $@

clean:
rm -rf $(BUILD_ROOT)
.PHONY: clean
26 changes: 14 additions & 12 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ set -eu -o pipefail
RC=0
die() {
echo 1>&2 $@
exit 1
}
echo "Installing build artifacts on the host"
# This script is supposed to 'install' the build results on the system,
# i.e. symlink something like `/vagrant/_build/root` to
# `/srv/scality/metalk8s-$VERSION` or however we build this.
mkdir -p /srv/scality || die "Failed to create /srv/scality"
rm -f /srv/scality/metalk8s-dev || die "Failed to unlink symlink destination"
ln -s /vagrant/_build/root /srv/scality/metalk8s-dev || die "Failed to create symlink"
echo "Installed build artifacts on the host"
Expand All @@ -25,17 +30,14 @@ BOOTSTRAP = <<-SCRIPT
set -eu -o pipefail
RC=0
if ! test -x /srv/scality/metalk8s-dev/bootstrap.sh; then
echo 1>&2 "Bootstrap script not found in build directory."
echo 1>&2 "Did you run 'make'?"
exit 1
fi
echo "Launching bootstrap"
# This script is supposed to launch the bootstrap process. If this process is
# already scripted in something provisioned in `/srv/scality/metalk8s-$VERSION`,
# then we could just chain/`exec` into that one.
echo "Bootstrap finished"
exit $RC
exec /srv/scality/metalk8s-dev/bootstrap.sh
SCRIPT

# To support VirtualBox linked clones
Expand Down
2 changes: 1 addition & 1 deletion pillar/top.sls → pillar/top.sls.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metalk8s-2.0:
metalk8s-@VERSION@:
'*':
- repositories
89 changes: 89 additions & 0 deletions scripts/bootstrap.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

set -e
set -u
# The trickery below is to only run `set -o pipefail`, which is a Bash'ism,
# when running in Bash and not some other `sh` which doesn't necessarily
# support `-o pipefail` (though must support `-e` and `-u` per POSIX).
if test -z "$(type -p)"; then set -o pipefail; fi

RPM=${RPM:-$(command -v rpm)}
SYSTEMCTL=${SYSTEMCTL:-$(command -v systemctl)}
YUM=${YUM:-$(command -v yum)}
SALT_CALL=${SALT_CALL:-salt-call}

SALT_MINION_FILE_CLIENT_LOCAL_CONF=/etc/salt/minion.d/99-file-client-local.conf

die() {
echo 1>&2 "$@"
exit 1
}

pre_minion_checks() {
test "x$(whoami)" = "xroot" || die "Script must run as root"
test -n "${RPM}" || die "rpm not found"
test -x "${RPM}" || die "rpm at '${RPM}' is not executable"
test -n "${SYSTEMCTL}" || die "systemctl not found"
test -x "${SYSTEMCTL}" || die "systemctl at '${SYSTEMCTL}' is not executable"
test -n "${YUM}" || die "yum not found"
test -x "${YUM}" || die "yum at '${YUM}' is not executable"
}

disable_salt_minion_service() {
${SYSTEMCTL} disable salt-minion.service 2>/dev/null || true
}

stop_salt_minion_service() {
${SYSTEMCTL} stop salt-minion.service 2>/dev/null || true
}

configure_salt_repository() {
${RPM} --import https://repo.saltstack.com/yum/redhat/7/x86_64/archive/2018.3.3/SALTSTACK-GPG-KEY.pub
cat > /etc/yum.repos.d/saltstack.repo << EOF
[saltstack-repo]
name=SaltStack repo for RHEL/CentOS \$releasever
baseurl=https://repo.saltstack.com/yum/redhat/\$releasever/\$basearch/archive/2018.3.3
enabled=1
gpgcheck=1
gpgkey=https://repo.saltstack.com/yum/redhat/\$releasever/\$basearch/archive/2018.3.3/SALTSTACK-GPG-KEY.pub
EOF
${YUM} clean expire-cache
}

install_salt_minion() {
${YUM} install -y salt-minion
}

configure_salt_minion_local_mode() {
cat > "${SALT_MINION_FILE_CLIENT_LOCAL_CONF}" << EOF
file_client: local
file_roots:
metalk8s-@VERSION@:
- /srv/scality/metalk8s-dev/salt
pillar_roots:
metalk8s-@VERSION@:
- /srv/scality/metalk8s-dev/pillar
EOF
}

run_bootstrap_prechecks() {
return
}

install_kubelet() {
${SALT_CALL} --local --retcode-passthrough state.apply metalk8s.containerd saltenv=metalk8s-@VERSION@ pillarenv=metalk8s-@VERSION@
${SALT_CALL} --local --retcode-passthrough state.apply metalk8s.kubelet saltenv=metalk8s-@VERSION@ pillarenv=metalk8s-@VERSION@
}

main() {
pre_minion_checks
disable_salt_minion_service
stop_salt_minion_service
configure_salt_repository
install_salt_minion
configure_salt_minion_local_mode
run_bootstrap_prechecks
install_kubelet
}

main

0 comments on commit 9d5f337

Please sign in to comment.