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

Add helper script and integrate with ssh-agent #90

Open
wants to merge 3 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
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ ADD https://raw.githubusercontent.com/crops/extsdk-container/master/restrict_use
COPY distro-entry.sh poky-entry.py poky-launch.sh /usr/bin/
COPY sudoers.usersetup /etc/

RUN echo -e "\n# ssh-agent socket bind-mounted from host\n"\
"if [ -s /tmp/ssh-auth-sock ]; then\n"\
" export SSH_AUTH_SOCK=/tmp/ssh-auth-sock\n"\
"fi\n" >> /etc/skel/.bashrc

# For ubuntu, do not use dash.
RUN which dash &> /dev/null && (\
echo "dash dash/sh boolean false" | debconf-set-selections && \
Expand Down
87 changes: 87 additions & 0 deletions poky-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

usage() {
cat << EOF
Usage:
poky-container list
List available images

poky-container run IMAGE [HOST_WORKDIR]
Run the selected image on a specific location

Parameters:
IMAGE The name of the image to run
HOST_WORKDIR The working directory, ie, location if the workspace
on the host, which will show as /workdir in the
container.
By default, the current working directory is used.

EOF
}


list() {
cat << EOF
AlmaLinux:
alma-8 alma-9

CentOS:
centos-7

Debian:
debian-9 debian-10 debian-11

Fedora:
fedora-33 fedora-34 fedora-35 fedora-36

OpenSuse:
opensuse-15.2 opensuse-15.3 opensuse-15.4

Ubuntu:
ubuntu-16.04 ubuntu-18.04 ubuntu-20.04 ubuntu-22.04

EOF
}

run() {
CONTAINER_WORKDIR=/workdir
HOST_WORKDIR=$(readlink -f .)
if [ $# -eq 2 ]; then
HOST_WORKDIR=$(readlink -f $2)
elif [ $# -ne 1 ]; then
echo "Error: Invalid arguments"
usage
exit 1
fi
IMAGE=$1

SSH_AUTH_SOCK_MOUNT=""
if [ -z "$SSH_AUTH_SOCK" ]; then
eval $(ssh-agent)
SSH_AUTH_SOCK_MOUNT="--mount type=bind,source=$(readlink -f $SSH_AUTH_SOCK),destination=/tmp/ssh-auth-sock"
fi

docker run --rm -it -v $HOST_WORKDIR:$CONTAINER_WORKDIR \
$SSH_AUTH_SOCK_MOUNT \
crops/poky:$IMAGE --workdir=$CONTAINER_WORKDIR
}


CMD=$1
shift

case $CMD in
list)
list
;;
run)
run $@
;;
*)
usage
;;
esac