Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support snapcraft subdirectory #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/bash-completion/snapbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _snapbuilder()
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="help delete shell clean --help -h --mount-ssh --silo -s"
opts="help delete shell clean --help -h --mount-ssh --silo -s --snapcraft-dir"

COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
Expand Down
9 changes: 5 additions & 4 deletions imagebuilder
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ createContainer() {
lxc config device add ${CONTAINERNAME} loop-control unix-char path=/dev/loop-control

# Give permissions to the container
lxc config set ${CONTAINERNAME} raw.apparmor "mount,"
#lxc config set ${CONTAINERNAME} raw.apparmor "mount,"
lxc config set ${CONTAINERNAME} security.privileged true
lxc config set ${CONTAINERNAME} security.nesting true

startContainer
waitContainerNetwork
Expand Down Expand Up @@ -434,9 +435,9 @@ finish() {
return 0
fi

if containerRunning; then
execContainerRoot chown -R $USERNAME:$GROUPNAME ${BUILDDIR_MOUNT}
fi
#if containerRunning; then
# execContainerRoot chown -R $USERNAME:$GROUPNAME ${BUILDDIR_MOUNT}
#fi
}

#------------------------------------------------------------------------------------------
Expand Down
56 changes: 31 additions & 25 deletions snapbuilder
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
#!/bin/bash -e

PROGRAM_NAME=`basename $0`
SNAPCRAFT_DIR=.

display_help () {
echo "Usage: $PROGRAM_NAME [options] [command]"
echo ""
echo "Available commands:"
echo " help - Display this help."
echo " delete - Delete a container."
echo " shell - Enter a container."
echo " clean - Clean the snap build dir."
echo " help Display this help."
echo " delete Delete a container."
echo " shell Enter a container."
echo " clean Clean the snap build dir."
echo "Options:"
echo " --help, -h - Display this help."
echo " --mount-ssh - Mount ~/.ssh into the container (if snapcraft requires ssh keys to access repositories)."
echo " --silo, -s - Add ci-repo.nymea.io/... to the apt sources"
echo " --help, -h Display this help."
echo " --mount-ssh Mount ~/.ssh into the container (if snapcraft requires ssh keys to access repositories)."
echo " --silo, -s [NAME] Add the silo ci-repo.nymea.io/[NAME] to the apt sources"
echo " --snapcraft-dir [DIR] Specify the directory where the snapcraft command should be started"
}

variables () {

SNAPCRAFT_FILE=snapcraft.yaml
SNAPCRAFT_FILE=${SNAPCRAFT_DIR}/snapcraft.yaml
if [ ! -e $SNAPCRAFT_FILE ]; then
if [ ! -d snap ]; then
echo "${NEGATIVE_COLOR}snapcraft.yaml not found.${NC}"
exit 1
else
SNAPCRAFT_FILE=snap/snapcraft.yaml
if [ ! -e $SNAPCRAFT_FILE ]; then
echo "${NEGATIVE_COLOR}snap/snapcraft.yaml not found.${NC}"
exit 1
fi
fi

echo "${NEGATIVE_COLOR}Could not find ${SNAPCRAFT_FILE}${NC}"
exit 1
fi

if grep "base: core18" $SNAPCRAFT_FILE > /dev/null; then
DISTRO=bionic
else
DISTRO=xenial
fi

PACKAGE=`cat $SNAPCRAFT_FILE | grep name | head -n 1 | cut -d " " -f 2`
VERSION=`cat $SNAPCRAFT_FILE | grep version | head -n 1 | cut -d " " -f 2`
RED='\033[0;31m'
Expand Down Expand Up @@ -176,9 +169,15 @@ exec_container_root () {
lxc exec $LXD_CONTAINER -- sh -c "cd $SOURCE_PATH_CONTAINER; $command"
}

exec_snapcraft() {
params="$@"
echo lxc exec $LXD_CONTAINER "$@"
lxc exec $LXD_CONTAINER -- su -l -c "cd $SOURCE_PATH_CONTAINER/${SNAPCRAFT_DIR}; snapcraft $params" $USERNAME
}

exec_container () {
command="$@"
#echo lxc exec $LXD_CONTAINER "$@"
echo lxc exec $LXD_CONTAINER "$@"
lxc exec $LXD_CONTAINER -- su -l -c "cd $SOURCE_PATH_CONTAINER; $command" $USERNAME
}

Expand All @@ -200,14 +199,15 @@ check_for_container_network() {

build () {
exec_container_root rm /var/lib/dpkg/lock || true
exec_container snapcraft
exec_snapcraft
}

clean () {
exec_container snapcraft clean $@
exec_snapcraft clean $@
}

variables
########################################################################
# Main
########################################################################

while [ "$1" != "" ]; do
OPTION=`echo $1 | awk -F= '{print $1}'`
Expand All @@ -224,6 +224,10 @@ while [ "$1" != "" ]; do
--silo)
SILO_NAME=$VALUE
;;
--snapcraft-dir)
shift;
SNAPCRAFT_DIR=$1
;;
-s)
shift;
SILO_NAME=$1
Expand All @@ -247,6 +251,8 @@ while [ "$1" != "" ]; do
esac
done

variables

COMMAND=$1
if [ -n "$COMMAND" ] ; then
shift
Expand Down