Skip to content

Commit

Permalink
Update devcontainer setup for gpg
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Jun 11, 2024
1 parent 3ceb3c5 commit 70922c9
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 58 deletions.
41 changes: 33 additions & 8 deletions .devcontainer/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,43 @@ RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \
sudo apt-get clean


ARG DEVELOP_PACKAGES="dos2unix git locales-all rsync tar ssh tzdata sudo vim"

FROM conan-build as conan-develop
#TODO deps needed for clion devcontainer
ARG DEVELOP_PACKAGES="$DEVELOP_PACKAGES curl unzip ps libxext libxrender libxtst libxi freetype procps gcompat"

ARG SSHD_INSTALL="sudo ( \
echo 'Port 2233'; \
echo 'LogLevel INFO'; \
echo 'PermitRootLogin yes'; \
echo 'PasswordAuthentication yes'; \
echo 'Subsystem sftp /usr/lib/openssh/sftp-server'; \
) > /etc/ssh/sshd_config_celix \
&& sudo mkdir /run/sshd"

FROM conan-build as conan-dev

#Install development dependencies
RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \
DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y --no-install-recommends $DEVELOP_PACKAGES && \
RUN sudo DEBIAN_FRONTEND="noninteractive" apt-get update && \
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
gnupg2 dos2unix git locales-all rsync tar ssh tzdata sudo vim openssh-server && \
sudo apt-get clean

FROM apt-build as apt-develop
#Setup sshd
# RUN sudo mkdir /etc/ssh && \
# sudo touch /etc/ssh/sshd_config_celix && \
# sudo echo "Port 2233\n \
# LogLevel INFO\n \
# PermitRootLogin yes\n \
# PasswordAuthentication yes\n \
# Subsystem sftp /usr/lib/openssh/sftp-server" > /etc/ssh/sshd_config_celix && \
# sudo mkdir /run/sshd

RUN sudo mkdir /run/sshd

FROM apt-build as apt-dev

#Install development dependencies
RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \
DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y --no-install-recommends $DEVELOP_PACKAGES && \
sudo apt-get clean
RUN ${APT_INSTALL}

#Setup sshd
RUN ${SSHD_INSTALL}
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "Apache Celix Dev Container",
"build": {
"dockerfile": "Containerfile",
"target": "conan-develop"
"target": "conan-dev"
},
"runArgs" : [
"--userns=keep-id"
],
"onCreateCommand": "sh .devcontainer/setup-conan.sh",
"postCreateCommand": "sh .devcontainer/build-conan.sh"
"onCreateCommand": "sh .devcontainer/setup-project-with-conan.sh",
"postCreateCommand": "sh .devcontainer/build-project-with-conan.sh"
}
109 changes: 109 additions & 0 deletions .devcontainer/run-dev-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Start a Celix dev container with all needed dependencies
# pre-installed already.

SCRIPT_LOCATION=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
CELIX_REPO_ROOT=$(realpath "${SCRIPT_LOCATION}/..")

CONTAINER_COMMAND_DEFAULT="sudo /usr/sbin/sshd -D -e -p 2233"
CONTAINER_COMMAND=${1:-${CONTAINER_COMMAND_DEFAULT}}

# Check which container engine is available.
# Check for podman first, because the 'podman-docker' package might be installed providing a dummy 'docker' command.
if command -v podman > /dev/null 2>&1; then
CONTAINER_ENGINE="podman"
else
CONTAINER_ENGINE="docker"
fi

# Check if container celix-dev already exists
if [ "$(${CONTAINER_ENGINE} ps -a --format '{{.Names}}' | grep celix-dev)" ]; then
echo "Container 'celix-dev' already exists. Do you want to remove it?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Removing container celix-dev"; ${CONTAINER_ENGINE} rm -f celix-dev; break;;
No ) exit;;
esac
done
echo ""
fi

ADDITIONAL_ARGS=""
echo "Do you want to mount the .ssh directory to the container (as an overlayfs)?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Add .ssh directory mount arguments"; ADDITIONAL_ARGS="--volume ${HOME}/.ssh:/home/celixdev/.ssh:O"; break;;
No ) break;;
esac
done
echo ""

if [ -e "${HOME}/.gnupg" ]; then
echo "Do you want to mount the .gnupg directory to the container (as an overlayfs)?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Add .gnupg directory mount arguments"; ADDITIONAL_ARGS="--volume ${HOME}/.gnupg:/home/celixdev/.gnupg:O"; break;;
No ) break;;
esac
done
echo ""
fi

# Start a container with all the Celix dependencies pre-installed
# --userns=keep-id is used to keep the user id the same in the container as on the host
# --privileged to allow the unit tests to change thread priorities
# --net=host is used to allow e.g. communication with etcd
# --volume & --workdir are set to the Celix repo root (to allow building and editing of the Celix repo)
# --security-opt disables SELinux for the container
# -d runs the container in detached mode
echo "Starting container 'celix-dev' with command: ${CONTAINER_COMMAND}"
${CONTAINER_ENGINE} run -it --rm --privileged -d \
--name celix-dev \
--userns keep-id \
--net=host \
${ADDITIONAL_ARGS} \
--volume "${CELIX_REPO_ROOT}":"${CELIX_REPO_ROOT}" \
--workdir "${CELIX_REPO_ROOT}" \
--security-opt label=disable \
apache/celix-conan-dev:latest bash -c "${CONTAINER_COMMAND}"
echo ""

echo "Do you want to setup the git user and email in the container?"
USER_NAME=$(git config user.name)
USER_EMAIL=$(git config user.email)
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Setting up git user and email"; ${CONTAINER_ENGINE} exec celix-dev bash -c "git config --global user.email '${USER_EMAIL}' && git config --global user.name '${USER_NAME}'"; break;;
No ) break;;
esac
done
echo ""

echo "Do you want to copy the ssh key to the container?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Copying ssh key (password: celixdev)"; ssh-copy-id -p 2233 celixdev@localhost; break;;
No ) break;;
esac
done
echo ""

echo "Done."
File renamed without changes.
File renamed without changes.
47 changes: 0 additions & 47 deletions container/run-ubuntu-container.sh

This file was deleted.

0 comments on commit 70922c9

Please sign in to comment.